[Slider] Fix some issues
This commit is contained in:
@@ -120,7 +120,8 @@ var activateSlider = (interval, name) => {
|
||||
sliderAutoAdvance();
|
||||
});
|
||||
sliderAutoAdvance();
|
||||
loadImageType(name);
|
||||
if (name !== null)
|
||||
loadImageType(name);
|
||||
};
|
||||
const sliderAutoAdvance = () => {
|
||||
if (sliderAutoAdvanceInterval > 0) {
|
||||
@@ -145,13 +146,15 @@ const allowedExtensions = [
|
||||
'svg',
|
||||
'png'
|
||||
];
|
||||
let oldName = '';
|
||||
/**
|
||||
* Load type of image, can be used to load images for different platforms (i.e. mobile optimization)
|
||||
* @param name - The name appended to the image filename
|
||||
*/
|
||||
var loadImageType = (name) => {
|
||||
const newClass = 'slider-type' + name;
|
||||
sliderElements.forEach(el => {
|
||||
const baseURL = el.dataset.imageBaseURL;
|
||||
const baseURL = el.dataset.imageBaseUrl;
|
||||
const filetype = el.dataset.filetype;
|
||||
if (allowedExtensions.indexOf(filetype) === -1) {
|
||||
console.warn('[ SLIDER ] Invalid filetype ' + filetype + ' for image element with id ' + el.id);
|
||||
@@ -161,7 +164,13 @@ var loadImageType = (name) => {
|
||||
console.warn('[ SLIDER ] ImageBaseURL incorrect for image element with id ' + el.id);
|
||||
return;
|
||||
}
|
||||
el.style.setProperty('background-image', `url(${baseURL}${name}${filetype})`);
|
||||
try {
|
||||
el.classList.remove(oldName);
|
||||
}
|
||||
catch ( /* empty */_a) { /* empty */ }
|
||||
el.classList.add(newClass);
|
||||
oldName = newClass;
|
||||
el.style.setProperty('background-image', `url(${baseURL}${name ? name : ''}.${filetype})`);
|
||||
});
|
||||
};
|
||||
for (const el in fetchedElements) {
|
||||
|
||||
Reference in New Issue
Block a user