From b7d593ecd51de1cc2d3b0372ae25b465501d90f2 Mon Sep 17 00:00:00 2001 From: Nick Thomas Date: Sat, 18 May 2024 22:19:21 -0700 Subject: [PATCH] can pass in the axis --- docs/assets/js/glider.min.js | 2 +- glider.js | 17 +++++++++++++---- glider.min.js | 2 +- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/docs/assets/js/glider.min.js b/docs/assets/js/glider.min.js index cc00d96..e437abe 100644 --- a/docs/assets/js/glider.min.js +++ b/docs/assets/js/glider.min.js @@ -13,4 +13,4 @@ Release Date: October 25th, 2018 */ -!function(e){"function"==typeof define&&define.amd?define(e):"object"==typeof exports?module.exports=e():e()}(function(){var a="undefined"!=typeof window?window:this,e=a.Glider=function(e,t){var i=this;if(e._glider)return e._glider;if(i.ele=e,i.ele.classList.add("glider"),(i.ele._glider=i).opt=Object.assign({},{slidesToScroll:1,slidesToShow:1,resizeLock:!0,duration:.5,passiveListeners:!1,easing:function(e,t,i,o,s){return o*(t/=s)*t+i}},t),i.animate_id=i.page=i.slide=0,i.arrows={},i._opt=i.opt,i.opt.skipTrack)i.track=i.ele.children[0];else for(i.track=document.createElement("div"),i.ele.appendChild(i.track);1!==i.ele.children.length;)i.track.appendChild(i.ele.children[0]);i.track.classList.add("glider-track"),i.init(),i.resize=i.init.bind(i,!0),i.event(i.ele,"add",{scroll:i.updateControls.bind(i)},{passive:i.opt.passiveListeners}),i.event(a,"add",{resize:i.resize})},t=e.prototype;return t.init=function(e,t){var i,o=this,s=0,r=0,l=(o.slides=o.track.children,[].forEach.call(o.slides,function(e,t){e.classList.add("glider-slide"),e.setAttribute("data-gslide",t)}),o.containerWidth=o.ele.clientWidth,o.settingsBreakpoint());t=t||l,"auto"!==o.opt.slidesToShow&&void 0===o.opt._autoSlide||(i=o.containerWidth/o.opt.itemWidth,o.opt._autoSlide=o.opt.slidesToShow=o.opt.exactWidth?i:Math.max(1,Math.floor(i))),"auto"===o.opt.slidesToScroll&&(o.opt.slidesToScroll=Math.floor(o.opt.slidesToShow)),o.itemWidth=o.opt.exactWidth?o.opt.itemWidth:o.containerWidth/o.opt.slidesToShow,[].forEach.call(o.slides,function(e){e.style.height="auto",e.style.width=o.itemWidth+"px",s+=o.itemWidth,r=Math.max(e.offsetHeight,r)}),o.track.style.width=s+"px",o.trackWidth=s,o.isDrag=!1,o.preventClick=!1,o.move=!1,o.opt.resizeLock&&o.scrollTo(o.slide*o.itemWidth,0),(l||t)&&(o.bindArrows(),o.buildDots(),o.bindDrag()),o.updateControls(),o.emit(e?"refresh":"loaded")},t.bindDrag=function(){function e(){t.mouseDown=void 0,t.ele.classList.remove("drag"),t.isDrag&&(t.preventClick=!0),t.isDrag=!1}var t=this;t.mouse=t.mouse||t.handleMouse.bind(t);function i(){t.move=!0}var o={mouseup:e,mouseleave:e,mousedown:function(e){e.preventDefault(),e.stopPropagation(),t.mouseDown=e.clientX,t.ele.classList.add("drag"),t.move=!1,setTimeout(i,300)},touchstart:function(e){t.ele.classList.add("drag"),t.move=!1,setTimeout(i,300)},mousemove:t.mouse,click:function(e){t.preventClick&&t.move&&(e.preventDefault(),e.stopPropagation()),t.preventClick=!1,t.move=!1}};t.ele.classList.toggle("draggable",!0===t.opt.draggable),t.event(t.ele,"remove",o),t.opt.draggable&&t.event(t.ele,"add",o,{passive:t.opt.passiveListeners})},t.buildDots=function(){var e=this;if(e.opt.dots){if("string"==typeof e.opt.dots?e.dots=document.querySelector(e.opt.dots):e.dots=e.opt.dots,e.dots){e.dots.innerHTML="",e.dots.setAttribute("role","tablist"),e.dots.classList.add("glider-dots");for(var t=0;t=n.trackWidth),a=(n.opt.rewind||(n.arrows.prev&&(n.arrows.prev.classList.toggle("disabled",n.ele.scrollLeft<=0||t),n.arrows.prev.setAttribute("aria-disabled",n.arrows.prev.classList.contains("disabled"))),n.arrows.next&&(n.arrows.next.classList.toggle("disabled",Math.ceil(n.ele.scrollLeft+n.containerWidth)>=Math.floor(n.trackWidth)||t),n.arrows.next.setAttribute("aria-disabled",n.arrows.next.classList.contains("disabled")))),n.slide=Math.round(n.ele.scrollLeft/n.itemWidth),n.page=Math.round(n.ele.scrollLeft/n.containerWidth),n.slide+Math.floor(Math.floor(n.opt.slidesToShow)/2)),d=Math.floor(n.opt.slidesToShow)%2?0:a+1;1===Math.floor(n.opt.slidesToShow)&&(d=0),n.ele.scrollLeft+n.containerWidth>=Math.floor(n.trackWidth)&&(n.page=n.dots?n.dots.children.length-1:0),[].forEach.call(n.slides,function(e,t){var i=e.classList,e=i.contains("visible"),o=n.ele.scrollLeft,s=n.ele.scrollLeft+n.containerWidth,r=n.itemWidth*t,l=r+n.itemWidth,r=([].forEach.call(i,function(e){/^left|right/.test(e)&&i.remove(e)}),i.toggle("active",n.slide===t),a===t||d&&d===t?i.add("center"):(i.remove("center"),i.add([t=Math.floor(o)&&Math.floor(l)<=Math.ceil(s));i.toggle("visible",r),r!==e&&n.emit("slide-"+(r?"visible":"hidden"),{slide:t})}),n.dots&&[].forEach.call(n.dots.children,function(e,t){e.classList.toggle("active",n.page===t)}),e&&n.opt.scrollLock&&(clearTimeout(n.scrollLock),n.scrollLock=setTimeout(function(){clearTimeout(n.scrollLock),.02n.containerWidth+n.ele.scrollLeft&&n.scrollItem(n.getCurrentSlide()))},n.opt.scrollLockDelay||250))},t.getCurrentSlide=function(){return this.round(this.ele.scrollLeft/this.itemWidth)},t.scrollItem=function(e,t,i){i&&i.preventDefault();var o,s=this,r=e,i=(++s.animate_id,s.slide),l=!0===t?(e=Math.round(e*s.containerWidth/s.itemWidth))*s.itemWidth:("string"==typeof e&&(l="prev"===e,e=s.opt.slidesToScroll%1||s.opt.slidesToShow%1?s.getCurrentSlide():s.slide,l?e-=s.opt.slidesToScroll:e+=s.opt.slidesToScroll,s.opt.rewind&&(o=s.ele.scrollLeft,e=l&&!o?s.slides.length:!l&&o+s.containerWidth>=Math.floor(s.trackWidth)?0:e)),e=Math.max(Math.min(e,s.slides.length),0),s.slide=e,s.itemWidth*e);return s.emit("scroll-item",{prevSlide:i,slide:e}),s.scrollTo(l,s.opt.duration*Math.abs(s.ele.scrollLeft-l),function(){s.updateControls(),s.emit("animated",{value:r,type:"string"==typeof r?"arrow":t?"dot":"slide"})}),!1},t.settingsBreakpoint=function(){var e=this,t=e._opt.responsive;if(t){t.sort(function(e,t){return t.breakpoint-e.breakpoint});for(var i=0;i=o.breakpoint)return e.breakpoint!==o.breakpoint&&(e.opt=Object.assign({},e._opt,o.settings),e.breakpoint=o.breakpoint,!0)}}var s=0!==e.breakpoint;return e.opt=Object.assign({},e._opt),e.breakpoint=0,s},t.scrollTo=function(t,i,o){var s=this,r=(new Date).getTime(),l=s.animate_id,n=function(){var e=(new Date).getTime()-r;s.ele.scrollLeft=s.ele.scrollLeft+(t-s.ele.scrollLeft)*s.opt.easing(0,e,0,1,i),e=n.trackWidth),a=(n.opt.rewind||(n.arrows.prev&&(n.arrows.prev.classList.toggle("disabled",n.ele.scrollLeft<=0||t),n.arrows.prev.setAttribute("aria-disabled",n.arrows.prev.classList.contains("disabled"))),n.arrows.next&&(n.arrows.next.classList.toggle("disabled",Math.ceil(n.ele.scrollLeft+n.containerWidth)>=Math.floor(n.trackWidth)||t),n.arrows.next.setAttribute("aria-disabled",n.arrows.next.classList.contains("disabled")))),n.slide=Math.round(n.ele.scrollLeft/n.itemWidth),n.page=Math.round(n.ele.scrollLeft/n.containerWidth),n.slide+Math.floor(Math.floor(n.opt.slidesToShow)/2)),d=Math.floor(n.opt.slidesToShow)%2?0:a+1;1===Math.floor(n.opt.slidesToShow)&&(d=0),n.ele.scrollLeft+n.containerWidth>=Math.floor(n.trackWidth)&&(n.page=n.dots?n.dots.children.length-1:0),[].forEach.call(n.slides,function(e,t){var o=e.classList,e=o.contains("visible"),i=n.ele.scrollLeft,s=n.ele.scrollLeft+n.containerWidth,r=n.itemWidth*t,l=r+n.itemWidth,r=([].forEach.call(o,function(e){/^left|right/.test(e)&&o.remove(e)}),o.toggle("active",n.slide===t),a===t||d&&d===t?o.add("center"):(o.remove("center"),o.add([t=Math.floor(i)&&Math.floor(l)<=Math.ceil(s));o.toggle("visible",r),r!==e&&n.emit("slide-"+(r?"visible":"hidden"),{slide:t})}),n.dots&&[].forEach.call(n.dots.children,function(e,t){e.classList.toggle("active",n.page===t)}),e&&n.opt.scrollLock&&(clearTimeout(n.scrollLock),n.scrollLock=setTimeout(function(){clearTimeout(n.scrollLock),.02n.containerWidth+n.ele.scrollLeft&&n.scrollItem(n.getCurrentSlide()))},n.opt.scrollLockDelay||250))},t.getCurrentSlide=function(){return this.round(this.ele.scrollLeft/this.itemWidth)},t.scrollItem=function(e,t,o){o&&o.preventDefault();var i,s=this,r=e,o=(++s.animate_id,s.slide),l=!0===t?(e=Math.round(e*s.containerWidth/s.itemWidth))*s.itemWidth:("string"==typeof e&&(l="prev"===e,e=s.opt.slidesToScroll%1||s.opt.slidesToShow%1?s.getCurrentSlide():s.slide,l?e-=s.opt.slidesToScroll:e+=s.opt.slidesToScroll,s.opt.rewind&&(i=s.ele.scrollLeft,e=l&&!i?s.slides.length:!l&&i+s.containerWidth>=Math.floor(s.trackWidth)?0:e)),e=Math.max(Math.min(e,s.slides.length),0),s.slide=e,s.itemWidth*e);return s.emit("scroll-item",{prevSlide:o,slide:e}),s.scrollTo(l,s.opt.duration*Math.abs(s.ele.scrollLeft-l),function(){s.updateControls(),s.emit("animated",{value:r,type:"string"==typeof r?"arrow":t?"dot":"slide"})}),!1},t.settingsBreakpoint=function(){var e=this,t=e._opt.responsive;if(t){t.sort(function(e,t){return t.breakpoint-e.breakpoint});for(var o=0;o=i.breakpoint)return e.breakpoint!==i.breakpoint&&(e.opt=Object.assign({},e._opt,i.settings),e.breakpoint=i.breakpoint,!0)}}var s=0!==e.breakpoint;return e.opt=Object.assign({},e._opt),e.breakpoint=0,s},t.scrollTo=function(t,o,i){var s=this,r=(new Date).getTime(),l=s.animate_id,n=function(){var e=(new Date).getTime()-r;s.ele.scrollLeft=s.ele.scrollLeft+(t-s.ele.scrollLeft)*s.opt.easing(0,e,0,1,o),e=n.trackWidth),a=(n.opt.rewind||(n.arrows.prev&&(n.arrows.prev.classList.toggle("disabled",n.ele.scrollLeft<=0||t),n.arrows.prev.setAttribute("aria-disabled",n.arrows.prev.classList.contains("disabled"))),n.arrows.next&&(n.arrows.next.classList.toggle("disabled",Math.ceil(n.ele.scrollLeft+n.containerWidth)>=Math.floor(n.trackWidth)||t),n.arrows.next.setAttribute("aria-disabled",n.arrows.next.classList.contains("disabled")))),n.slide=Math.round(n.ele.scrollLeft/n.itemWidth),n.page=Math.round(n.ele.scrollLeft/n.containerWidth),n.slide+Math.floor(Math.floor(n.opt.slidesToShow)/2)),d=Math.floor(n.opt.slidesToShow)%2?0:a+1;1===Math.floor(n.opt.slidesToShow)&&(d=0),n.ele.scrollLeft+n.containerWidth>=Math.floor(n.trackWidth)&&(n.page=n.dots?n.dots.children.length-1:0),[].forEach.call(n.slides,function(e,t){var i=e.classList,e=i.contains("visible"),o=n.ele.scrollLeft,s=n.ele.scrollLeft+n.containerWidth,r=n.itemWidth*t,l=r+n.itemWidth,r=([].forEach.call(i,function(e){/^left|right/.test(e)&&i.remove(e)}),i.toggle("active",n.slide===t),a===t||d&&d===t?i.add("center"):(i.remove("center"),i.add([t=Math.floor(o)&&Math.floor(l)<=Math.ceil(s));i.toggle("visible",r),r!==e&&n.emit("slide-"+(r?"visible":"hidden"),{slide:t})}),n.dots&&[].forEach.call(n.dots.children,function(e,t){e.classList.toggle("active",n.page===t)}),e&&n.opt.scrollLock&&(clearTimeout(n.scrollLock),n.scrollLock=setTimeout(function(){clearTimeout(n.scrollLock),.02n.containerWidth+n.ele.scrollLeft&&n.scrollItem(n.getCurrentSlide()))},n.opt.scrollLockDelay||250))},t.getCurrentSlide=function(){return this.round(this.ele.scrollLeft/this.itemWidth)},t.scrollItem=function(e,t,i){i&&i.preventDefault();var o,s=this,r=e,i=(++s.animate_id,s.slide),l=!0===t?(e=Math.round(e*s.containerWidth/s.itemWidth))*s.itemWidth:("string"==typeof e&&(l="prev"===e,e=s.opt.slidesToScroll%1||s.opt.slidesToShow%1?s.getCurrentSlide():s.slide,l?e-=s.opt.slidesToScroll:e+=s.opt.slidesToScroll,s.opt.rewind&&(o=s.ele.scrollLeft,e=l&&!o?s.slides.length:!l&&o+s.containerWidth>=Math.floor(s.trackWidth)?0:e)),e=Math.max(Math.min(e,s.slides.length),0),s.slide=e,s.itemWidth*e);return s.emit("scroll-item",{prevSlide:i,slide:e}),s.scrollTo(l,s.opt.duration*Math.abs(s.ele.scrollLeft-l),function(){s.updateControls(),s.emit("animated",{value:r,type:"string"==typeof r?"arrow":t?"dot":"slide"})}),!1},t.settingsBreakpoint=function(){var e=this,t=e._opt.responsive;if(t){t.sort(function(e,t){return t.breakpoint-e.breakpoint});for(var i=0;i=o.breakpoint)return e.breakpoint!==o.breakpoint&&(e.opt=Object.assign({},e._opt,o.settings),e.breakpoint=o.breakpoint,!0)}}var s=0!==e.breakpoint;return e.opt=Object.assign({},e._opt),e.breakpoint=0,s},t.scrollTo=function(t,i,o){var s=this,r=(new Date).getTime(),l=s.animate_id,n=function(){var e=(new Date).getTime()-r;s.ele.scrollLeft=s.ele.scrollLeft+(t-s.ele.scrollLeft)*s.opt.easing(0,e,0,1,i),e=n.trackWidth),a=(n.opt.rewind||(n.arrows.prev&&(n.arrows.prev.classList.toggle("disabled",n.ele.scrollLeft<=0||t),n.arrows.prev.setAttribute("aria-disabled",n.arrows.prev.classList.contains("disabled"))),n.arrows.next&&(n.arrows.next.classList.toggle("disabled",Math.ceil(n.ele.scrollLeft+n.containerWidth)>=Math.floor(n.trackWidth)||t),n.arrows.next.setAttribute("aria-disabled",n.arrows.next.classList.contains("disabled")))),n.slide=Math.round(n.ele.scrollLeft/n.itemWidth),n.page=Math.round(n.ele.scrollLeft/n.containerWidth),n.slide+Math.floor(Math.floor(n.opt.slidesToShow)/2)),d=Math.floor(n.opt.slidesToShow)%2?0:a+1;1===Math.floor(n.opt.slidesToShow)&&(d=0),n.ele.scrollLeft+n.containerWidth>=Math.floor(n.trackWidth)&&(n.page=n.dots?n.dots.children.length-1:0),[].forEach.call(n.slides,function(e,t){var o=e.classList,e=o.contains("visible"),i=n.ele.scrollLeft,s=n.ele.scrollLeft+n.containerWidth,r=n.itemWidth*t,l=r+n.itemWidth,r=([].forEach.call(o,function(e){/^left|right/.test(e)&&o.remove(e)}),o.toggle("active",n.slide===t),a===t||d&&d===t?o.add("center"):(o.remove("center"),o.add([t=Math.floor(i)&&Math.floor(l)<=Math.ceil(s));o.toggle("visible",r),r!==e&&n.emit("slide-"+(r?"visible":"hidden"),{slide:t})}),n.dots&&[].forEach.call(n.dots.children,function(e,t){e.classList.toggle("active",n.page===t)}),e&&n.opt.scrollLock&&(clearTimeout(n.scrollLock),n.scrollLock=setTimeout(function(){clearTimeout(n.scrollLock),.02n.containerWidth+n.ele.scrollLeft&&n.scrollItem(n.getCurrentSlide()))},n.opt.scrollLockDelay||250))},t.getCurrentSlide=function(){return this.round(this.ele.scrollLeft/this.itemWidth)},t.scrollItem=function(e,t,o){o&&o.preventDefault();var i,s=this,r=e,o=(++s.animate_id,s.slide),l=!0===t?(e=Math.round(e*s.containerWidth/s.itemWidth))*s.itemWidth:("string"==typeof e&&(l="prev"===e,e=s.opt.slidesToScroll%1||s.opt.slidesToShow%1?s.getCurrentSlide():s.slide,l?e-=s.opt.slidesToScroll:e+=s.opt.slidesToScroll,s.opt.rewind&&(i=s.ele.scrollLeft,e=l&&!i?s.slides.length:!l&&i+s.containerWidth>=Math.floor(s.trackWidth)?0:e)),e=Math.max(Math.min(e,s.slides.length),0),s.slide=e,s.itemWidth*e);return s.emit("scroll-item",{prevSlide:o,slide:e}),s.scrollTo(l,s.opt.duration*Math.abs(s.ele.scrollLeft-l),function(){s.updateControls(),s.emit("animated",{value:r,type:"string"==typeof r?"arrow":t?"dot":"slide"})}),!1},t.settingsBreakpoint=function(){var e=this,t=e._opt.responsive;if(t){t.sort(function(e,t){return t.breakpoint-e.breakpoint});for(var o=0;o=i.breakpoint)return e.breakpoint!==i.breakpoint&&(e.opt=Object.assign({},e._opt,i.settings),e.breakpoint=i.breakpoint,!0)}}var s=0!==e.breakpoint;return e.opt=Object.assign({},e._opt),e.breakpoint=0,s},t.scrollTo=function(t,o,i){var s=this,r=(new Date).getTime(),l=s.animate_id,n=function(){var e=(new Date).getTime()-r;s.ele.scrollLeft=s.ele.scrollLeft+(t-s.ele.scrollLeft)*s.opt.easing(0,e,0,1,o),e