-
Notifications
You must be signed in to change notification settings - Fork 13
/
jquery.slider.min.js
executable file
·1 lines (1 loc) · 5.01 KB
/
jquery.slider.min.js
1
!function(a){"use strict";function b(a){function d(a){return a.replace(/\-([a-z])/gi,function(a,b){return b.toUpperCase()})}for(var b=["-webkit-","-moz-",""],c=document.documentElement,e=b.length-1;e>=0;e--){var f=d(b[e]+a);if(f in c.style)return f}return!1}function c(){var a={transition:"transitionend",WebkitTransition:"webkitTransitionEnd",MozTransition:"mozTransitionEnd"},b=document.documentElement;for(var c in a)if(void 0!==b.style[c])return a[c];return!1}function d(){if(!window.getComputedStyle)return!1;var c,a=document.createElement("div"),d=b("transform");return document.body.insertBefore(a,null),a.style[d]="translate3d(1px,1px,1px)",c=getComputedStyle(a)[d],document.body.removeChild(a),void 0!==c&&c.length>0&&"none"!==c}function f(a,b,c){var d;return function(){var e=this,f=arguments,g=function(){d=null,c||a.apply(e,f)},h=c&&!d;clearTimeout(d),d=setTimeout(g,b),h&&a.apply(e,f)}}var e={hasTouch:!!("ontouchstart"in window||window.DocumentTouch&&document instanceof DocumentTouch),event:function(){return{start:this.hasTouch?"touchstart":"mousedown",move:this.hasTouch?"touchmove":"mousemove",end:this.hasTouch?"touchend":"mouseup",leave:this.hasTouch?"touchleave":"mouseout"}}},g="ikSlider",h=function(h,i){function D(){L(),j.responsive&&a(window).on("resize."+g,f(M,50)),!j.caption&&n.attr("disabled",!0),j.controls&&E(),j.touch&&(o.find("img").attr("draggable",!1),F()),j.autoPlay&&(J(),j.pauseOnHover&&(k.on("mouseenter."+g,function(){clearInterval(z)}),k.on("mouseleave."+g,J))),j.arrows?(!j.infinite&&K("prev"),m.on("click."+g,function(a){a.preventDefault(),G("next"===this.getAttribute("data-ikslider-dir")?t+1:t-1)})):m.attr("disabled",!0)}function E(){x=a("<div/>",{class:"slider-nav"}).appendTo(k);for(var b=[],c=0;q>c;c++){var d=t===c?"is-active":"";b.push('<a class="slider-nav__control '+d+'" data-ikslider-control="'+c+'"></a>')}x.html(b.join("")),y=x.find(".slider-nav__control"),x.on("click."+g,".slider-nav__control",function(b){b.preventDefault(),a(this).hasClass("is-active")||G(parseInt(this.getAttribute("data-ikslider-control"),10))})}function F(){l.addClass("has-touch");var a,b,c,d;l.on(e.event().start+"."+g,function(e){if(!w&&!v){var f;e.originalEvent.targetTouches?(d=e.originalEvent.targetTouches[0].target,f=e.originalEvent.targetTouches[0]):(f=e.originalEvent,e.preventDefault()),c=0,a=f.pageX||f.clientX,b=f.pageY||f.clientY,w=!0}}),l.on(e.event().move+"."+g,function(e){if(w){var f;if(e.originalEvent.targetTouches){if(e.originalEvent.targetTouches.length>1||d!==e.originalEvent.targetTouches[0].target)return;f=e.originalEvent.targetTouches[0]}else e.preventDefault(),f=e.originalEvent;var g=f.pageX||f.clientX,h=f.pageY||f.clientY;Math.abs(a-g)>=Math.abs(b-h)&&(c=a-g,H(parseInt(u,10)-c))}}),l.on(e.event().end+"."+g,function(a){if(w){var b=c<0?t-1:t+1;if(Math.abs(c)<50||!j.infinite&&(b>q-1||b<0))return w=!1,void H(u,!0);w=!1,d=null,G(b)}}),l.on(e.event().leave+"."+g,function(){w&&(H(u,!0),w=!1)})}function G(a){v||a!==t&&(t=a>q-1?0:a,a<0&&(t=q-1),j.infinite||(m.attr("disabled",!1),a===q-1&&K("next"),0===t&&K("prev")),u=-r*t,j.controls&&y.removeClass("is-active").eq(t).addClass("is-active"),v=!0,H(u,!0),I())}function H(a,b){B&&A?(p[B]=b?A+" "+j.speed+"ms "+j.cssEase:"none",p[A]=C?"translate3d("+a+"px, 0, 0)":"translateX("+a+"px)",b?l.one(c(),function(a){v=!1}):v=!1):b?l.animate({"margin-left":a},j.speed,"linear",function(){v=!1}):(l.css("margin-left",a),v=!1)}function I(){var b=a.Event("changeSlide."+g,{currentSlide:t});k.trigger(b)}function J(){z&&clearInterval(z),z=setInterval(function(){w||G(t+1)},j.delay)}function K(a){k.find(".slider__switch--"+a).attr("disabled",!0)}function L(){r=k.outerWidth(),s=q*r,o.css("width",r),p.width=s+"px"}function M(){z&&clearInterval(z),L(),u=-r*t,H(u),J()}function N(){p.width="",p[A]="",p[B]="",o.css("width",""),j.autoPlay&&(z&&clearInterval(z),k.off("mouseenter."+g),k.off("mouseleave."+g)),j.arrows&&(m.off("click."+g),m.attr("disabled",!1)),j.controls&&x.off("click."+g).remove(),n.attr("disabled",!1),j.touch&&(l.removeClass("has-touch").off(e.event().start+"."+g).off(e.event().move+"."+g).off(e.event().end+"."+g).off(e.event().leave+"."+g),w=!1),j.responsive&&a(window).off("resize."+g),k.removeData(g),k=null,l=null,m=null,n=null,o=null,x=null,y=null,p=null,q=null,r=null,s=null,t=null,u=null,v=null,z=null,C=null,v=!1,A=null,B=null}var x,y,z,j=a.extend({touch:!0,infinite:!1,autoPlay:!0,pauseOnHover:!0,delay:1e4,responsive:!0,controls:!0,arrows:!0,caption:!0,speed:300,cssEase:"ease-out"},i||{}),k=h,l=k.find(".slider"),m=k.find(".slider__switch"),n=l.find(".slider__caption"),o=l.find(".slider__item"),p=l.get(0).style,q=o.length,r=k.outerWidth(),s=q*r,t=0,u=0,v=!1,w=!1,A=b("transform"),B=b("transition"),C=d();return{init:D,show:G,destroy:N}};a.fn[g]=function(b){var c=this;this.each(function(){var d=a(this),e=d.data(g),f="object"==typeof b&&b;if(e||!/(destroy|\d+)/.test(b)){if(e||(e=new h(d,f),d.data("ikSlider",e),e.init()),"string"==typeof b||"number"==typeof b&&"init"!==b)if("number"==typeof b)c=e.show(b);else{if(!e[b])throw new Error("Error:: ikSlider has no method: "+b);c=e[b]()}return c}})}}(jQuery);