You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

3 lines
13 KiB

/*! UIkit 3.0.0-rc.17 | http://www.getuikit.com | (c) 2014 - 2018 YOOtheme | MIT License */
!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?module.exports=i(require("uikit-util")):"function"==typeof define&&define.amd?define("uikitslider",["uikit-util"],i):t.UIkitSlider=i(t.UIkit.util)}(this,function(f){"use strict";function n(t){return.5*t+300}function l(t,i){return void 0===t&&(t=0),void 0===i&&(i="%"),"translateX("+t+(t?i:"")+")"}function u(t,i,e){var n,s=v(t,i);return e?s-(n=t,g(i).width/2-g(n).width/2):Math.min(s,r(i))}function r(t){return Math.max(0,c(t)-g(t).width)}function c(t){return m(t).reduce(function(t,i){return g(i).width+t},0)}function v(t,i){return(f.position(t).left+(f.isRtl?g(t).width-g(i).width:0))*(f.isRtl?-1:1)}function g(t){return t.getBoundingClientRect()}function p(t,i,e){f.trigger(t,f.createEvent(i,!1,!1,e))}function m(t){return f.toNodes(t.children)}var t={mixins:[{connected:function(){f.addClass(this.$el,this.$name)}},{mixins:[{props:{autoplay:Boolean,autoplayInterval:Number,pauseOnHover:Boolean},data:{autoplay:!1,autoplayInterval:7e3,pauseOnHover:!0},connected:function(){this.startAutoplay()},disconnected:function(){this.stopAutoplay()},events:[{name:"visibilitychange",el:document,handler:function(){document.hidden?this.stopAutoplay():this.startAutoplay()}},{name:f.pointerDown,handler:"stopAutoplay"},{name:"mouseenter",filter:function(){return this.autoplay},handler:function(){this.isHovering=!0}},{name:"mouseleave",filter:function(){return this.autoplay},handler:function(){this.isHovering=!1}}],methods:{startAutoplay:function(){var t=this;this.stopAutoplay(),this.autoplay&&(this.interval=setInterval(function(){return!(t.isHovering&&t.pauseOnHover)&&!t.stack.length&&t.show("next")},this.autoplayInterval))},stopAutoplay:function(){this.interval&&clearInterval(this.interval)}}},{data:{threshold:10,preventCatch:!1},created:function(){var n=this;["start","move","end"].forEach(function(t){var e=n[t];n[t]=function(t){var i=f.getPos(t).x*(f.isRtl?-1:1);n.prevPos=i!==n.pos?n.pos:n.prevPos,n.pos=i,e(t)}})},events:[{name:f.pointerDown,delegate:function(){return this.slidesSelector},handler:function(t){var i;!f.isTouch(t)&&(!(i=t.target).children.length&&i.childNodes.length)||0<t.button||this.length<2||this.preventCatch||this.start(t)}},{name:"touchmove",passive:!1,handler:"move",delegate:function(){return this.slidesSelector}},{name:"dragstart",handler:function(t){t.preventDefault()}}],methods:{start:function(){var t=this;this.drag=this.pos,this._transitioner?(this.percent=this._transitioner.percent(),this.drag+=this._transitioner.getDistance()*this.percent*this.dir,this._transitioner.cancel(),this._transitioner.translate(this.percent),this.dragging=!0,this.stack=[]):this.prevIndex=this.index;var i=f.on(document,f.pointerMove.replace(" touchmove",""),this.move,{passive:!1});this.unbindMove=function(){i(),t.unbindMove=null},f.on(window,"scroll",this.unbindMove),f.on(document,f.pointerUp,this.end,!0)},move:function(t){var i=this;if(this.unbindMove){var e=this.pos-this.drag;if(!(0===e||this.prevPos===this.pos||!this.dragging&&Math.abs(e)<this.threshold)){t.cancelable&&t.preventDefault(),this.dragging=!0,this.dir=e<0?1:-1;for(var n=this.slides,s=this.prevIndex,r=Math.abs(e),h=this.getIndex(s+this.dir,s),o=this._getDistance(s,h)||n[s].offsetWidth;h!==s&&o<r;)i.drag-=o*i.dir,s=h,r-=o,h=i.getIndex(s+i.dir,s),o=i._getDistance(s,h)||n[s].offsetWidth;this.percent=r/o;var a,d=n[s],l=n[h],u=this.index!==h,c=s===h;[this.index,this.prevIndex].filter(function(t){return!f.includes([h,s],t)}).forEach(function(t){f.trigger(n[t],"itemhidden",[i]),c&&(a=!0,i.prevIndex=s)}),(this.index===s&&this.prevIndex!==s||a)&&f.trigger(n[this.index],"itemshown",[this]),u&&(this.prevIndex=s,this.index=h,!c&&f.trigger(d,"beforeitemhide",[this]),f.trigger(l,"beforeitemshow",[this])),this._transitioner=this._translate(Math.abs(this.percent),d,!c&&l),u&&(!c&&f.trigger(d,"itemhide",[this]),f.trigger(l,"itemshow",[this]))}}},end:function(){if(f.off(window,"scroll",this.unbindMove),this.unbindMove&&this.unbindMove(),f.off(document,f.pointerUp,this.end,!0),this.dragging){if(this.dragging=null,this.index===this.prevIndex)this.percent=1-this.percent,this.dir*=-1,this._show(!1,this.index,!0),this._transitioner=null;else{var t=(f.isRtl?this.dir*(f.isRtl?1:-1):this.dir)<0==this.prevPos>this.pos;this.index=t?this.index:this.prevIndex,t&&(this.percent=1-this.percent),this.show(0<this.dir&&!t||this.dir<0&&t?"next":"previous",!0)}f.preventClick()}this.drag=this.percent=null}}},{data:{selNav:!1},computed:{nav:function(t,i){var e=t.selNav;return f.$(e,i)},navItemSelector:function(t){var i=t.attrItem;return"["+i+"],[data-"+i+"]"},navItems:function(t,i){return f.$$(this.navItemSelector,i)}},update:{write:function(){var e=this;this.nav&&this.length!==this.nav.children.length&&f.html(this.nav,this.slides.map(function(t,i){return"<li "+e.attrItem+'="'+i+'"><a href="#"></a></li>'}).join("")),f.toggleClass(f.$$(this.navItemSelector,this.$el).concat(this.nav),"uk-hidden",!this.maxIndex),this.updateNav()},events:["load","resize"]},events:[{name:"click",delegate:function(){return this.navItemSelector},handler:function(t){t.preventDefault(),t.current.blur(),this.show(f.data(t.current,this.attrItem))}},{name:"itemshow",handler:"updateNav"}],methods:{updateNav:function(){var e=this,n=this.getValidIndex();this.navItems.forEach(function(t){var i=f.data(t,e.attrItem);f.toggleClass(t,e.clsActive,f.toNumber(i)===n),f.toggleClass(t,"uk-invisible",e.finite&&("previous"===i&&0===n||"next"===i&&n>=e.maxIndex))})}}}],props:{clsActivated:Boolean,easing:String,index:Number,finite:Boolean,velocity:Number},data:function(){return{easing:"ease",finite:!1,velocity:1,index:0,stack:[],percent:0,clsActive:"uk-active",clsActivated:!1,Transitioner:!1,transitionOptions:{}}},computed:{duration:function(t,i){var e=t.velocity;return n(i.offsetWidth/e)},length:function(){return this.slides.length},list:function(t,i){var e=t.selList;return f.$(e,i)},maxIndex:function(){return this.length-1},slidesSelector:function(t){return t.selList+" > *"},slides:function(){return f.toNodes(this.list.children)}},events:{itemshown:function(){this.$update(this.list)}},methods:{show:function(t,i){var e=this;if(void 0===i&&(i=!1),!this.dragging&&this.length){var n=this.stack,s=i?0:n.length,r=function(){n.splice(s,1),n.length&&e.show(n.shift(),!0)};if(n[i?"unshift":"push"](t),!i&&1<n.length)2===n.length&&this._transitioner.forward(Math.min(this.duration,200));else{var h=this.index,o=f.hasClass(this.slides,this.clsActive)&&this.slides[h],a=this.getIndex(t,this.index),d=this.slides[a];if(o!==d){var l,u;if(this.dir=(u=h,"next"===(l=t)?1:"previous"===l?-1:l<u?-1:1),this.prevIndex=h,this.index=a,o&&f.trigger(o,"beforeitemhide",[this]),!f.trigger(d,"beforeitemshow",[this,o]))return this.index=this.prevIndex,void r();var c=this._show(o,d,i).then(function(){return o&&f.trigger(o,"itemhidden",[e]),f.trigger(d,"itemshown",[e]),new f.Promise(function(t){f.fastdom.write(function(){n.shift(),n.length?e.show(n.shift(),!0):e._transitioner=null,t()})})});return o&&f.trigger(o,"itemhide",[this]),f.trigger(d,"itemshow",[this]),c}r()}}},getIndex:function(t,i){return void 0===t&&(t=this.index),void 0===i&&(i=this.index),f.clamp(f.getIndex(t,this.slides,i,this.finite),0,this.maxIndex)},getValidIndex:function(t,i){return void 0===t&&(t=this.index),void 0===i&&(i=this.prevIndex),this.getIndex(t,i)},_show:function(t,i,e){if(this._transitioner=this._getTransitioner(t,i,this.dir,f.assign({easing:e?i.offsetWidth<600?"cubic-bezier(0.25, 0.46, 0.45, 0.94)":"cubic-bezier(0.165, 0.84, 0.44, 1)":this.easing},this.transitionOptions)),!e&&!t)return this._transitioner.translate(1),f.Promise.resolve();var n=this.stack.length;return this._transitioner[1<n?"forward":"show"](1<n?Math.min(this.duration,75+75/(n-1)):this.duration,this.percent)},_getDistance:function(t,i){return new this._getTransitioner(t,t!==i&&i).getDistance()},_translate:function(t,i,e){void 0===i&&(i=this.prevIndex),void 0===e&&(e=this.index);var n=this._getTransitioner(i!==e&&i,e);return n.translate(t),n},_getTransitioner:function(t,i,e,n){return void 0===t&&(t=this.prevIndex),void 0===i&&(i=this.index),void 0===e&&(e=this.dir||1),void 0===n&&(n=this.transitionOptions),new this.Transitioner(f.isNumber(t)?this.slides[t]:t,f.isNumber(i)?this.slides[i]:i,e*(f.isRtl?-1:1),n)}}},{update:{write:function(){if(!this.stack.length&&!this.dragging){var t=this.getValidIndex();delete this.index,f.removeClass(this.slides,this.clsActive,this.clsActivated),this.show(t)}},events:["load","resize"]}}],props:{center:Boolean,sets:Boolean},data:{center:!1,sets:!1,attrItem:"uk-slider-item",selList:".uk-slider-items",selNav:".uk-slider-nav",clsContainer:"uk-slider-container",Transitioner:function(s,n,r,t){var i=t.center,h=t.easing,o=t.list,a=new f.Deferred,e=s?u(s,o,i):u(n,o,i)+g(n).width*r,d=n?u(n,o,i):e+g(s).width*r*(f.isRtl?-1:1);return{dir:r,show:function(t,i,e){void 0===i&&(i=0);var n=e?"linear":h;return t-=Math.round(t*f.clamp(i,-1,1)),this.translate(i),s&&this.updateTranslates(),i=s?i:f.clamp(i,0,1),p(this.getItemIn(),"itemin",{percent:i,duration:t,timing:n,dir:r}),s&&p(this.getItemIn(!0),"itemout",{percent:1-i,duration:t,timing:n,dir:r}),f.Transition.start(o,{transform:l(-d*(f.isRtl?-1:1),"px")},t,n).then(a.resolve,f.noop),a.promise},stop:function(){return f.Transition.stop(o)},cancel:function(){f.Transition.cancel(o)},reset:function(){f.css(o,"transform","")},forward:function(t,i){return void 0===i&&(i=this.percent()),f.Transition.cancel(o),this.show(t,i,!0)},translate:function(t){var i=this.getDistance()*r*(f.isRtl?-1:1);f.css(o,"transform",l(f.clamp(i-i*t-d,-c(o),g(o).width)*(f.isRtl?-1:1),"px")),this.updateTranslates(),s&&(t=f.clamp(t,-1,1),p(this.getItemIn(),"itemtranslatein",{percent:t,dir:r}),p(this.getItemIn(!0),"itemtranslateout",{percent:1-t,dir:r}))},percent:function(){return Math.abs((f.css(o,"transform").split(",")[4]*(f.isRtl?-1:1)+e)/(d-e))},getDistance:function(){return Math.abs(d-e)},getItemIn:function(t){void 0===t&&(t=!1);var i=this.getActives(),e=f.sortBy(m(o),"offsetLeft"),n=f.index(e,i[0<r*(t?-1:1)?i.length-1:0]);return~n&&e[n+(s&&!t?r:0)]},getActives:function(){var e=u(s||n,o,i);return f.sortBy(m(o).filter(function(t){var i=v(t,o);return e<=i&&i+g(t).width<=g(o).width+e}),"offsetLeft")},updateTranslates:function(){var e=this.getActives();m(o).forEach(function(t){var i=f.includes(e,t);p(t,"itemtranslate"+(i?"in":"out"),{percent:i?1:0,dir:t.offsetLeft<=n.offsetLeft?1:-1})})}}}},computed:{avgWidth:function(){return c(this.list)/this.length},finite:function(t){return t.finite||c(this.list)<g(this.list).width+m(this.list).reduce(function(t,i){return Math.max(t,g(i).width)},0)+this.center},maxIndex:function(){if(!this.finite||this.center&&!this.sets)return this.length-1;if(this.center)return this.sets[this.sets.length-1];f.css(this.slides,"order","");for(var t=r(this.list),i=this.length;i--;)if(v(this.list.children[i],this.list)<t)return Math.min(i+1,this.length-1);return 0},sets:function(t){var r=this,i=t.sets,h=g(this.list).width/(this.center?2:1),o=0,a=h,d=0;return(i=i&&this.slides.reduce(function(t,i,e){var n=g(i).width;if(o<d+n&&(!r.center&&e>r.maxIndex&&(e=r.maxIndex),!f.includes(t,e))){var s=r.slides[e+1];r.center&&s&&n<a-g(s).width/2?a-=n:(a=h,t.push(e),o=d+h+(r.center?n/2:0))}return d+=n,t},[]))&&i.length&&i},transitionOptions:function(){return{center:this.center,list:this.list}}},connected:function(){f.toggleClass(this.$el,this.clsContainer,!f.$("."+this.clsContainer,this.$el))},update:{write:function(){var e=this;f.$$("["+this.attrItem+"],[data-"+this.attrItem+"]",this.$el).forEach(function(t){var i=f.data(t,e.attrItem);e.maxIndex&&f.toggleClass(t,"uk-hidden",f.isNumeric(i)&&(e.sets&&!f.includes(e.sets,f.toFloat(i))||i>e.maxIndex))})},events:["load","resize"]},events:{beforeitemshow:function(t){!this.dragging&&this.sets&&this.stack.length<2&&!f.includes(this.sets,this.index)&&(this.index=this.getValidIndex());var i=Math.abs(this.index-this.prevIndex+(0<this.dir&&this.index<this.prevIndex||this.dir<0&&this.index>this.prevIndex?(this.maxIndex+1)*this.dir:0));if(!this.dragging&&1<i){for(var e=0;e<i;e++)this.stack.splice(1,0,0<this.dir?"next":"previous");t.preventDefault()}else this.duration=n(this.avgWidth/this.velocity)*(g(this.dir<0||!this.slides[this.prevIndex]?this.slides[this.index]:this.slides[this.prevIndex]).width/this.avgWidth),this.reorder()},itemshow:function(){!f.isUndefined(this.prevIndex)&&f.addClass(this._getTransitioner().getItemIn(),this.clsActive)},itemshown:function(){var i=this,e=this._getTransitioner(this.index).getActives();this.slides.forEach(function(t){return f.toggleClass(t,i.clsActive,f.includes(e,t))}),(!this.sets||f.includes(this.sets,f.toFloat(this.index)))&&this.slides.forEach(function(t){return f.toggleClass(t,i.clsActivated,f.includes(e,t))})}},methods:{reorder:function(){var e=this;if(f.css(this.slides,"order",""),!this.finite){var n=0<this.dir&&this.slides[this.prevIndex]?this.prevIndex:this.index;if(this.slides.forEach(function(t,i){return f.css(t,"order",0<e.dir&&i<n?1:e.dir<0&&i>=e.index?-1:"")}),this.center)for(var t=this.slides[n],i=g(this.list).width/2-g(t).width/2,s=0;0<i;){var r=e.getIndex(--s+n,n),h=e.slides[r];f.css(h,"order",n<r?-2:-1),i-=g(h).width}}},getValidIndex:function(t,i){var e;if(void 0===t&&(t=this.index),void 0===i&&(i=this.prevIndex),t=this.getIndex(t,i),!this.sets)return t;do{if(f.includes(this.sets,t))return t;e=t,t=this.getIndex(t+this.dir,i)}while(t!==e);return t}}};return"undefined"!=typeof window&&window.UIkit&&window.UIkit.component("slider",t),t});