Commit 59ef50c8 authored by Michael Iseard's avatar Michael Iseard
Browse files

update slider

parent 07b7694b
let sliders=document.getElementsByClassName("skroll-slider");for(var sliderObjects=[],i=0;i<sliders.length;i++){var el=sliders[i],num=el.children.length,imgElements=el.querySelectorAll("img"),slides=el.children,imgUrls=Array.from(el.querySelectorAll("img")).map(function(e,s){return e.remove(),e.src}),slideText={};for(let e=0;e<slides.length;e++)slideText[e]=slides[e];if(sliderObjects[i]={slider:el,img:imgElements,slideText:slideText,imgUrls:imgUrls,num:num,settings:{effect:"zoom",animateText:!0,showIndicators:!0,showArrows:!0,paused:!1,autoPause:!0,slideIndex:0,duration:5e3,transition:"pan"}},el.hasAttribute("data-skroll")){var settings=JSON.parse(el.dataset.skroll);for(const e of Object.keys(settings))sliderObjects[i].settings[e]=settings[e]}sliderConstruct(sliderObjects[i])}function sliderConstruct(e){e.slider.classList.add(e.settings.effect+"-effect",e.settings.animateText?"animate-text":null,e.settings.transition);var s=document.createDocumentFragment(),t=document.createElement("DIV");0==e.settings.showArrows?t.setAttribute("class","arrows hidden"):t.setAttribute("class","arrows");var n=document.createElement("DIV");n.setAttribute("class","slide-arrow left-arrow");var d=document.createElement("DIV");d.setAttribute("class","slide-arrow right-arrow"),t.appendChild(n),t.appendChild(d),s.prepend(t),e.arrows=[n,d];var r=document.createElement("DIV");e.slides=r,r.classList.add("slides"),"pan"===e.settings.transition&&(r.style.width=e.num+"00%"),"pan"===e.settings.transition&&(r.style.width=e.num+"00%");var l={slide:null,slideWrap:null};for(let s=0;s<e.num;s++)l.slideWrap=document.createElement("DIV"),s===e.settings.slideIndex?l.slideWrap.setAttribute("class","slide-wrap current-slide"):l.slideWrap.setAttribute("class","slide-wrap"),l.slide=document.createElement("DIV"),l.slide.setAttribute("class","slide"),l.slideText=e.slideText[s],l.slideText.setAttribute("class","slide-text"),l.slide.style.backgroundImage="url("+e.imgUrls[s]+")",l.slideWrap.appendChild(l.slide),l.slideWrap.appendChild(l.slideText),r.appendChild(l.slideWrap);s.appendChild(r),e.indicators={};var a=document.createElement("DIV");0==e.settings.showIndicators?a.setAttribute("class","indicators hidden"):a.setAttribute("class","indicators");for(let t=0;t<e.num;t++){var c=document.createElement("SPAN");t===e.settings.slideIndex?c.setAttribute("class","slide-indicator current-indicator"):c.setAttribute("class","slide-indicator"),c.setAttribute("data-slide",t),a.appendChild(c),s.appendChild(a),e.indicators[t]=c}e.slider.appendChild(s),setBindings(e),autoSlide(sliderObjects[i])}function setBindings(e){for(var s=0;s<e.arrows.length;s++)e.arrows[s].addEventListener("click",function(s){if(!e.slider.classList.contains("animating")){if(e.prevSlideIndex=e.settings.slideIndex,s.target.classList.contains("left-arrow"))var t=e.settings.slideIndex-1;else if(s.target.classList.contains("right-arrow"))t=e.settings.slideIndex+1;updateIndex(e,t),clearTimeouts(e),sliderChange(e)}});for(s=0;s<e.num;s++)e.indicators[s].addEventListener("click",function(s){e.slider.classList.contains("animating")||!1===s.target.classList.contains("current-indicator")&&(clearTimeouts(e),updateIndex(e,Number(s.target.dataset.slide)),sliderChange(e))})}function sliderChange(e){if(e.prev=e.slider.getElementsByClassName("current-slide")[0],e.settings.slideIndex<0?(e.settings.slideIndex=e.num-1,e.num&&e.indicators[0].parentElement.classList.add("transition-last"),setTimeout(function(){e.num&&e.indicators[0].parentElement.classList.remove("transition-last")},1e3)):e.settings.slideIndex>e.num-1&&(e.settings.slideIndex=0,e.num&&e.indicators[0].parentElement.classList.add("transition-first"),setTimeout(function(){e.num&&e.indicators[0].parentElement.classList.remove("transition-first")},1e3)),e.num>1){e.slider.classList.remove("forwards","backwards");for(var s=0;s<e.num;s++)e.slides.children[s].classList.remove("current-slide","prev-slide","next-slide"),e.num&&e.indicators[s].classList.remove("current-indicator");e.prevSlideIndex<e.settings.slideIndex?e.slider.classList.add("forwards"):e.slider.classList.add("backwards"),e.slider.classList.add("animating"),e.prev.classList.add("prev-slide"),e.settings.slideIndex===e.num-1?e.slides.children[0].classList.add("next-slide"):e.slides.children[e.settings.slideIndex+1]&&e.slides.children[e.settings.slideIndex+1].classList.add("next-slide"),e.slides.children[e.settings.slideIndex].classList.add("current-slide"),e.num&&e.indicators[e.settings.slideIndex].classList.add("current-indicator"),"pan"===e.settings.transition&&(e.slider.children[1].style.transform="translateX(-"+e.settings.slideIndex/e.num*100+"00%)"),e.intervalPrevAnim=setTimeout(function(){e.slider.classList.remove("animating")},1e3),autoSlide(e)}}function updateIndex(e,s){e.prevSlideIndex=e.settings.slideIndex,e.settings.slideIndex=s}function autoSlide(e){!1===e.settings.paused&&(e.intervalSlideChange=setTimeout(function(){var s=e.settings.slideIndex+1;updateIndex(e,s),sliderChange(e)},e.settings.duration))}function clearTimeouts(e){e.settings.autoPause&&(e.settings.paused=!0),clearTimeout(e.intervalSlideChange),clearTimeout(e.intervalPrevAnim);for(var s=0;s<e.num;s++)e.slider.classList.remove("animating")}
\ No newline at end of file
let sliders=document.getElementsByClassName("skroll-slider");for(var sliderObjects=[],i=0;i<sliders.length;i++){var el=sliders[i],num=el.children.length,imgElements=el.querySelectorAll("img"),slides=el.children,imgUrls=Array.from(el.querySelectorAll("img")).map(function(e,s){return e.remove(),e.src}),slideText={};for(let e=0;e<slides.length;e++)slideText[e]=slides[e];if(sliderObjects[i]={slider:el,img:imgElements,slideText:slideText,imgUrls:imgUrls,num:num,settings:{effect:"zoom",animateText:!0,showIndicators:!0,showArrows:!0,paused:!1,autoPause:!1,slideIndex:0,duration:5e3,transition:"pan"}},el.hasAttribute("data-skroll")){var settings=JSON.parse(el.dataset.skroll);for(const e of Object.keys(settings))sliderObjects[i].settings[e]=settings[e]}sliderConstruct(sliderObjects[i])}function sliderConstruct(e){e.slider.classList.add(e.settings.effect+"-effect",e.settings.animateText?"animate-text":null,e.settings.transition);var s=document.createDocumentFragment(),t=document.createElement("DIV");0==e.settings.showArrows?t.setAttribute("class","arrows hidden"):t.setAttribute("class","arrows");var n=document.createElement("DIV");n.setAttribute("class","slide-arrow left-arrow");var d=document.createElement("DIV");d.setAttribute("class","slide-arrow right-arrow"),t.appendChild(n),t.appendChild(d),s.prepend(t),e.arrows=[n,d];var r=document.createElement("DIV");e.slides=r,r.classList.add("slides"),"pan"===e.settings.transition&&(r.style.width=e.num+"00%"),"pan"===e.settings.transition&&(r.style.width=e.num+"00%");var l={slide:null,slideWrap:null};for(let s=0;s<e.num;s++)l.slideWrap=document.createElement("DIV"),s===e.settings.slideIndex?l.slideWrap.setAttribute("class","slide-wrap current-slide"):l.slideWrap.setAttribute("class","slide-wrap"),l.slide=document.createElement("DIV"),l.slide.setAttribute("class","slide"),l.slideText=e.slideText[s],l.slideText.setAttribute("class","slide-text"),l.slide.style.backgroundImage="url("+e.imgUrls[s]+")",l.slideWrap.appendChild(l.slide),l.slideWrap.appendChild(l.slideText),r.appendChild(l.slideWrap);s.appendChild(r),e.indicators={};var a=document.createElement("DIV");0==e.settings.showIndicators?a.setAttribute("class","indicators hidden"):a.setAttribute("class","indicators");for(let t=0;t<e.num;t++){var c=document.createElement("SPAN");t===e.settings.slideIndex?c.setAttribute("class","slide-indicator current-indicator"):c.setAttribute("class","slide-indicator"),c.setAttribute("data-slide",t),a.appendChild(c),s.appendChild(a),e.indicators[t]=c}e.slider.appendChild(s),setBindings(e),autoSlide(sliderObjects[i])}function setBindings(e){for(var s=0;s<e.arrows.length;s++)e.arrows[s].addEventListener("click",function(s){if(!e.slider.classList.contains("animating")){if(e.prevSlideIndex=e.settings.slideIndex,s.target.classList.contains("left-arrow"))var t=e.settings.slideIndex-1;else if(s.target.classList.contains("right-arrow"))t=e.settings.slideIndex+1;updateIndex(e,t),clearTimeouts(e),sliderChange(e)}});for(s=0;s<e.num;s++)e.indicators[s].addEventListener("click",function(s){e.slider.classList.contains("animating")||!1===s.target.classList.contains("current-indicator")&&(clearTimeouts(e),updateIndex(e,Number(s.target.dataset.slide)),sliderChange(e))})}function sliderChange(e){if(e.prev=e.slider.getElementsByClassName("current-slide")[0],e.settings.slideIndex<0?(e.settings.slideIndex=e.num-1,e.num&&e.indicators[0].parentElement.classList.add("transition-last"),setTimeout(function(){e.num&&e.indicators[0].parentElement.classList.remove("transition-last")},1e3)):e.settings.slideIndex>e.num-1&&(e.settings.slideIndex=0,e.num&&e.indicators[0].parentElement.classList.add("transition-first"),setTimeout(function(){e.num&&e.indicators[0].parentElement.classList.remove("transition-first")},1e3)),e.num>1){e.slider.classList.remove("forwards","backwards");for(var s=0;s<e.num;s++)e.slides.children[s].classList.remove("current-slide","prev-slide","next-slide"),e.num&&e.indicators[s].classList.remove("current-indicator");e.prevSlideIndex<e.settings.slideIndex?e.slider.classList.add("forwards"):e.slider.classList.add("backwards"),e.slider.classList.add("animating"),e.prev.classList.add("prev-slide"),e.settings.slideIndex===e.num-1?e.slides.children[0].classList.add("next-slide"):e.slides.children[e.settings.slideIndex+1]&&e.slides.children[e.settings.slideIndex+1].classList.add("next-slide"),e.slides.children[e.settings.slideIndex].classList.add("current-slide"),e.num&&e.indicators[e.settings.slideIndex].classList.add("current-indicator"),"pan"===e.settings.transition&&(e.slider.children[1].style.transform="translateX(-"+e.settings.slideIndex/e.num*100+"00%)"),e.intervalPrevAnim=setTimeout(function(){e.slider.classList.remove("animating")},1e3),autoSlide(e)}}function updateIndex(e,s){e.prevSlideIndex=e.settings.slideIndex,e.settings.slideIndex=s}function autoSlide(e){!1===e.settings.paused&&(e.intervalSlideChange=setTimeout(function(){var s=e.settings.slideIndex+1;updateIndex(e,s),sliderChange(e)},e.settings.duration))}function clearTimeouts(e){e.settings.autoPause&&(e.settings.paused=!0),clearTimeout(e.intervalSlideChange),clearTimeout(e.intervalPrevAnim);for(var s=0;s<e.num;s++)e.slider.classList.remove("animating")}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment