forked from powy1993/Rundiv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRundiv.min.js
1 lines (1 loc) · 5.63 KB
/
Rundiv.min.js
1
function Rundiv(a,b){"use strict";function c(){s=w.children,v=s.length,s.length<2&&(b.continuous=!1),r.transitions&&b.continuous&&s.length<3&&(w.appendChild(s[0].cloneNode(!0)),w.appendChild(w.children[1].cloneNode(!0)),s=w.children),t=new Array(s.length),u=a.getBoundingClientRect().width||a.offsetWidth,w.style.width=s.length*u+"px";for(var c=s.length;c--;){var d=s[c];d.style.width=u+"px",d.setAttribute("data-index",c+1),r.transitions&&(d.style.left=c*-u+"px",k(c,x>c?-u:c>x?u:0,0))}b.continuous&&r.transitions&&(k(f(x-1),-u,0),k(f(x+1),u,0)),r.transitions||(w.style.left=x*-u+"px"),a.style.visibility="visible"}function d(){b.continuous?g(x-1):x&&g(x-1)}function e(){b.continuous?g(x+1):x<s.length-1&&g(x+1)}function f(a){return(s.length+a%s.length)%s.length}function g(a,c){if(x!=a){if(r.transitions){var d=Math.abs(x-a)/(x-a);if(b.continuous){var e=d;d=-t[f(a)]/u,d!==e&&(a=-d*s.length+a)}for(var g=Math.abs(x-a)-1;g--;)k(f((a>x?a:x)-g-1),u*d,0);a=f(a),k(x,u*d,c||y),k(a,0,c||y),b.continuous&&k(f(a-d),-(u*d),0)}else a=f(a),m(x*-u,a*-u,c||y);h(a)}}function h(a){b.formerpage=x,x=a,q(b.callback&&b.callback(x,s[x])),b.hasNav&&i(b.formerpage,a),b.auto&&n()}function i(a,c){b.listelem.children[a].className="",b.listelem.children[c].className="active"}function j(a){b.listelem=a;for(var c=a.children,d=c.length;d--;)c[d].setAttribute("data-index",d+1)}function k(a,b,c){l(a,b,c),t[a]=b}function l(a,b,c){var d=s[a],e=d&&d.style;e&&(e.webkitTransitionDuration=e.MozTransitionDuration=e.msTransitionDuration=e.OTransitionDuration=e.transitionDuration=c+"ms",e.webkitTransform="translate("+b+"px,0)translateZ(0)",e.msTransform=e.MozTransform=e.OTransform="translateX("+b+"px)")}function m(a,c,d){if(!d)return void(w.style.left=c+"px");var e=+new Date,f=setInterval(function(){var g=+new Date-e;return g>d?(w.style.left=c+"px",B&&n(),b.transitionEnd&&b.transitionEnd.call(event,x,s[x]),void clearInterval(f)):void(w.style.left=(c-a)*(Math.floor(g/d*100)/100)+a+"px")},4)}function n(){o(),z=setTimeout(e,B)}function o(){clearTimeout(z)}var p=function(){},q=function(a){setTimeout(a||p,0)},r={addEventListener:!!window.addEventListener,touch:"ontouchstart"in window||window.DocumentTouch&&document instanceof DocumentTouch,transitions:function(a){var b=["transitionProperty","WebkitTransition","MozTransition","OTransition","msTransition"];for(var c in b)if("undefine"!=typeof a.style[b[c]])return!0;return!1}(document.createElement("Rundiv"))};if(a){var s,t,u,v,w=a.children[0];b=b||{};var x=parseInt(b.startSlide,10)-1||0,y=b.speed||300;b.continuous="undefine"!=typeof b.continuous?b.continuous:!0;var z,A,B=b.auto||0,C={},D={},E={handleEvent:function(a){switch(a.type){case"touchstart":this.start(a);break;case"touchmove":this.move(a);break;case"touchend":q(this.end(a));break;case"webkitTransitionEnd":case"msTransitionEnd":case"oTransitionEnd":case"otransitionend":case"transitionend":q(this.transitionEnd(a));break;case"resize":q(c)}b.stopPropagation&&a.stopPropagation()},start:function(a){var b=a.touches[0];C={x:b.pageX,y:b.pageY,time:+new Date},A=void 0,D={},w.addEventListener("touchmove",this,!1),w.addEventListener("touchend",this,!1)},move:function(a){if(!(a.touches.length>1||a.scale&&1!==a.scale)){b.disableScroll&&a.preventDefault();var c=a.touches[0];D={x:c.pageX-C.x,y:c.pageY-C.y},"undefined"==typeof A&&(A=!!(A||Math.abs(D.x)<Math.abs(D.y))),A||(a.preventDefault(),o(),b.continuous?(l(f(x-1),D.x+t[f(x-1)],0),l(x,D.x+t[x],0),l(f(x+1),D.x+t[f(x+1)],0)):(D.x=D.x/(!x&&D.x>0||x==s.length-1&&D.x<0?Math.abs(D.x)/u+1:1),l(x-1,D.x+t[x-1],0),l(x,D.x+t[x],0),l(x+1,D.x+t[x+1],0)))}},end:function(){var a=+new Date-C.time,c=Number(a)<250&&Math.abs(D.x)>20||Math.abs(D.x)>u/2,d=!x&&D.x>0||x==s.length-1&&D.x<0;b.continuous&&(d=!1);var e=D.x<0;A||(c&&!d?(e?(b.continuous?(k(f(x-1),-u,0),k(f(x+2),u,0)):k(x-1,-u,0),k(x,t[x]-u,y),k(f(x+1),t[f(x+1)]-u,y),h(f(x+1))):(b.continuous?(k(f(x+1),u,0),k(f(x-2),-u,0)):k(x+1,u,0),k(x,t[x]+u,y),k(f(x-1),t[f(x-1)]+u,y),h(f(x-1))),b.callback&&b.callback(x,s[x])):b.continuous?(k(f(x-1),-u,y),k(x,0,y),k(f(x+1),u,y)):(k(x-1,-u,y),k(x,0,y),k(x+1,u,y))),w.removeEventListener("touchmove",E,!1),w.removeEventListener("touchend",E,!1)},transitionEnd:function(a){parseInt(a.target.getAttribute("data-index"),10)==x&&(B&&n(),b.transitionEnd&&b.transitionEnd.call(a,x,s[x]))}};return c(),B&&n(),r.addEventListener?(r.touch&&w.addEventListener("touchstart",E,!1),r.transitions&&(w.addEventListener("webkitTransitionEnd",E,!1),w.addEventListener("msTransitionEnd",E,!1),w.addEventListener("oTransitionEnd",E,!1),w.addEventListener("otransitionend",E,!1),w.addEventListener("transitionend",E,!1)),window.addEventListener("resize",E,!1)):window.onresize=function(){c()},{linkNav:function(a){var b=document.getElementById(a);j(b),b.addEventListener("click",function(a){o(),elem=a.target;var b=parseInt(elem.getAttribute("data-index"),10);b&&g(b-1,800)},!1)},setup:function(){c()},slide:function(a,b){o(),g(a,b)},prev:function(){o(),d()},next:function(){o(),e()},stop:function(){o()},getPage:function(){return x+1},getNumSlides:function(){return v},kill:function(){o(),w.style.width="",w.style.left="";for(var a=s.length;a--;){var b=s[a];b.style.width="",b.style.left="",r.transitions&&l(a,0,0)}r.addEventListener?(w.removeEventListener("touchstart",E,!1),w.removeEventListener("webkitTransitionEnd",E,!1),w.removeEventListener("msTransitionEnd",E,!1),w.removeEventListener("oTransitionEnd",E,!1),w.removeEventListener("otransitionend",E,!1),w.removeEventListener("transitionend",E,!1),window.removeEventListener("resize",E,!1)):window.onresize=null}}}}(window.jQuery||window.Zepto)&&!function(a){a.fn.Rundiv=function(b){return this.each(function(){a(this).data("Rundiv",new Rundiv(a(this)[0],b))})}}(window.jQuery||window.Zepto);