Commit 5de14215 authored by Michael Iseard's avatar Michael Iseard
Browse files

update citrus

parent cf573434
This diff is collapsed.
"use strict";var getSliders=function(){var e=[],t=function(e){this.sliderContainer=e,this.slideText=function(e){var t={};for(let s=0;s<e.length;s++)t[s]=e[s];return t}(e.children),this.num=e.children.length,this.imgUrls=function(e){return Array.from(e.children).map(function(e,t){var s=e.getElementsByTagName("img")[0].src;return e.getElementsByTagName("img")[0].remove(),s})}(e),this.settings={width:"100%",height:"100%",autoHeight:!1,effect:!0,effectType:"zoom",animateText:!0,showIndicators:!0,showArrows:!0,paused:!1,autoPause:!0,slideIndex:0,slideDuration:5e3,slideTransition:"pan"},this.reset=function(){a(this),c(this),o(this)}};let s=document.getElementsByClassName("citrus-slider");for(var i=0;i<s.length;i++){e[i]=new t(s[i]);var n=e[i];r(n),a(n),o(n)}function r(e){if(e.sliderContainer.hasAttribute("data-citrus")){var t=JSON.parse(e.sliderContainer.dataset.citrus);for(const s of Object.keys(t))e.settings[s]=t[s];e.sliderContainer.removeAttribute("data-citrus"),e.settings.slideIndex>e.num||e.settings.slideIndex<=0?e.settings.slideIndex=0:e.settings.slideIndex--}}function a(e){var t=e.settings.height;!0===e.settings.autoHeight&&(t=function(e){var t=0;for(let s=0;s<e.num;s++){let i=e.slideText[s].offsetHeight;t<i&&(t=i)}return(t+=250)+"px"}(e)),e.sliderContainer.setAttribute("style","width:"+e.settings.width+"; height:"+t),e.sliderContainer.setAttribute("class","citrus-slider"),e.sliderContainer.classList.add("transition-"+e.settings.slideTransition),e.settings.effect&&e.sliderContainer.classList.add("effect-"+e.settings.effectType),e.settings.animateText&&e.sliderContainer.classList.add("animate-text"),function(e){var t=document.createDocumentFragment(),s=document.createElement("DIV");0==e.settings.showArrows?s.setAttribute("class","arrows hidden"):s.setAttribute("class","arrows");var i=document.createElement("DIV");i.setAttribute("class","slide-arrow left-arrow");var n=document.createElement("DIV");n.setAttribute("class","slide-arrow right-arrow"),s.appendChild(i),s.appendChild(n),t.appendChild(s),e.arrows=[i,n];var r=document.createElement("DIV");e.slides=r,r.classList.add("slides"),"pan"===e.settings.slideTransition&&(r.style.width=e.num+"00%");"pan"===e.settings.slideTransition&&(r.style.width=e.num+"00%",r.style.transform="translateX(-"+e.settings.slideIndex/e.num*100+"%)");var a={slide:null,slideWrap:null};for(let t=0;t<e.num;t++)a.slideWrap=document.createElement("DIV"),t===e.settings.slideIndex?a.slideWrap.setAttribute("class","slide-wrap current-slide"):a.slideWrap.setAttribute("class","slide-wrap"),a.slide=document.createElement("DIV"),a.slide.setAttribute("class","slide"),a.slideText=e.slideText[t],a.slideText.setAttribute("class","slide-text"),a.slide.style.backgroundImage="url("+e.imgUrls[t]+")",a.slideWrap.appendChild(a.slide),a.slideWrap.appendChild(a.slideText),r.appendChild(a.slideWrap);t.appendChild(r),e.indicators={};var o=document.createElement("DIV");0==e.settings.showIndicators?o.setAttribute("class","indicators hidden"):o.setAttribute("class","indicators");for(let s=0;s<e.num;s++){var u=document.createElement("SPAN");s===e.settings.slideIndex?u.setAttribute("class","slide-indicator current-indicator"):u.setAttribute("class","slide-indicator"),u.setAttribute("data-slide",s),o.appendChild(u),t.appendChild(o),e.indicators[s]=u}e.sliderContainer.innerHTML="",e.sliderContainer.appendChild(t),function(e){for(var t=0;t<e.arrows.length;t++)e.arrows[t].addEventListener("click",function(t){if(e.settings.autoPause&&(e.settings.paused=!0),!e.sliderContainer.classList.contains("animating")){if(e.prevSlideIndex=e.settings.slideIndex,t.target.classList.contains("left-arrow"))var s=e.settings.slideIndex-1;else if(t.target.classList.contains("right-arrow"))var s=e.settings.slideIndex+1;l(e,s),c(e),d(e)}});for(t=0;t<e.num;t++)e.indicators[t].addEventListener("click",function(t){e.settings.autoPause&&(e.settings.paused=!0),e.sliderContainer.classList.contains("animating")||!1===t.target.classList.contains("current-indicator")&&(c(e),l(e,Number(t.target.dataset.slide)),d(e))})}(e)}(e)}function d(e){if(e.prev=e.sliderContainer.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.sliderContainer.classList.remove("forwards","backwards");for(var t=0;t<e.num;t++)e.slides.children[t].classList.remove("current-slide","prev-slide","next-slide"),e.num&&e.indicators[t].classList.remove("current-indicator");e.prevSlideIndex<e.settings.slideIndex?e.sliderContainer.classList.add("forwards"):e.sliderContainer.classList.add("backwards"),e.sliderContainer.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.slideTransition&&(e.sliderContainer.children[1].style.transform="translateX(-"+e.settings.slideIndex/e.num*100+"%)"),e.intervalPrevAnim=setTimeout(function(){e.sliderContainer.classList.remove("animating")},1e3),o(e)}}function l(e,t){e.prevSlideIndex=e.settings.slideIndex,e.settings.slideIndex=t}function o(e){!1===e.settings.paused&&(e.intervalSlideChange=setTimeout(function(){var t=e.settings.slideIndex+1;l(e,t),d(e)},e.settings.slideDuration))}function c(e){clearTimeout(e.intervalSlideChange),clearTimeout(e.intervalPrevAnim);for(var t=0;t<e.num;t++)e.sliderContainer.classList.remove("animating")}return e}();
//# sourceMappingURL=../map/citrus-slider.min.js.map
"use strict";function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var citrus=function(){var t=[],e=function t(e){_classCallCheck(this,t),this.sliderContainer=e,this.slideText=function(t){for(var e={},s=0;s<t.length;s++)e[s]=t[s];return e}(e.children),this.num=e.children.length,this.imgUrls=function(t){var e=Array.from(t.children).map(function(t){return t.getElementsByTagName("img")[0].src}),s=t.getElementsByTagName("img");for(;s[0];)s[0].remove();return e}(e),this.settings={animateText:!0,animationDuration:.8,autoHeight:!1,autoPause:!0,effect:!0,effectType:"zoom",height:"100%",paused:!1,showArrows:!0,showIndicators:!0,slideDuration:5e3,slideIndex:0,slideTransition:"pan",width:"100%"}};e.prototype.goToSlide=function(t){this.settings.slideIndex=t,n(this)},e.prototype.stop=function(){this.settings.paused=!0,clearTimeout(this.intervalSlideChange)},e.prototype.play=function(){this.settings.paused=!1,r(this)},e.prototype.prevSlide=function(){this.settings.slideIndex--,n(this)},e.prototype.nextSlide=function(){this.settings.slideIndex++,n(this)},e.prototype.reset=function(){clearTimeout(this.intervalSlideChange),i(this),r(this)};var s=Array.from(document.getElementsByClassName("citrus-slider"));function i(t){var e=t.settings.height;!0===t.settings.autoHeight&&(e=function(t){for(var e=0,s=0;s<t.num;s++){var i=t.slideText[s].offsetHeight;e<i&&(e=i)}return(e+=250)+"px"}(t)),t.sliderContainer.setAttribute("style","width:"+t.settings.width+"; height:"+e),t.sliderContainer.setAttribute("class","citrus-slider"),t.sliderContainer.classList.add("transition-"+t.settings.slideTransition),t.settings.effect&&t.sliderContainer.classList.add("effect-"+t.settings.effectType),t.settings.animateText&&t.sliderContainer.classList.add("animate-text"),function(t){var e=document.createDocumentFragment(),s=document.createElement("DIV");0==t.settings.showArrows?s.setAttribute("class","citrus-arrows hidden"):s.setAttribute("class","citrus-arrows");var i=document.createElement("DIV");i.setAttribute("class","slide-arrow left-arrow");var r=document.createElement("DIV");r.setAttribute("class","slide-arrow right-arrow"),s.appendChild(i),s.appendChild(r),e.appendChild(s),t.arrows=[i,r];var a=document.createElement("DIV");t.slides=a,a.setAttribute("class","citrus-slides"),"pan"===t.settings.slideTransition&&(a.style.width=t.num+"00%");"pan"===t.settings.slideTransition&&(a.style.width=t.num+"00%",a.style.transform="translateX(-"+t.settings.slideIndex/t.num*100+"%)");for(var d=0;d<t.num;d++){var l=document.createElement("DIV");l.setAttribute("style","animation-duration:"+t.settings.animationDuration+"s"),d===t.settings.slideIndex?l.setAttribute("class","slide-wrap current-slide"):l.setAttribute("class","slide-wrap");var o=document.createElement("DIV");o.setAttribute("class","slide");var c=t.slideText[d];c.setAttribute("class","slide-text"),o.style.backgroundImage="url("+t.imgUrls[d]+")",l.appendChild(o),l.appendChild(c),a.appendChild(l)}e.appendChild(a),t.indicators=[];var u=document.createElement("DIV");0==t.settings.showIndicators?u.setAttribute("class","citrus-indicators hidden"):u.setAttribute("class","citrus-indicators");for(var g=0;g<t.num;g++){var m=document.createElement("SPAN");g===t.settings.slideIndex?m.setAttribute("class","slide-indicator current-indicator"):m.setAttribute("class","slide-indicator"),m.setAttribute("data-slide",g),u.appendChild(m),e.appendChild(u),t.indicators[g]=m}t.sliderContainer.innerHTML="",t.sliderContainer.appendChild(e),function(t){var e=!0,s=!1,i=void 0;try{for(var r,a=t.arrows[Symbol.iterator]();!(e=(r=a.next()).done);e=!0){var d=r.value;d.addEventListener("click",function(e){t.settings.autoPause&&(t.settings.paused=!0),t.sliderContainer.classList.contains("animating")||(t.settings.prevIndex=t.settings.slideIndex,e.target.classList.contains("left-arrow")?t.settings.slideIndex--:e.target.classList.contains("right-arrow")&&t.settings.slideIndex++,n(t))})}}catch(t){s=!0,i=t}finally{try{!e&&a.return&&a.return()}finally{if(s)throw i}}var l=!0,o=!1,c=void 0;try{for(var u,g=t.indicators[Symbol.iterator]();!(l=(u=g.next()).done);l=!0){var m=u.value;m.addEventListener("click",function(e){t.settings.autoPause&&(t.settings.paused=!0),t.sliderContainer.classList.contains("animating")||!1===e.target.classList.contains("current-indicator")&&(t.settings.prevIndex=t.settings.slideIndex,t.settings.slideIndex=Number(e.target.dataset.slide),n(t))})}}catch(t){o=!0,c=t}finally{try{!l&&g.return&&g.return()}finally{if(o)throw c}}}(t)}(t)}function n(t){if(clearTimeout(t.intervalSlideChange),t.prev=t.sliderContainer.getElementsByClassName("current-slide")[0],t.settings.slideIndex<0?(t.settings.slideIndex=t.num-1,t.num&&(t.indicators[0].parentElement.classList.add("transition-last"),setTimeout(function(){t.indicators[0].parentElement.classList.remove("transition-last")},1e3))):t.settings.slideIndex>t.num-1&&(t.settings.slideIndex=0,t.num&&(t.indicators[0].parentElement.classList.add("transition-first"),setTimeout(function(){t.indicators[0].parentElement.classList.remove("transition-first")},1e3))),t.num>1){t.sliderContainer.classList.remove("forwards","backwards");for(var e=0;e<t.num;e++)t.slides.children[e].classList.remove("current-slide","prev-slide","next-slide"),t.num&&t.indicators[e].classList.remove("current-indicator");t.settings.prevIndex<t.settings.slideIndex?t.sliderContainer.classList.add("forwards"):t.sliderContainer.classList.add("backwards"),t.prev.classList.add("prev-slide"),t.settings.slideIndex===t.num-1?t.slides.children[0].classList.add("next-slide"):t.slides.children[t.settings.slideIndex+1]&&t.slides.children[t.settings.slideIndex+1].classList.add("next-slide"),t.slides.children[t.settings.slideIndex].classList.add("current-slide"),t.num&&t.indicators[t.settings.slideIndex].classList.add("current-indicator"),"pan"===t.settings.slideTransition&&(t.sliderContainer.children[1].style.transform="translateX(-"+t.settings.slideIndex/t.num*100+"%)"),t.sliderContainer.classList.add("animating"),t.intervalPrevAnim=setTimeout(function(){t.sliderContainer.classList.remove("animating")},1e3*t.settings.animationDuration),r(t)}}function r(t){!1===t.settings.paused&&(t.intervalSlideChange=setTimeout(function(){t.settings.prevIndex=t.settings.slideIndex,t.settings.slideIndex++,n(t)},t.settings.slideDuration))}return s.forEach(function(n,a){t[a]=new e(s[a]);var d=t[a];!function(t,e){if(t.sliderContainer.hasAttribute("data-citrus")){var s=JSON.parse(t.sliderContainer.dataset.citrus),i=!0,n=!1,r=void 0;try{for(var a,d=Object.keys(s)[Symbol.iterator]();!(i=(a=d.next()).done);i=!0){var l=a.value;t.settings[l]=s[l]}}catch(t){n=!0,r=t}finally{try{!i&&d.return&&d.return()}finally{if(n)throw r}}t.sliderContainer.removeAttribute("data-citrus"),t.settings.slideIndex>t.num||t.settings.slideIndex<=0?t.settings.slideIndex=0:t.settings.slideIndex--}"function"==typeof e&&e(t)}(d,i),r(d)}),t}();
\ 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