-
Notifications
You must be signed in to change notification settings - Fork 10
/
jquery.roto.min.js
21 lines (21 loc) · 9.1 KB
/
jquery.roto.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*!
* Bez v1.0.10-g5ae0136
* http://github.com/rdallasgray/bez
*
* A plugin to convert CSS3 cubic-bezier co-ordinates to jQuery-compatible easing functions
*
* With thanks to Nikolay Nemshilov for clarification on the cubic-bezier maths
* See http://st-on-it.blogspot.com/2011/05/calculating-cubic-bezier-function.html
*
* Copyright 2011 Robert Dallas Gray. All rights reserved.
* Provided under the FreeBSD license: https://github.com/rdallasgray/bez/blob/master/LICENSE.txt
*/jQuery.extend({bez:function(a){var b="bez_"+$.makeArray(arguments).join("_").replace(".","p");if(typeof jQuery.easing[b]!="function"){var c=function(a,b){var c=[null,null],d=[null,null],e=[null,null],f=function(f,g){return e[g]=3*a[g],d[g]=3*(b[g]-a[g])-e[g],c[g]=1-e[g]-d[g],f*(e[g]+f*(d[g]+f*c[g]))},g=function(a){return e[0]+a*(2*d[0]+3*c[0]*a)},h=function(a){var b=a,c=0,d;while(++c<14){d=f(b,0)-a;if(Math.abs(d)<.001)break;b-=d/g(b)}return b};return function(a){return f(h(a),1)}};jQuery.easing[b]=function(b,d,e,f,g){return f*c([a[0],a[1]],[a[2],a[3]])(d/g)+e}}return b}});
/*!
* Roto v1.5.5-gfe1c278
* http://github.com/rdallasgray/roto
*
* A simple, flexible, touch-capable scrolling plugin for jQuery
*
* Copyright 2012 Robert Dallas Gray. All rights reserved.
* Provided under the FreeBSD license: https://github.com/rdallasgray/roto/blob/master/LICENSE.txt
*/(function(e,t,n,r){e.fn.roto=function(i){var s={rotoSelector:".rotoFrame",btnPrev:".prev",btnNext:".next",btnAction:"shift",direction:"h",shift_duration:200,shift_bezier:[0,0,0,1],drift_duration:1800,drift_factor:500,drift_bezier:[0,0,.3,1],bounce_duration:400,bounce_bezier:[0,.5,.5,1],pull_divisor:1.7,timer_interval:50,disable_transitions:!1,startOffset:0,endOffset:0,snap:!0,clickables:"a, img",auto_disable:!0},i=e.extend(s,i||{}),o=1e3,u="client",a=function(){try{return n.createEvent("TouchEvent"),!0}catch(e){return!1}}(),f=a?{start:"touchstart",move:"touchmove",end:"touchend"}:{start:"mousedown",move:"mousemove",end:"mouseup"},l=function(e){return a&&typeof e.originalEvent.touches!="undefined"?e.originalEvent.touches[0]:e},c={h:{measure:"Width",offsetName:"left",coOrd:"X",opp:"v"},v:{measure:"Height",offsetName:"top",coOrd:"Y",opp:"h"}},h=c[i.direction],p=null,d=null,v=null,m=null;if(!i.disable_transitions){var g=n.body||n.documentElement,y={transform:"transform",MozTransform:"-moz-transform",WebkitTransform:"-webkit-transform"},b={transition:{prop:"transition",event:"transitionend"},MozTransition:{prop:"-moz-transition",event:"transitionend"},WebkitTransition:{prop:"-webkit-transition",event:"webkitTransitionEnd"}};for(var w in y)if(typeof g.style[w]!="undefined"){p=y[w];break}for(var w in b)if(typeof g.style[w]!="undefined"){d=b[w].prop,v=b[w].event;break}}var E=d!==null;return this.each(function(){var m=e(this),g=m.children(i.rotoSelector).length>0?m.children(i.rotoSelector).first():m.children("ul").length>0?m.children("ul").first():m.children().first(),y=g.children(),b=0,w=0,S=0,x=0,T=-1,N=0,C=0,k=typeof m.attr("id")!==r?m.attr("id"):"roto"+(new Date).getTime(),L=null,A=null,O={ready:"ready",tracking:"tracking",drifting:"drifting",shifting:"shifting",bouncing:"bouncing"},M=O.ready,_=!1,D=m.find(i.btnPrev),P=m.find(i.btnNext),H=null,B=!0,j=function(t,n,s,u){var a=u,f=i[s+"_duration"];if(!_||!E)a=function(){G(),u()},_=!0;if(E){var l=I();l.timingFunction[s]===r&&(l.timingFunction[s]=["cubic-bezier(",i[s+"_bezier"].join(","),")"].join(""));var c={};c[l.durationProp]=f/o+"s",c[l.timingFunctionProp]=A.timingFunction[s],t.css(c),t.data("animationCallback",a),t.unbind(v),t.one(v,function(){t.data("animationCallback",null),a()}),t.css(n)}else t.animate(n,f,e.bez(i[s+"_bezier"]),a)},F=function(e){if(E){var t=R();e.unbind(v),e.css(q(t)),typeof e.data("animationCallback")=="function"&&(e.data("animationCallback")(),e.data("animationCallback",null))}else e.stop()},I=function(){return A===null&&(A={durationProp:d+"-duration",timingFunctionProp:d+"-timing-function",timingFunction:{}}),A},q=function(e){var t={};if(E){if(L===null){var n=a?"3d":"",r=n==="3d"?"(Xpx,Ypx,0px)":"(Xpx,Ypx)",i=c[h.opp].coOrd;L=["translate",n,r.replace(i,"0")].join("")}t[p]=L.replace(h.coOrd,e)}else t[h.offsetName]=e+"px";return t},R=function(){var e;if(!E)e=g.position()[h.offsetName]-b;else{var t=g.css(p);if(t==="none")return 0;var n=t.match(/\-?[0-9]+/g),r=h.coOrd==="X"?n[4]:n[5];e=parseInt(r)}return e-i.startOffset},U=function(t,n){var r=0,i,s,o=n>0?y.get().reverse():y,u,a,f="outer"+h.measure;return e.each(o,function(o,l){a=e(l),r=-1*Math.round(a.position()[h.offsetName]),u=l;if(r*n>=t*n)return!1;n<0?(i=-1*r+a[f](!0),s=-1*t):(i=a.prev().length>0?r+a.prev()[f](!0):r,s=t);if(i>s)return!1}),[u,r]},z=function(t,n){var r=n<0?"next":"prev",i=e(U(t,n)[0]),s=i;while(s[r]().length>0&&s.position()[h.offsetName]===i.position()[h.offsetName])s=s[r]();return s},W=function(e,t,n){var t=t===0?T:t;return n?-1*Math.round(z(e,t).position()[h.offsetName]):U(e,t)[1]},X=function(){var e=R();return e===W(e,T,!1)},V=function(){C=0,y=g.children(),y.css({display:"block","float":"left"});if(i.direction==="h")y.each(function(t,n){C+=Math.round(e(n)["outer"+h.measure](!0))}),g[h.measure.toLowerCase()](C);else{var t=e(y.last());C=Math.round(t.position()[h.offsetName]+t["outer"+h.measure](!0))}N=Math.round(m[h.measure.toLowerCase()]()),S=-1*Math.round(Math.max(0,C-N)+b+i.endOffset);if(i.snap){var n=W(S,-1,!1);S=n>S?W(S,-1,!0):n}i.auto_disable&&J(S!==w)},J=function(e){e||nt(w),B=!!e},K=function(){return H===null&&(H=typeof D=="object"&&typeof D.click=="function"&&typeof P=="object"&&typeof P.click=="function"),H},Q=function(){if(!K())return;var e=R();e>S?P.removeAttr("disabled"):P.attr("disabled","disabled"),e<w?D.removeAttr("disabled"):D.attr("disabled","disabled")},G=function(){m.trigger("rotoChange",[U(R(),1)[0]]),_=!1},Y=function(e){var t=typeof e,n;switch(t){case"number":Z(e);break;case"object":et(e);break;case"string":(n=e.match(/(-?[0-9]+)(px$)/))?nt(parseInt(n[1])):(n=e.match(/prev|next/))&&tt(e)}},Z=function(t){if(t<0||t>=y.length)return;var n=e(y.get(t));et(n)},et=function(t){var n=e(t);if(!n.parent()===g)return;nt(-1*n.position()[h.offsetName])},tt=function(e){var t=e==="prev"?1:-1;et(z(R(),t))},nt=function(e,t){t=t||"shift",e>w?e=w:e<S&&(e=S),e+=i.startOffset,j(g,q(e),t,function(){Q(),M=O.ready})},rt=function(e){if(M===O.shifting)return;var t=0;M=O.shifting,T=e,e<0?t=Math.max(W(R()-(N-i.startOffset),e,!1),S):t=Math.min(W(R()+(N-i.startOffset),e,!1),w),nt(t)},it=function(e){var t=e<0?"next":"prev";tt(t)},st=function(e){var t=Math.round(e+x),n;if(t<w&&t>S)n=t;else var r=t>=w?t-w:t-S,n=t-r/i.pull_divisor;if(M!==O.tracking){var s={},o=I();s[o.durationProp]="0s",s[o.timingFunctionProp]="none",g.css(s)}M=O.tracking,g.css(q(n))},ot=function(){var e=ft.getPointerSpeed(),t=e[0],n=e[1],r=R(),s=t*i.drift_factor*n,o=s+r;o>w?o=w:o<S?o=S:i.snap&&!X()&&(o=W(o,n,!0));if(o===r){G();return}M=O.drifting,nt(o,"drift")},ut=function(e){var t=e<0?S:w;M=O.bouncing,nt(t,"bounce")},at=i.btnAction==="shift"?rt:it,ft=function(){var e=0,n=0,r=0,s=null,o={startCoOrd:0,endCoOrd:0};return{start:function(){r=e=n,s=t.setInterval(function(){o.startCoOrd=e,o.endCoOrd=n,e=n},i.timer_interval)},stop:function(){clearInterval(s),o.endCoOrd=n},getPointerSpeed:function(){var e=o.endCoOrd-o.startCoOrd,t=Math.abs(e),n=t/i.timer_interval,s=e===0?o.endCoOrd-r:e,u=s<=0?s===0?0:-1:1;return u!==0&&(T=u),[n,u]},setCurrentCoOrd:function(e){n=e}}}(),lt=function(){V(),Q(),i.setTestVars&&setTestVars()};g.bind(f.start+".roto-"+k,function(s){var o=M;x=R(),F(g);var c=g.find("a"),p={},d=u+h.coOrd,v=!1;o!==O.drifting&&g.undelegate(i.clickables,"click.roto-trackclick-"+k),M=O.ready,a||(s.target.draggable&&s.preventDefault(),n.ondragstart!==r&&g.find(i.clickables).one("dragstart.roto-"+k,function(e){e.preventDefault()}),c.length>0&&e(n).one(f.move+".roto-"+k,function(t){c.data("events")!==r&&(e.each(c.data("events"),function(t,n){p[t]=[],e.each(n,function(e,n){n.namespace!=="roto-"+k&&p[t].push(n)})}),c.unbind(),v=!0),g.delegate(i.clickables,"click.roto-trackclick-"+k,function(e){e.preventDefault()})})),s=l(s);var m=s[d];ft.setCurrentCoOrd(m),e(n).bind(f.move+".roto-"+k,function(e){if(!B)return;e.preventDefault(),e=l(e),ft.setCurrentCoOrd(e[d]),st(e[d]-m)}),e(n).bind(f.end+".roto-"+k,function(){ft.stop();var r=R();r>w||r<S?ut(R()-w):ot(),e(n).unbind(f.move+".roto-"+k),t.setTimeout(function(){v&&e.each(p,function(t,n){e.each(n,function(e,t){var n=t.type;t.namespace!==""&&(n=[n,".",t.namespace].join("")),c.bind(n,t.data,t.handler)})})},250),e(this).unbind()}),ft.start()}),D.length===0&&i.btnPrev===s.btnPrev&&m.attr("id")&&(D=e("#"+m.attr("id")+"-prev"),P=e("#"+m.attr("id")+"-next")),K()&&(D.click(function(){return at(1)}),P.click(function(){return at(-1)})),e(t).resize(function(){lt()}),d==="-webkit-transition"&&g.css("-webkit-backface-visibility","hidden"),m.css({display:"block",overflow:"hidden",position:"relative"}),g.css({position:"relative",padding:0,margin:0}),m.bind("rotoGoto",function(e,t){Y(t)}),m.bind("rotoShift",function(e,t){rt(t)}),m.bind("rotoContentChange",function(){lt()}),m.bind("rotoDisable",function(){J(!1)}),m.bind("rotoEnable",function(){J(!0)}),lt(),i.startOffset!==0&&(g.css(q(i.startOffset)),Q()),b=Math.round(g.position()[h.offsetName]),b!==i.startOffset&&V()})}})(jQuery,window,document);