Skip to content

armgit / GSAP

Public Imported from GitHub
0

GSAP (GreenSock Animation Platform): high-performance JavaScript animation for anything JavaScript can touch. 100% free, including every plugin.

Draggable 0.7.0

GreenSocka5bb4796d8ac
diff --git a/src/minified/utils/Draggable.min.js b/src/minified/utils/Draggable.min.js
index c05ce15..97da15f 100644
--- a/src/minified/utils/Draggable.min.js
+++ b/src/minified/utils/Draggable.min.js
@@ -1,12 +1,14 @@
/*!
- * VERSION: 0.6.0
- * DATE: 2013-07-19
+ * VERSION: 0.7.0
+ * DATE: 2013-08-18
* UPDATES AND DOCS AT: http://www.greensock.com
*
+ * Requires TweenLite and CSSPlugin (or TweenMax which contains both of those). ThrowPropsPlugin is required for momentum-based continuation of movement after the mouse/touch is released (ThrowPropsPlugin is a membership benefit of Club GreenSock - http://www.greensock.com/club/).
+ *
* @license Copyright (c) 2008-2013, GreenSock. All rights reserved.
* This work is subject to the terms at http://www.greensock.com/terms_of_use.html or for
* Club GreenSock members, the software agreement that was issued with your membership.
*
* @author: Jack Doyle, [email protected]
*/
-(window._gsQueue||(window._gsQueue=[])).push(function(){"use strict";window._gsDefine("utils.Draggable",["events.EventDispatcher","TweenLite"],function(t,e){var i,s,r,n={css:{}},a={css:{}},o={css:{}},h={css:{}},l={},_=document,u=_.documentElement,f=[],c=function(){return!1},p=180/Math.PI,m=Math.PI/180,d=_.all&&!_.addEventListener,g=function(t,e){return t=t||window.event,l.pageX=t.clientX+_.body.scrollLeft+u.scrollLeft,l.pageY=t.clientY+_.body.scrollTop+u.scrollTop,e&&(t.returnValue=!1),l},v=function(t,e){var s,r,n,a=t.style;if(void 0===a[e]){for(n=["O","Moz","ms","Ms","Webkit"],r=5,s=e.charAt(0).toUpperCase()+e.substr(1);--r>-1&&void 0===a[n[r]+s];);if(0>r)return"";i=3===r?"ms":n[r],e=i+s}return e},y=function(t,e,i){var s=t.style;void 0===s[e]&&(e=v(t,e)),null==i?s.removeProperty?s.removeProperty(e.replace(/([A-Z])/g,"-$1").toLowerCase()):s.removeAttribute(e):void 0!==s[e]&&(s[e]=i)},T=_.defaultView?_.defaultView.getComputedStyle:c,w=function(t,e,i){var s,r=(t._gsTransform||{})[e];return r||0===r?r:(t.style[e]?r=t.style[e]:(s=T(t))?(t=s.getPropertyValue(e.replace(/([A-Z])/g,"-$1").toLowerCase()),r=t||s.length?t:s[e]):t.currentStyle&&(r=t.currentStyle[e]),i?r:parseFloat(r)||0)},x=function(t,e,i){t.addEventListener?t.addEventListener(e,i,!1):t.attachEvent&&t.attachEvent("on"+e,i)},b=function(t,e,i){t.removeEventListener?t.removeEventListener(e,i):t.detachEvent&&t.detachEvent("on"+e,i)},P=function(t,e,i){var s=t.vars,r=s[i],n=t._listeners[e];"function"==typeof r&&r.apply(s[i+"Scope"]||t,s[i+"Params"]||f),n&&t.dispatchEvent(e)},S=function(t){if(t===window)return{top:null!=t.pageYOffset?t.pageYOffset:null!=_.scrollTop?_.scrollTop:_.body.scrollTop||u.scrollTop||0,left:null!=t.pageXOffset?t.pageXOffset:null!=_.scrollLeft?_.scrollLeft:_.body.scrollLeft||u.scrollLeft||0,width:u?u.clientWidth:t.innerWidth,height:u?u.clientHeight:t.innerHeight};var e=t.offsetWidth,i=t.offsetHeight,s=t.offsetTop,r=t.offsetLeft;for(d&&t._gsTransform&&(s-=t._gsTransform.y,r-=t._gsTransform.x);t=t.offsetParent;)s+=t.offsetTop,r+=t.offsetLeft;return{top:s,left:r,width:e,height:i}},C=v(_.body,"transformOrigin").replace(/([A-Z])/g,"-$1").toLowerCase(),k=v(_.body,"transform"),R=""!==v(_.body,"perspective"),A=k&&R,D=function(t){var e=S(t),i=T(t),s=C&&i?i.getPropertyValue(C):"50% 50%",r=s.split(" "),n=-1!==s.indexOf("left")?"0%":-1!==s.indexOf("right")?"100%":r[0],a=-1!==s.indexOf("top")?"0%":-1!==s.indexOf("bottom")?"100%":r[1];return null==a?a="0":"center"===a&&(a="50%"),("center"===n||isNaN(parseFloat(n)))&&(n="50%"),e.left+=-1!==n.indexOf("%")?e.width*parseFloat(n)/100:parseFloat(n),e.top+=-1!==a.indexOf("%")?e.height*parseFloat(a)/100:parseFloat(a),e},O=function(t){return t.length&&t[0]&&(t[0].nodeType&&t[0].style&&!t.nodeType||t[0].length&&t[0][0])?!0:!1},M=function(t){var e,i,s,r=[],n=t.length;for(e=0;n>e;e++)if(i=t[e],O(i))for(s=i.length,s=0;i.length>s;s++)r.push(i[s]);else r.push(i);return r},L=function(t,e,i,s,r){var n,a,o,h={};if(e)if(r&&e instanceof Array)for(h.end=n=[],o=e.length,a=0;o>a;a++)n[a]=e[a]*r;else h.end="function"==typeof e?function(i){return e.call(t,i)}:e;return(i||0===i)&&(h.max=i),(s||0===s)&&(h.min=s),h},I=function(){var t,e=_.createElement("div"),i=_.createElement("div"),s=i.style;return s.display="inline-block",s.position="relative",e.style.cssText=i.innerHTML="width:90px; height:40px; padding:10px; overflow:auto; visibility: hidden",e.appendChild(i),_.body.appendChild(e),r=i.offsetHeight+18>e.scrollHeight,s.width="100%",A||(s.paddingRight="500px",t=e.scrollLeft=e.scrollWidth-e.clientWidth,s.left="-90px",t=t!==e.scrollLeft),_.body.removeChild(e),t}(),E=function(t){t.length&&t[0]&&(t=t[0]);var i,s,n,a,o=_.createElement("div"),h=o.style,l=t.firstChild,u=0,f=0,c=t.scrollTop,p=t.scrollLeft,m=0,g=0,v=0;this.scrollTop=function(t,e){return arguments.length?(this.top(-t,e),void 0):-this.top()},this.scrollLeft=function(t,e){return arguments.length?(this.left(-t,e),void 0):-this.left()},this.left=function(i,s){if(!arguments.length)return-(t.scrollLeft+f);var r=t.scrollLeft-p,n=f;return(r>2||-2>r)&&!s?(p=t.scrollLeft,e.killTweensOf(this,{left:1,scrollLeft:1}),this.left(-p),void 0):(i=-i,0>i?(f=0|i-.5,i=0):i>g?(f=0|i-g,i=g):f=0,(f||n)&&(A?h[k]="translate3d("+-f+"px,"+-u+"px,0px)":h.left=-f+"px",I&&f+m>=0&&(h.paddingRight=f+m+"px")),t.scrollLeft=0|i,p=t.scrollLeft,void 0)},this.top=function(i,s){if(!arguments.length)return-(t.scrollTop+u);var r=t.scrollTop-c,n=u;return(r>2||-2>r)&&!s?(c=t.scrollTop,e.killTweensOf(this,{top:1,scrollTop:1}),this.top(-c),void 0):(i=-i,0>i?(u=0|i-.5,i=0):i>v?(u=0|i-v,i=v):u=0,(u||n)&&(A?h[k]="translate3d("+-f+"px,"+-u+"px,0px)":h.top=-u+"px"),t.scrollTop=0|i,c=t.scrollTop,void 0)},this.maxScrollTop=function(){return v},this.maxScrollLeft=function(){return g},this.disable=function(){for(l=o.firstChild;l;)a=l.nextSibling,t.appendChild(l),l=a;t.removeChild(o)},this.enable=function(){if(l=t.firstChild,l!==o){for(;l;)a=l.nextSibling,o.appendChild(l),l=a;t.appendChild(o),this.calibrate()}},this.calibrate=function(e){var a,l,_=t.clientWidth===i;(!_||t.clientHeight!==s||o.offsetHeight!==n||e)&&((u||f)&&(a=this.left(),l=this.top(),this.left(-t.scrollLeft),this.top(-t.scrollTop)),(!_||e)&&(h.display="block",h.width="auto",h.paddingRight="0px",m=Math.max(0,t.scrollWidth-t.clientWidth),m&&(m+=w(t,"paddingLeft")+(r?w(t,"paddingRight"):0))),h.display="inline-block",h.position="relative",h.overflow="visible",h.width="100%",h.paddingRight=m+"px",r&&(h.paddingBottom=w(t,"paddingBottom",!0)),d&&(h.zoom="1"),i=t.clientWidth,s=t.clientHeight,g=t.scrollWidth-i,v=t.scrollHeight-s,n=o.offsetHeight,(a||l)&&(this.left(a),this.top(l)))},this.content=o,this.element=t,this.enable()},N=function(i,r){t.call(this,i),i.length&&i[0]&&(i=i[0]),s||(s=(window.GreenSockGlobals||window).com.greensock.plugins.ThrowPropsPlugin),this.vars=r=r||{},this.target=i,this.x=this.y=0;var l,u,f,v,T,C,k,R,A,O,M,I,F,X,U,z,B=(r.type||(d?"top,left":"x,y")).toLowerCase(),Y=-1!==B.indexOf("x")||-1!==B.indexOf("y"),j=-1!==B.indexOf("rotation"),q=Y?"x":"left",V=Y?"y":"top",W=-1!==B.indexOf("x")||-1!==B.indexOf("left")||"scroll"===B,H=-1!==B.indexOf("y")||-1!==B.indexOf("top")||"scroll"===B,Q=this,G={},$=parseFloat(r.edgeTolerance)||1-(parseFloat(r.edgeResistance)||0),Z=function(t){if(d?t=g(t,!0):t.preventDefault(),t.changedTouches?(t=X=t.changedTouches[0],U=t.identifier):X=null,e.killTweensOf(l||i,G),f=t.pageY,u=t.pageX,j?(z=D(i),v=z.left,T=z.top,z=Math.atan2(T-f,u-v)):l?(T=l.top(),v=l.left()):(T=w(i,V),v=w(i,q)),j||l||r.zIndexBoost===!1||(i.style.zIndex=N.zIndex++),X?(x(_,"touchmove",K),x(_,"touchend",J)):(x(_,"mousemove",K),x(_,"mouseup",J)),Q.isDragging=!0,k=!(!r.onDrag&&!Q._listeners.drag),C=!1,l)l.calibrate(),Q.xMin=A=-l.maxScrollLeft(),Q.yMin=M=-l.maxScrollTop(),Q.xMax=R=Q.yMax=O=0,C=!0;else if(r.bounds&&!j){var s=S(i),n=r.bounds.length&&r.bounds!==window&&r.bounds[0]&&!r.bounds.nodeType?S(r.bounds[0]):r.bounds===window||r.bounds.style?S(r.bounds):r.bounds;Q.xMin=A=(Y?0:w(i,"left"))+n.left-s.left,Q.yMin=M=(Y?0:w(i,"top"))+n.top-s.top,Q.xMax=R=A+(n.width-i.offsetWidth),Q.yMax=O=M+(n.height-i.offsetHeight),A>R&&(Q.xMin=R,Q.xMax=R=A,A=Q.xMin),M>O&&(Q.yMin=O,Q.yMax=O=M,M=Q.yMin),C=!0}return C&&(v>R?v=R+(v-R)/$:A>v&&(v=A-(A-v)/$),T>O?T=O+(T-O)/$:M>T&&(T=M-(M-T)/$)),j||y(i,"cursor",r.cursor||"move"),P(Q,"dragstart","onDragStart"),!1},K=function(t){d?t=g(t,!0):t.preventDefault();var s,r,n,a,o,h=t.changedTouches;if(h&&(t=h[0],t!==X&&t.identifier!==U)){for(o=h.length;--o>-1&&(t=h[o]).identifier!==U;);if(0>o)return}return j?(n=Math.atan2(T-t.pageY,t.pageX-v),F.rotation="+="+(z-n)*p,e.set(i,I),z=n):(r=t.pageY-f,s=t.pageX-u,n=s>2||-2>s?v+s:v,a=r>2||-2>r?T+r:T,C&&(n>R?n=R+(n-R)*$:A>n&&(n=A+(n-A)*$),a>O?a=O+(a-O)*$:M>a&&(a=M+(a-M)*$)),Q.x=n,Q.y=a,l?(H&&l.top(a),W&&l.left(n)):Y?(H&&(F.y=a),W&&(F.x=n),e.set(i,I)):(H&&(i.style.top=a+"px"),W&&(i.style.left=n+"px"))),k&&P(Q,"drag","onDrag"),!0},J=function(t){d&&(t=g(t,!1));var e,n,a,o,h,c=t.changedTouches,p=r.throwProps;if(c&&(t=c[0],t!==X&&t.identifier!==U)){for(a=c.length;--a>-1&&(t=c[a]).identifier!==U;);if(0>a)return}n=t.pageY-f,e=t.pageX-u,Q.isDragging=!1,b(_,"mouseup",J),b(_,"touchend",J),b(_,"mousemove",K),b(_,"touchmove",K),p&&s&&(p===!0&&(o=r.snap||{},h=o instanceof Array||"function"==typeof o,p={resistance:(r.resistance||1e3)/(j?100:1)},j?p.rotation=L(Q,h?o:o.rotation,R,A,r.useRadians?null:m):(W&&(p[q]=L(Q,h?o:o.x||o.left||o.scrollLeft,R,A,l?-1:null)),H&&(p[V]=L(Q,h?o:o.y||o.top||o.scrollTop,O,M,l?-1:null)))),s.to(l||i,{throwProps:p,ease:r.ease||Power3.easeOut,onComplete:r.onComplete,onUpdate:r.onUpdate},r.maxDuration||2,r.minDuration||.5,void 0===r.overshootTolerance?$+.2:r.overshootTolerance)),j||y(i,"cursor",r.cursor||"move"),2>e&&e>-2&&2>n&&n>-2&&P(Q,"click","onClick"),P(Q,"dragend","onDragEnd")};this.enable=function(){x(i,"mousedown",Z),x(i,"touchstart",Z),j||y(i,"cursor",r.cursor||"move"),y(i,"userSelect","none"),y(i,"touchCallout","none"),s&&s.track(l||i,Y?"x,y":j?"rotation":"top,left"),l&&l.enable()},this.disable=function(){var t=this.isDragging;j||y(i,"cursor",null),e.killTweensOf(l||i,G),y(i,"userSelect","text"),y(i,"touchCallout","default"),b(i,"mousedown",Z),b(i,"touchstart",Z),b(_,"mouseup",J),b(_,"touchend",J),b(_,"mousemove",K),b(_,"touchmove",K),s&&s.untrack(l||i,Y?"x,y":j?"rotation":"top,left"),l&&l.disable(),this.isDragging=!1,t&&P(this,"dragend","onDragEnd")},-1!==B.indexOf("scroll")&&(l=this.scrollProxy=new E(i),i._gsTransform&&.01===i._gsTransform.z&&(e.set(i,{z:0}),e.set(i,{z:0})),i.style.overflowY=H?"auto":"hidden",i.style.overflowX=W?"auto":"hidden",i=l.content),i.ondragstart=_.onselectstart=i.onselectstart=c,e.set(i,{z:"+=0.01"}),j?G.rotation=1:(W&&(G.x=G.left=1),H&&(G.y=G.top=1)),j?(I=h,F=I.css):Y&&(I=W&&H?n:W?a:o,F=I.css),this.isDragging=!1,this.enable()},F=N.prototype=new t;return F.constructor=N,N.version="0.6.0",N.zIndex=1e3,N.create=function(t,i){"string"==typeof t&&(t=e.selector(t));for(var s=O(t)?M(t):[t],r=s.length;--r>-1;)s[r]=new N(s[r],i);return s},N},!0)}),window._gsDefine&&window._gsQueue.pop()();
\ No newline at end of file
+(window._gsQueue||(window._gsQueue=[])).push(function(){"use strict";window._gsDefine("utils.Draggable",["events.EventDispatcher","TweenLite"],function(t,e){var i,s,r,n={css:{}},a={css:{}},o={css:{}},h={css:{}},l={},_=document,u=_.documentElement,f=[],c=function(){return!1},p=180/Math.PI,m=Math.PI/180,d=_.all&&!_.addEventListener,g=[],v="ontouchstart"in u&&"orientation"in window,y=function(t,e){return t=t||window.event,l.pageX=t.clientX+_.body.scrollLeft+u.scrollLeft,l.pageY=t.clientY+_.body.scrollTop+u.scrollTop,e&&(t.returnValue=!1),l},T=function(t){return t?("string"==typeof t&&(t=e.selector(t)),t.length&&t!==window&&t[0]&&t[0].style&&!t.nodeType&&(t=t[0]),t===window||t.nodeType&&t.style?t:null):t},w=function(t,e){var s,r,n,a=t.style;if(void 0===a[e]){for(n=["O","Moz","ms","Ms","Webkit"],r=5,s=e.charAt(0).toUpperCase()+e.substr(1);--r>-1&&void 0===a[n[r]+s];);if(0>r)return"";i=3===r?"ms":n[r],e=i+s}return e},x=function(t,e,i){var s=t.style;void 0===s[e]&&(e=w(t,e)),null==i?s.removeProperty?s.removeProperty(e.replace(/([A-Z])/g,"-$1").toLowerCase()):s.removeAttribute(e):void 0!==s[e]&&(s[e]=i)},b=_.defaultView?_.defaultView.getComputedStyle:c,P=function(t,e,i){var s,r=(t._gsTransform||{})[e];return r||0===r?r:(t.style[e]?r=t.style[e]:(s=b(t))?(t=s.getPropertyValue(e.replace(/([A-Z])/g,"-$1").toLowerCase()),r=t||s.length?t:s[e]):t.currentStyle&&(r=t.currentStyle[e]),i?r:parseFloat(r)||0)},S=function(t,e,i){t.addEventListener?t.addEventListener(e,i,!1):t.attachEvent&&t.attachEvent("on"+e,i)},C=function(t,e,i){t.removeEventListener?t.removeEventListener(e,i):t.detachEvent&&t.detachEvent("on"+e,i)},k=function(t,e,i){var s=t.vars,r=s[i],n=t._listeners[e];"function"==typeof r&&r.apply(s[i+"Scope"]||t,s[i+"Params"]||f),n&&t.dispatchEvent(e)},R=function(t){if(t===window)return{top:null!=t.pageYOffset?t.pageYOffset:null!=_.scrollTop?_.scrollTop:_.body.scrollTop||u.scrollTop||0,left:null!=t.pageXOffset?t.pageXOffset:null!=_.scrollLeft?_.scrollLeft:_.body.scrollLeft||u.scrollLeft||0,width:u?u.clientWidth:t.innerWidth,height:u?u.clientHeight:t.innerHeight};var e=t.offsetWidth,i=t.offsetHeight,s=t.offsetTop,r=t.offsetLeft;for(d&&t._gsTransform&&(s-=t._gsTransform.y,r-=t._gsTransform.x);t=t.offsetParent;)s+=t.offsetTop,r+=t.offsetLeft;return{top:s,left:r,width:e,height:i}},A=_.createElement("div"),D=w(A,"transformOrigin").replace(/([A-Z])/g,"-$1").toLowerCase(),O=w(A,"transform"),M=""!==w(A,"perspective"),L=O&&M,I=function(t){var e=R(t),i=b(t),s=D&&i?i.getPropertyValue(D):"50% 50%",r=s.split(" "),n=-1!==s.indexOf("left")?"0%":-1!==s.indexOf("right")?"100%":r[0],a=-1!==s.indexOf("top")?"0%":-1!==s.indexOf("bottom")?"100%":r[1];return null==a?a="0":"center"===a&&(a="50%"),("center"===n||isNaN(parseFloat(n)))&&(n="50%"),e.left+=-1!==n.indexOf("%")?e.width*parseFloat(n)/100:parseFloat(n),e.top+=-1!==a.indexOf("%")?e.height*parseFloat(a)/100:parseFloat(a),e},E=function(t){return t.length&&t[0]&&(t[0].nodeType&&t[0].style&&!t.nodeType||t[0].length&&t[0][0])?!0:!1},N=function(t){var e,i,s,r=[],n=t.length;for(e=0;n>e;e++)if(i=t[e],E(i))for(s=i.length,s=0;i.length>s;s++)r.push(i[s]);else r.push(i);return r},F=function(t,e,i,s,r){var n,a,o,h={};if(e)if(r&&e instanceof Array)for(h.end=n=[],o=e.length,a=0;o>a;a++)n[a]=e[a]*r;else h.end="function"==typeof e?function(i){return e.call(t,i)}:e;return(i||0===i)&&(h.max=i),(s||0===s)&&(h.min=s),h},X=function(){var t,e=_.createElement("div"),i=_.createElement("div"),s=i.style,n=_.body||A;return s.display="inline-block",s.position="relative",e.style.cssText=i.innerHTML="width:90px; height:40px; padding:10px; overflow:auto; visibility: hidden",e.appendChild(i),n.appendChild(e),r=i.offsetHeight+18>e.scrollHeight,s.width="100%",L||(s.paddingRight="500px",t=e.scrollLeft=e.scrollWidth-e.clientWidth,s.left="-90px",t=t!==e.scrollLeft),n.removeChild(e),t}(),U=function(t){t=T(t);var i,s,n,a,o=_.createElement("div"),h=o.style,l=t.firstChild,u=0,f=0,c=t.scrollTop,p=t.scrollLeft,m=0,g=0,v=0;this.scrollTop=function(t,e){return arguments.length?(this.top(-t,e),void 0):-this.top()},this.scrollLeft=function(t,e){return arguments.length?(this.left(-t,e),void 0):-this.left()},this.left=function(i,s){if(!arguments.length)return-(t.scrollLeft+f);var r=t.scrollLeft-p,n=f;return(r>2||-2>r)&&!s?(p=t.scrollLeft,e.killTweensOf(this,{left:1,scrollLeft:1}),this.left(-p),void 0):(i=-i,0>i?(f=0|i-.5,i=0):i>g?(f=0|i-g,i=g):f=0,(f||n)&&(L?h[O]="translate3d("+-f+"px,"+-u+"px,0px)":h.left=-f+"px",X&&f+m>=0&&(h.paddingRight=f+m+"px")),t.scrollLeft=0|i,p=t.scrollLeft,void 0)},this.top=function(i,s){if(!arguments.length)return-(t.scrollTop+u);var r=t.scrollTop-c,n=u;return(r>2||-2>r)&&!s?(c=t.scrollTop,e.killTweensOf(this,{top:1,scrollTop:1}),this.top(-c),void 0):(i=-i,0>i?(u=0|i-.5,i=0):i>v?(u=0|i-v,i=v):u=0,(u||n)&&(L?h[O]="translate3d("+-f+"px,"+-u+"px,0px)":h.top=-u+"px"),t.scrollTop=0|i,c=t.scrollTop,void 0)},this.maxScrollTop=function(){return v},this.maxScrollLeft=function(){return g},this.disable=function(){for(l=o.firstChild;l;)a=l.nextSibling,t.appendChild(l),l=a;t.removeChild(o)},this.enable=function(){if(l=t.firstChild,l!==o){for(;l;)a=l.nextSibling,o.appendChild(l),l=a;t.appendChild(o),this.calibrate()}},this.calibrate=function(e){var a,l,_=t.clientWidth===i;(!_||t.clientHeight!==s||o.offsetHeight!==n||e)&&((u||f)&&(a=this.left(),l=this.top(),this.left(-t.scrollLeft),this.top(-t.scrollTop)),(!_||e)&&(h.display="block",h.width="auto",h.paddingRight="0px",m=Math.max(0,t.scrollWidth-t.clientWidth),m&&(m+=P(t,"paddingLeft")+(r?P(t,"paddingRight"):0))),h.display="inline-block",h.position="relative",h.overflow="visible",h.width="100%",h.paddingRight=m+"px",r&&(h.paddingBottom=P(t,"paddingBottom",!0)),d&&(h.zoom="1"),i=t.clientWidth,s=t.clientHeight,g=t.scrollWidth-i,v=t.scrollHeight-s,n=o.offsetHeight,(a||l)&&(this.left(a),this.top(l)))},this.content=o,this.element=t,this.enable()},z=function(i,r){t.call(this,i),i=T(i),s||(s=(window.GreenSockGlobals||window).com.greensock.plugins.ThrowPropsPlugin),this.vars=r=r||{},this.target=i,this.x=this.y=0;var l,u,f,w,b,A,D,O,M,L,E,N,X,B,Y,j,q,V=(r.type||(d?"top,left":"x,y")).toLowerCase(),W=-1!==V.indexOf("x")||-1!==V.indexOf("y"),H=-1!==V.indexOf("rotation"),Q=W?"x":"left",G=W?"y":"top",$=-1!==V.indexOf("x")||-1!==V.indexOf("left")||"scroll"===V,Z=-1!==V.indexOf("y")||-1!==V.indexOf("top")||"scroll"===V,K=this,J=T(r.trigger||i),te={},ee=parseFloat(r.edgeTolerance)||1-(void 0===r.edgeResistance?1:parseFloat(r.edgeResistance)),ie=function(){if(q){var t=K.x,s=K.y;H?(X.rotation="+="+(j-t)*p,e.set(i,N),j=t):l?(Z&&l.top(s),$&&l.left(t)):W?(Z&&(X.y=s),$&&(X.x=t),e.set(i,N)):(Z&&(i.style.top=s+"px"),$&&(i.style.left=t+"px")),D&&k(K,"drag","onDrag")}q=!1},se=function(t){if(d?t=y(t,!0):t.preventDefault(),!K.isDragging){if(t.changedTouches?(t=B=t.changedTouches[0],Y=t.identifier):B=null,g.push(ie),e.killTweensOf(l||i,te),f=t.pageY,u=t.pageX,H?(j=I(i),w=j.left,b=j.top,j=Math.atan2(b-f,u-w)):l?(b=l.top(),w=l.left()):(b=P(i,G),w=P(i,Q)),H||l||r.zIndexBoost===!1||(i.style.zIndex=z.zIndex++),B?(S(J,"touchend",ne),S(J,"touchmove",re)):(S(_,"mousemove",re),S(_,"mouseup",ne)),K.isDragging=!0,D=!(!r.onDrag&&!K._listeners.drag),A=q=!1,l)l.calibrate(),K.xMin=M=-l.maxScrollLeft(),K.yMin=E=-l.maxScrollTop(),K.xMax=O=K.yMax=L=0,A=!0;else if(r.bounds&&!H){var s=R(i),n=T(r.bounds),a=n?R(n):r.bounds;K.xMin=M=(W?0:P(i,"left"))+a.left-s.left,K.yMin=E=(W?0:P(i,"top"))+a.top-s.top,K.xMax=O=M+(a.width-i.offsetWidth),K.yMax=L=E+(a.height-i.offsetHeight),M>O&&(K.xMin=O,K.xMax=O=M,M=K.xMin),E>L&&(K.yMin=L,K.yMax=L=E,E=K.yMin),A=!0}A&&(w>O?w=O+(w-O)/ee:M>w&&(w=M-(M-w)/ee),b>L?b=L+(b-L)/ee:E>b&&(b=E-(E-b)/ee)),H||x(J,"cursor",r.cursor||"move"),k(K,"dragstart","onDragStart")}},re=function(t){d?t=y(t,!0):t.preventDefault();var e,i,s,r,n,a=t.changedTouches;if(a&&(t=a[0],t!==B&&t.identifier!==Y)){for(n=a.length;--n>-1&&(t=a[n]).identifier!==Y;);if(0>n)return}q=!0,H?K.x=Math.atan2(b-t.pageY,t.pageX-w):(i=t.pageY-f,e=t.pageX-u,s=e>2||-2>e?w+e:w,r=i>2||-2>i?b+i:b,A&&(s>O?s=O+(s-O)*ee:M>s&&(s=M+(s-M)*ee),r>L?r=L+(r-L)*ee:E>r&&(r=E+(r-E)*ee)),K.x!==s||K.y!==r?(K.x=s,K.y=r):q=!1)},ne=function(t){d?t=y(t,!0):t.preventDefault();var e,n,a,o,h,c=t.changedTouches,p=r.throwProps;if(c&&(t=c[0],t!==B&&t.identifier!==Y)){for(a=c.length;--a>-1&&(t=c[a]).identifier!==Y;);if(0>a)return}for(q=!1,a=g.length;--a>-1;)g[a]===ie&&g.splice(a,1);return n=t.pageY-f,e=t.pageX-u,K.isDragging=!1,B?(C(J,"touchend",ne),C(J,"touchmove",re)):(C(_,"mouseup",ne),C(_,"mousemove",re)),p&&s&&(p===!0&&(o=r.snap||{},h=o instanceof Array||"function"==typeof o,p={resistance:(r.resistance||1e3)/(H?100:1)},H?p.rotation=F(K,h?o:o.rotation,O,M,r.useRadians?null:m):($&&(p[Q]=F(K,h?o:o.x||o.left||o.scrollLeft,O,M,l?-1:null)),Z&&(p[G]=F(K,h?o:o.y||o.top||o.scrollTop,L,E,l?-1:null)))),s.to(l||i,{throwProps:p,ease:r.ease||Power3.easeOut,onComplete:r.onComplete,onUpdate:r.onUpdate},r.maxDuration||2,r.minDuration||.5,void 0===r.overshootTolerance?ee+.2:r.overshootTolerance)),H||x(J,"cursor",r.cursor||"move"),2>e&&e>-2&&2>n&&n>-2&&k(K,"click","onClick"),k(K,"dragend","onDragEnd"),!0};this.enable=function(){S(J,"mousedown",se),S(J,"touchstart",se),H||x(J,"cursor",r.cursor||"move"),x(J,"userSelect","none"),x(J,"touchCallout","none"),s&&s.track(l||i,W?"x,y":H?"rotation":"top,left"),l&&l.enable()},this.disable=function(){var t,r=this.isDragging;for(H||x(J,"cursor",null),e.killTweensOf(l||i,te),x(J,"userSelect","text"),x(J,"touchCallout","default"),C(J,"mousedown",se),C(J,"touchstart",se),C(_,"mouseup",ne),C(J,"touchend",ne),C(_,"mousemove",re),C(J,"touchmove",re),s&&s.untrack(l||i,W?"x,y":H?"rotation":"top,left"),l&&l.disable(),t=g.length;--t>-1;)g[t]===ie&&g.splice(t,1);this.isDragging=!1,r&&k(this,"dragend","onDragEnd")},-1!==V.indexOf("scroll")&&(l=this.scrollProxy=new U(i),i.style.overflowY=Z&&!v?"auto":"hidden",i.style.overflowX=$&&!v?"auto":"hidden",i=l.content),J.ondragstart=J.onselectstart=c,r.force3D!==!1&&e.set(i,{force3D:!0}),H?te.rotation=1:($&&(te.x=te.left=1),Z&&(te.y=te.top=1)),H?(N=h,X=N.css):W&&(N=$&&Z?n:$?a:o,X=N.css),this.isDragging=!1,this.enable()},B=z.prototype=new t;return B.constructor=z,z.version="0.7.0",z.zIndex=1e3,e.ticker.addEventListener("tick",function(){for(var t=g.length;--t>-1;)g[t]()}),S(_,"touchcancel",function(){}),z.create=function(t,i){"string"==typeof t&&(t=e.selector(t));for(var s=E(t)?N(t):[t],r=s.length;--r>-1;)s[r]=new z(s[r],i);return s},z},!0)}),window._gsDefine&&window._gsQueue.pop()();
\ No newline at end of file
diff --git a/src/uncompressed/utils/Draggable.js b/src/uncompressed/utils/Draggable.js
old mode 100644
new mode 100755
index 7e5cc1a..3edbb68
--- a/src/uncompressed/utils/Draggable.js
+++ b/src/uncompressed/utils/Draggable.js
@@ -1,8 +1,10 @@
/*!
- * VERSION: 0.6.0
- * DATE: 2013-07-19
+ * VERSION: 0.7.0
+ * DATE: 2013-08-18
* UPDATES AND DOCS AT: http://www.greensock.com
*
+ * Requires TweenLite and CSSPlugin (or TweenMax which contains both of those). ThrowPropsPlugin is required for momentum-based continuation of movement after the mouse/touch is released (ThrowPropsPlugin is a membership benefit of Club GreenSock - http://www.greensock.com/club/).
+ *
* @license Copyright (c) 2008-2013, GreenSock. All rights reserved.
* This work is subject to the terms at http://www.greensock.com/terms_of_use.html or for
* Club GreenSock members, the software agreement that was issued with your membership.
@@ -15,33 +17,48 @@
window._gsDefine("utils.Draggable", ["events.EventDispatcher","TweenLite"], function(EventDispatcher, TweenLite) {
- var tempVarsXY = {css:{}}, //speed optimization - we reuse the same vars object for x/y TweenLite.set() calls to minimize garbage collection tasks and improve performance.
- tempVarsX = {css:{}},
- tempVarsY = {css:{}},
- tempVarsRotation = {css:{}},
- tempEvent = {}, //for populating with pageX/pageY in old versions of IE
- doc = document,
- docElement = doc.documentElement,
- emptyArray = [],
- emptyFunc = function() { return false; },
- RAD2DEG = 180 / Math.PI,
- DEG2RAD = Math.PI / 180,
- isOldIE = (doc.all && !doc.addEventListener),
- prefix,
+ var _tempVarsXY = {css:{}}, //speed optimization - we reuse the same vars object for x/y TweenLite.set() calls to minimize garbage collection tasks and improve performance.
+ _tempVarsX = {css:{}},
+ _tempVarsY = {css:{}},
+ _tempVarsRotation = {css:{}},
+ _tempEvent = {}, //for populating with pageX/pageY in old versions of IE
+ _doc = document,
+ _docElement = _doc.documentElement,
+ _emptyArray = [],
+ _emptyFunc = function() { return false; },
+ _RAD2DEG = 180 / Math.PI,
+ _DEG2RAD = Math.PI / 180,
+ _isOldIE = (_doc.all && !_doc.addEventListener),
+ _updateQueue = [],
+ _isTouchDevice = (("ontouchstart" in _docElement) && ("orientation" in window)),
+ _prefix,
ThrowPropsPlugin,
//just used for IE8 and earlier to normalize events and populate pageX/pageY
- populateIEEvent = function(e, preventDefault) {
+ _populateIEEvent = function(e, preventDefault) {
e = e || window.event;
- tempEvent.pageX = e.clientX + doc.body.scrollLeft + docElement.scrollLeft;
- tempEvent.pageY = e.clientY + doc.body.scrollTop + docElement.scrollTop;
+ _tempEvent.pageX = e.clientX + _doc.body.scrollLeft + _docElement.scrollLeft;
+ _tempEvent.pageY = e.clientY + _doc.body.scrollTop + _docElement.scrollTop;
if (preventDefault) {
e.returnValue = false;
}
- return tempEvent;
+ return _tempEvent;
+ },
+
+ _unwrapElement = function(value) { //grabs the first element it finds (and we include the window as an element), so if it's selector text, it'll feed that value to TweenLite.selector, if it's a jQuery object or some other selector engine's result, it'll grab the first one, and same for an array. If the value doesn't contain a DOM element, it'll just return null.
+ if (!value) {
+ return value;
+ }
+ if (typeof(value) === "string") {
+ value = TweenLite.selector(value);
+ }
+ if (value.length && value !== window && value[0] && value[0].style && !value.nodeType) {
+ value = value[0];
+ }
+ return (value === window || (value.nodeType && value.style)) ? value : null;
},
- checkPrefix = function(e, p) {
+ _checkPrefix = function(e, p) {
var s = e.style,
capped, i, a;
if (s[p] === undefined) {
@@ -52,15 +69,15 @@
if (i < 0) {
return "";
}
- prefix = (i === 3) ? "ms" : a[i];
- p = prefix + capped;
+ _prefix = (i === 3) ? "ms" : a[i];
+ p = _prefix + capped;
}
return p;
},
- setStyle = function(e, p, value) {
+ _setStyle = function(e, p, value) {
var s = e.style;
if (s[p] === undefined) {
- p = checkPrefix(e, p);
+ p = _checkPrefix(e, p);
}
if (value == null) {
if (s.removeProperty) {
@@ -72,15 +89,15 @@
s[p] = value;
}
},
- getComputedStyle = doc.defaultView ? doc.defaultView.getComputedStyle : emptyFunc,
- getStyle = function(element, prop, keepUnits) {
+ _getComputedStyle = _doc.defaultView ? _doc.defaultView.getComputedStyle : _emptyFunc,
+ _getStyle = function(element, prop, keepUnits) {
var rv = (element._gsTransform || {})[prop],
cs;
if (rv || rv === 0) {
return rv;
} else if (element.style[prop]) {
rv = element.style[prop];
- } else if ((cs = getComputedStyle(element))) {
+ } else if ((cs = _getComputedStyle(element))) {
element = cs.getPropertyValue(prop.replace(/([A-Z])/g, "-$1").toLowerCase());
rv = (element || cs.length) ? element : cs[prop]; //Opera behaves VERY strangely - length is usually 0 and cs[prop] is the only way to get accurate results EXCEPT when checking for -o-transform which only works with cs.getPropertyValue()!
} else if (element.currentStyle) {
@@ -88,45 +105,45 @@
}
return keepUnits ? rv : parseFloat(rv) || 0;
},
- addListener = function(element, type, func) {
+ _addListener = function(element, type, func) {
if (element.addEventListener) {
element.addEventListener(type, func, false);
} else if (element.attachEvent) {
element.attachEvent("on" + type, func);
}
},
- removeListener = function(element, type, func) {
+ _removeListener = function(element, type, func) {
if (element.removeEventListener) {
element.removeEventListener(type, func);
} else if (element.detachEvent) {
element.detachEvent("on" + type, func);
}
},
- dispatchEvent = function(instance, type, callbackName) {
+ _dispatchEvent = function(instance, type, callbackName) {
var vars = instance.vars,
callback = vars[callbackName],
listeners = instance._listeners[type];
if (typeof(callback) === "function") {
- callback.apply(vars[callbackName + "Scope"] || instance, vars[callbackName + "Params"] || emptyArray);
+ callback.apply(vars[callbackName + "Scope"] || instance, vars[callbackName + "Params"] || _emptyArray);
}
if (listeners) {
instance.dispatchEvent(type);
}
},
- getBounds = function(e) {
+ _getBounds = function(e) {
if (e === window) {
return {
- top:(e.pageYOffset != null) ? e.pageYOffset : (doc.scrollTop != null) ? doc.scrollTop : doc.body.scrollTop || docElement.scrollTop || 0,
- left:(e.pageXOffset != null) ? e.pageXOffset : (doc.scrollLeft != null) ? doc.scrollLeft : doc.body.scrollLeft || docElement.scrollLeft || 0,
- width:(docElement ? docElement.clientWidth : e.innerWidth),
- height:(docElement ? docElement.clientHeight : e.innerHeight)
+ top:(e.pageYOffset != null) ? e.pageYOffset : (_doc.scrollTop != null) ? _doc.scrollTop : _doc.body.scrollTop || _docElement.scrollTop || 0,
+ left:(e.pageXOffset != null) ? e.pageXOffset : (_doc.scrollLeft != null) ? _doc.scrollLeft : _doc.body.scrollLeft || _docElement.scrollLeft || 0,
+ width:(_docElement ? _docElement.clientWidth : e.innerWidth),
+ height:(_docElement ? _docElement.clientHeight : e.innerHeight)
};
}
var width = e.offsetWidth,
height = e.offsetHeight,
top = e.offsetTop,
left = e.offsetLeft;
- if (isOldIE && e._gsTransform) {
+ if (_isOldIE && e._gsTransform) {
top -= e._gsTransform.y;
left -= e._gsTransform.x;
}
@@ -136,14 +153,16 @@
}
return {top:top, left:left, width:width, height:height};
},
- originProp = checkPrefix(doc.body, "transformOrigin").replace(/([A-Z])/g, "-$1").toLowerCase(),
- transformProp = checkPrefix(doc.body, "transform"),
- supports3D = (checkPrefix(doc.body, "perspective") !== ""),
- use3DTransform = (transformProp && supports3D),
- getTransformOriginOffset = function(e) {
- var bounds = getBounds(e),
- cs = getComputedStyle(e),
- v = (originProp && cs) ? cs.getPropertyValue(originProp) : "50% 50%",
+
+ _tempDiv = _doc.createElement("div"),
+ _originProp = _checkPrefix(_tempDiv, "transformOrigin").replace(/([A-Z])/g, "-$1").toLowerCase(),
+ _transformProp = _checkPrefix(_tempDiv, "transform"),
+ _supports3D = (_checkPrefix(_tempDiv, "perspective") !== ""),
+ _use3DTransform = (_transformProp && _supports3D),
+ _getTransformOriginOffset = function(e) {
+ var bounds = _getBounds(e),
+ cs = _getComputedStyle(e),
+ v = (_originProp && cs) ? cs.getPropertyValue(_originProp) : "50% 50%",
a = v.split(" "),
x = (v.indexOf("left") !== -1) ? "0%" : (v.indexOf("right") !== -1) ? "100%" : a[0],
y = (v.indexOf("top") !== -1) ? "0%" : (v.indexOf("bottom") !== -1) ? "100%" : a[1];
@@ -159,16 +178,16 @@
bounds.top += (y.indexOf("%") !== -1) ? bounds.height * parseFloat(y) / 100 : parseFloat(y);
return bounds;
},
- isArrayLike = function(e) {
+ _isArrayLike = function(e) {
return (e.length && e[0] && ((e[0].nodeType && e[0].style && !e.nodeType) || (e[0].length && e[0][0]))) ? true : false; //could be an array of jQuery objects too, so accommodate that.
},
- flattenArray = function(a) {
+ _flattenArray = function(a) {
var result = [],
l = a.length,
i, e, j;
for (i = 0; i < l; i++) {
e = a[i];
- if (isArrayLike(e)) {
+ if (_isArrayLike(e)) {
j = e.length;
for (j = 0; j < e.length; j++) {
result.push(e[j]);
@@ -179,7 +198,7 @@
}
return result;
},
- parseThrowProps = function(draggable, snap, max, min, factor) {
+ _parseThrowProps = function(draggable, snap, max, min, factor) {
var vars = {},
a, i, l;
if (snap) {
@@ -206,35 +225,36 @@
return vars;
},
- addPaddingBR,
- addPaddingLeft = (function() { //this function is in charge of analyzing browser behavior related to padding. It sets the addPaddingBR to true if the browser doesn't normally factor in the bottom or right padding on the element inside the scrolling area, and it sets addPaddingLeft to true if it's a browser that requires the extra offset (offsetLeft) to be added to the paddingRight (like Opera).
- var div = doc.createElement("div"),
- child = doc.createElement("div"),
+ _addPaddingBR,
+ _addPaddingLeft = (function() { //this function is in charge of analyzing browser behavior related to padding. It sets the _addPaddingBR to true if the browser doesn't normally factor in the bottom or right padding on the element inside the scrolling area, and it sets _addPaddingLeft to true if it's a browser that requires the extra offset (offsetLeft) to be added to the paddingRight (like Opera).
+ var div = _doc.createElement("div"),
+ child = _doc.createElement("div"),
childStyle = child.style,
+ parent = _doc.body || _tempDiv,
val;
childStyle.display = "inline-block";
childStyle.position = "relative";
div.style.cssText = child.innerHTML = "width:90px; height:40px; padding:10px; overflow:auto; visibility: hidden";
div.appendChild(child);
- doc.body.appendChild(div);
- addPaddingBR = (child.offsetHeight + 18 > div.scrollHeight); //div.scrollHeight should be child.offsetHeight + 20 because of the 10px of padding on each side, but some browsers ignore one side. We allow a 2px margin of error.
+ parent.appendChild(div);
+ _addPaddingBR = (child.offsetHeight + 18 > div.scrollHeight); //div.scrollHeight should be child.offsetHeight + 20 because of the 10px of padding on each side, but some browsers ignore one side. We allow a 2px margin of error.
childStyle.width = "100%";
- if (!use3DTransform) {
+ if (!_use3DTransform) {
childStyle.paddingRight = "500px";
val = div.scrollLeft = div.scrollWidth - div.clientWidth;
childStyle.left = "-90px";
val = (val !== div.scrollLeft);
}
- doc.body.removeChild(div);
+ parent.removeChild(div);
return val;
}()),
+
+
//The ScrollProxy class wraps an element's contents into another div (we call it "content") that we either add padding when necessary or apply a translate3d() transform in order to overscroll (scroll past the boundaries). This allows us to simply set the scrollTop/scrollLeft (or top/left for easier reverse-axis orientation, which is what we do in Draggable) and it'll do all the work for us. For example, if we tried setting scrollTop to -100 on a normal DOM element, it wouldn't work - it'd look the same as setting it to 0, but if we set scrollTop of a ScrollProxy to -100, it'll give the correct appearance by either setting paddingTop of the wrapper to 100 or applying a 100-pixel translateY.
ScrollProxy = function(element) {
- if (element.length && element[0]) {
- element = element[0];
- }
- var content = doc.createElement("div"),
+ element = _unwrapElement(element);
+ var content = _doc.createElement("div"),
style = content.style,
node = element.firstChild,
offsetTop = 0,
@@ -283,12 +303,12 @@
offsetLeft = 0;
}
if (offsetLeft || oldOffset) {
- if (use3DTransform) {
- style[transformProp] = "translate3d(" + -offsetLeft + "px," + -offsetTop + "px,0px)";
+ if (_use3DTransform) {
+ style[_transformProp] = "translate3d(" + -offsetLeft + "px," + -offsetTop + "px,0px)";
} else {
style.left = -offsetLeft + "px";
}
- if (addPaddingLeft && offsetLeft + extraPadRight >= 0) {
+ if (_addPaddingLeft && offsetLeft + extraPadRight >= 0) {
style.paddingRight = offsetLeft + extraPadRight + "px";
}
}
@@ -319,8 +339,8 @@
offsetTop = 0;
}
if (offsetTop || oldOffset) {
- if (use3DTransform) {
- style[transformProp] = "translate3d(" + -offsetLeft + "px," + -offsetTop + "px,0px)";
+ if (_use3DTransform) {
+ style[_transformProp] = "translate3d(" + -offsetLeft + "px," + -offsetTop + "px,0px)";
} else {
style.top = -offsetTop + "px";
}
@@ -381,7 +401,7 @@
extraPadRight = Math.max(0, element.scrollWidth - element.clientWidth);
//if the content is wider than the container, we need to add the paddingLeft and paddingRight in order for things to behave correctly.
if (extraPadRight) {
- extraPadRight += getStyle(element, "paddingLeft") + (addPaddingBR ? getStyle(element, "paddingRight") : 0);
+ extraPadRight += _getStyle(element, "paddingLeft") + (_addPaddingBR ? _getStyle(element, "paddingRight") : 0);
}
}
style.display = "inline-block";
@@ -390,10 +410,10 @@
style.width = "100%";
style.paddingRight = extraPadRight + "px";
//some browsers neglect to factor in the bottom padding when calculating the scrollHeight, so we need to add that padding to the content when that happens. Allow a 2px margin for error
- if (addPaddingBR) {
- style.paddingBottom = getStyle(element, "paddingBottom", true);
+ if (_addPaddingBR) {
+ style.paddingBottom = _getStyle(element, "paddingBottom", true);
}
- if (isOldIE) {
+ if (_isOldIE) {
style.zoom = "1";
}
elementWidth = element.clientWidth;
@@ -414,20 +434,16 @@
-
-
Draggable = function(target, vars) {
EventDispatcher.call(this, target);
- if (target.length && target[0]) { //in case the target is a selector object.
- target = target[0];
- }
+ target = _unwrapElement(target); //in case the target is a selector object or selector text
if (!ThrowPropsPlugin) {
ThrowPropsPlugin = (window.GreenSockGlobals || window).com.greensock.plugins.ThrowPropsPlugin;
}
this.vars = vars = vars || {};
this.target = target;
this.x = this.y = 0;
- var type = (vars.type || (isOldIE ? "top,left" : "x,y")).toLowerCase(),
+ var type = (vars.type || (_isOldIE ? "top,left" : "x,y")).toLowerCase(),
xyMode = (type.indexOf("x") !== -1 || type.indexOf("y") !== -1),
rotationMode = (type.indexOf("rotation") !== -1),
xProp = xyMode ? "x" : "left",
@@ -435,26 +451,72 @@
allowX = (type.indexOf("x") !== -1 || type.indexOf("left") !== -1 || type === "scroll"),
allowY = (type.indexOf("y") !== -1 || type.indexOf("top") !== -1 || type === "scroll"),
self = this,
+ trigger = _unwrapElement(vars.trigger || target),
killProps = {},
- edgeTolerance = parseFloat(vars.edgeTolerance) || (1 - (parseFloat(vars.edgeResistance) || 0)), //legacy support for edgeTolerance (new, more intuitive name is edgeResistance which works the opposite)
- scrollProxy, startMouseX, startMouseY, startElementX, startElementY, hasBounds, hasDragCallback, xMax, xMin, yMax, yMin, tempVars, cssVars, touch, touchID, rotationOffset,
+ edgeTolerance = parseFloat(vars.edgeTolerance) || (1 - ((vars.edgeResistance === undefined) ? 1 : parseFloat(vars.edgeResistance))), //legacy support for edgeTolerance (new, more intuitive name is edgeResistance which works the opposite)
+ scrollProxy, startMouseX, startMouseY, startElementX, startElementY, hasBounds, hasDragCallback, xMax, xMin, yMax, yMin, tempVars, cssVars, touch, touchID, rotationOffset, dirty,
+
+ //this method gets called on every tick of TweenLite.ticker which allows us to synchronize the updates to the core engine (which is typically synchronized with the display refresh via requestAnimationFrame). This is an optimization - it's better than applying the values inside the "mousemove" or "touchmove" event handler which may get called many times inbetween refreshes.
+ update = function() {
+ if (dirty) {
+ var x = self.x,
+ y = self.y;
+ if (rotationMode) {
+ cssVars.rotation = "+=" + ((rotationOffset - x) * _RAD2DEG);
+ TweenLite.set(target, tempVars);
+ rotationOffset = x;
+ } else {
+ if (scrollProxy) {
+ if (allowY) {
+ scrollProxy.top(y);
+ }
+ if (allowX) {
+ scrollProxy.left(x);
+ }
+ } else if (xyMode) {
+ if (allowY) {
+ cssVars.y = y;
+ }
+ if (allowX) {
+ cssVars.x = x;
+ }
+ TweenLite.set(target, tempVars);
+ } else {
+ if (allowY) {
+ target.style.top = y + "px";
+ }
+ if (allowX) {
+ target.style.left = x + "px";
+ }
+ }
+ }
+ if (hasDragCallback) {
+ _dispatchEvent(self, "drag", "onDrag");
+ }
+ }
+ dirty = false;
+ },
onPress = function(e) {
- if (isOldIE) {
- e = populateIEEvent(e, true);
+ if (_isOldIE) {
+ e = _populateIEEvent(e, true);
} else {
e.preventDefault();
}
+ if (self.isDragging) { //just in case the browser dispatches a "touchstart" and "mousedown" (some browsers emulate mouse events when using touches)
+ return;
+ }
if (e.changedTouches) { //touch events store the data slightly differently
e = touch = e.changedTouches[0];
touchID = e.identifier;
} else {
touch = null;
}
+ _updateQueue.push(update); //causes the Draggable to update on each "tick" of TweenLite.ticker (performance optimization - updating values in a mousemove can cause them to happen too frequently, like multiple times between frame redraws which is wasteful, and it also prevents values from updating properly in IE8)
TweenLite.killTweensOf(scrollProxy || target, killProps); //in case the user tries to drag it before the last tween is done.
startMouseY = e.pageY; //record the starting x and y so that we can calculate the movement from the original in _onMouseMove
startMouseX = e.pageX;
if (rotationMode) {
- rotationOffset = getTransformOriginOffset(target);
+ rotationOffset = _getTransformOriginOffset(target);
startElementX = rotationOffset.left;
startElementY = rotationOffset.top;
rotationOffset = Math.atan2(startElementY - startMouseY, startMouseX - startElementX);
@@ -462,22 +524,22 @@
startElementY = scrollProxy.top();
startElementX = scrollProxy.left();
} else {
- startElementY = getStyle(target, yProp); //record the starting top and left values so that we can just add the mouse's movement to them later.
- startElementX = getStyle(target, xProp);
+ startElementY = _getStyle(target, yProp); //record the starting top and left values so that we can just add the mouse's movement to them later.
+ startElementX = _getStyle(target, xProp);
}
if (!rotationMode && !scrollProxy && vars.zIndexBoost !== false) {
target.style.zIndex = Draggable.zIndex++;
}
if (touch) { //note: on iOS, BOTH touchmove and mousemove are dispatched, but the mousemove has pageY and pageX of 0 which would mess up the calculations and needlessly hurt performance.
- addListener(doc, "touchmove", onMove); //don't forget touch events
- addListener(doc, "touchend", onRelease);
+ _addListener(trigger, "touchend", onRelease);
+ _addListener(trigger, "touchmove", onMove); //don't forget touch events
} else {
- addListener(doc, "mousemove", onMove); //attach these to the document instead of the box itself so that if the user's mouse moves too quickly (and off of the box), things still work.
- addListener(doc, "mouseup", onRelease);
+ _addListener(_doc, "mousemove", onMove); //attach these to the document instead of the box itself so that if the user's mouse moves too quickly (and off of the box), things still work.
+ _addListener(_doc, "mouseup", onRelease);
}
self.isDragging = true;
hasDragCallback = !!(vars.onDrag || self._listeners.drag);
- hasBounds = false;
+ hasBounds = dirty = false;
if (scrollProxy) {
scrollProxy.calibrate();
self.xMin = xMin = -scrollProxy.maxScrollLeft();
@@ -486,10 +548,11 @@
hasBounds = true;
} else if (!!vars.bounds && !rotationMode) {
- var targetBounds = getBounds(target),
- bounds = (vars.bounds.length && vars.bounds !== window && vars.bounds[0] && !vars.bounds.nodeType) ? getBounds(vars.bounds[0]) : (vars.bounds === window || vars.bounds.style) ? getBounds(vars.bounds) : vars.bounds; //could be a selector/jQuery object or a DOM element or a generic object like {top:0, left:100, width:1000, height:800}
- self.xMin = xMin = (xyMode ? 0 : getStyle(target, "left")) + bounds.left - targetBounds.left;
- self.yMin = yMin = (xyMode ? 0 : getStyle(target, "top")) + bounds.top - targetBounds.top;
+ var targetBounds = _getBounds(target),
+ boundsElement = _unwrapElement(vars.bounds),
+ bounds = boundsElement ? _getBounds(boundsElement) : vars.bounds; //could be a selector/jQuery object or a DOM element or a generic object like {top:0, left:100, width:1000, height:800}
+ self.xMin = xMin = (xyMode ? 0 : _getStyle(target, "left")) + bounds.left - targetBounds.left;
+ self.yMin = yMin = (xyMode ? 0 : _getStyle(target, "top")) + bounds.top - targetBounds.top;
self.xMax = xMax = xMin + (bounds.width - target.offsetWidth);
self.yMax = yMax = yMin + (bounds.height - target.offsetHeight);
if (xMin > xMax) {
@@ -518,14 +581,13 @@
}
if (!rotationMode) {
- setStyle(target, "cursor", vars.cursor || "move");
+ _setStyle(trigger, "cursor", vars.cursor || "move");
}
- dispatchEvent(self, "dragstart", "onDragStart");
- return false;
+ _dispatchEvent(self, "dragstart", "onDragStart");
},
onMove = function(e) {
- if (isOldIE) {
- e = populateIEEvent(e, true);
+ if (_isOldIE) {
+ e = _populateIEEvent(e, true);
} else {
e.preventDefault();
}
@@ -541,15 +603,13 @@
}
}
}
+ dirty = true; //a flag that indicates we need to update the target next time the TweenLite.ticker dispatches a "tick" event (typically on a requestAnimationFrame) - this is a performance optimization (we shouldn't update on every move because sometimes many move events can get dispatched between screen refreshes, and that'd be wasteful to update every time)
if (rotationMode) {
- x = Math.atan2(startElementY - e.pageY, e.pageX - startElementX);
- cssVars.rotation = "+=" + ((rotationOffset - x) * RAD2DEG);
- TweenLite.set(target, tempVars);
- rotationOffset = x;
+ self.x = Math.atan2(startElementY - e.pageY, e.pageX - startElementX);
} else {
- yChange = (e.pageY - startMouseY),
- xChange = (e.pageX - startMouseX),
- x = (xChange > 2 || xChange < -2) ? startElementX + xChange : startElementX,
+ yChange = (e.pageY - startMouseY);
+ xChange = (e.pageX - startMouseX);
+ x = (xChange > 2 || xChange < -2) ? startElementX + xChange : startElementX;
y = (yChange > 2 || yChange < -2) ? startElementY + yChange : startElementY;
if (hasBounds) {
if (x > xMax) {
@@ -563,40 +623,19 @@
y = yMin + (y - yMin) * edgeTolerance;
}
}
- self.x = x;
- self.y = y;
- if (scrollProxy) {
- if (allowY) {
- scrollProxy.top(y);
- }
- if (allowX) {
- scrollProxy.left(x);
- }
- } else if (xyMode) {
- if (allowY) {
- cssVars.y = y;
- }
- if (allowX) {
- cssVars.x = x;
- }
- TweenLite.set(target, tempVars);
+ if (self.x !== x || self.y !== y) {
+ self.x = x;
+ self.y = y;
} else {
- if (allowY) {
- target.style.top = y + "px";
- }
- if (allowX) {
- target.style.left = x + "px";
- }
+ dirty = false;
}
}
- if (hasDragCallback) {
- dispatchEvent(self, "drag", "onDrag");
- }
- return true;
},
onRelease = function(e) {
- if (isOldIE) {
- e = populateIEEvent(e, false);
+ if (_isOldIE) {
+ e = _populateIEEvent(e, true);
+ } else {
+ e.preventDefault();
}
var touches = e.changedTouches,
throwProps = vars.throwProps,
@@ -611,48 +650,59 @@
}
}
}
+ dirty = false;
+ i = _updateQueue.length;
+ while (--i > -1) {
+ if (_updateQueue[i] === update) {
+ _updateQueue.splice(i, 1);
+ }
+ }
yChange = (e.pageY - startMouseY);
xChange = (e.pageX - startMouseX);
self.isDragging = false;
- removeListener(doc, "mouseup", onRelease);
- removeListener(doc, "touchend", onRelease);
- removeListener(doc, "mousemove", onMove);
- removeListener(doc, "touchmove", onMove);
+ if (touch) {
+ _removeListener(trigger, "touchend", onRelease);
+ _removeListener(trigger, "touchmove", onMove);
+ } else {
+ _removeListener(_doc, "mouseup", onRelease);
+ _removeListener(_doc, "mousemove", onMove);
+ }
if (throwProps && ThrowPropsPlugin) {
if (throwProps === true) {
snap = vars.snap || {};
snapIsRaw = (snap instanceof Array || typeof(snap) === "function");
throwProps = {resistance:(vars.resistance || 1000) / (rotationMode ? 100 : 1)};
if (rotationMode) {
- throwProps.rotation = parseThrowProps(self, snapIsRaw ? snap : snap.rotation, xMax, xMin, vars.useRadians ? null : DEG2RAD);
+ throwProps.rotation = _parseThrowProps(self, snapIsRaw ? snap : snap.rotation, xMax, xMin, vars.useRadians ? null : _DEG2RAD);
} else {
if (allowX) {
- throwProps[xProp] = parseThrowProps(self, snapIsRaw ? snap : snap.x || snap.left || snap.scrollLeft, xMax, xMin, scrollProxy ? -1 : null);
+ throwProps[xProp] = _parseThrowProps(self, snapIsRaw ? snap : snap.x || snap.left || snap.scrollLeft, xMax, xMin, scrollProxy ? -1 : null);
}
if (allowY) {
- throwProps[yProp] = parseThrowProps(self, snapIsRaw ? snap : snap.y || snap.top || snap.scrollTop, yMax, yMin, scrollProxy ? -1 : null);
+ throwProps[yProp] = _parseThrowProps(self, snapIsRaw ? snap : snap.y || snap.top || snap.scrollTop, yMax, yMin, scrollProxy ? -1 : null);
}
}
}
ThrowPropsPlugin.to(scrollProxy || target, {throwProps:throwProps, ease:(vars.ease || Power3.easeOut), onComplete:vars.onComplete, onUpdate:vars.onUpdate}, vars.maxDuration || 2, vars.minDuration || 0.5, (vars.overshootTolerance === undefined) ? edgeTolerance + 0.2 : vars.overshootTolerance);
}
if (!rotationMode) {
- setStyle(target, "cursor", vars.cursor || "move");
+ _setStyle(trigger, "cursor", vars.cursor || "move");
}
if (xChange < 2 && xChange > -2 && yChange < 2 && yChange > -2) {
- dispatchEvent(self, "click", "onClick");
+ _dispatchEvent(self, "click", "onClick");
}
- dispatchEvent(self, "dragend", "onDragEnd");
+ _dispatchEvent(self, "dragend", "onDragEnd");
+ return true;
};
this.enable = function() {
- addListener(target, "mousedown", onPress);
- addListener(target, "touchstart", onPress);
+ _addListener(trigger, "mousedown", onPress);
+ _addListener(trigger, "touchstart", onPress);
if (!rotationMode) {
- setStyle(target, "cursor", vars.cursor || "move");
+ _setStyle(trigger, "cursor", vars.cursor || "move");
}
- setStyle(target, "userSelect", "none");
- setStyle(target, "touchCallout", "none");
+ _setStyle(trigger, "userSelect", "none");
+ _setStyle(trigger, "touchCallout", "none");
if (ThrowPropsPlugin) {
ThrowPropsPlugin.track(scrollProxy || target, (xyMode ? "x,y" : rotationMode ? "rotation" : "top,left"));
}
@@ -662,45 +712,51 @@
};
this.disable = function() {
- var dragging = this.isDragging;
+ var dragging = this.isDragging,
+ i;
if (!rotationMode) {
- setStyle(target, "cursor", null);
+ _setStyle(trigger, "cursor", null);
}
TweenLite.killTweensOf(scrollProxy || target, killProps); //in case the user tries to drag it before the last tween is done.
- setStyle(target, "userSelect", "text");
- setStyle(target, "touchCallout", "default");
- removeListener(target, "mousedown", onPress);
- removeListener(target, "touchstart", onPress);
- removeListener(doc, "mouseup", onRelease);
- removeListener(doc, "touchend", onRelease);
- removeListener(doc, "mousemove", onMove);
- removeListener(doc, "touchmove", onMove);
+ _setStyle(trigger, "userSelect", "text");
+ _setStyle(trigger, "touchCallout", "default");
+ _removeListener(trigger, "mousedown", onPress);
+ _removeListener(trigger, "touchstart", onPress);
+ _removeListener(_doc, "mouseup", onRelease);
+ _removeListener(trigger, "touchend", onRelease);
+ _removeListener(_doc, "mousemove", onMove);
+ _removeListener(trigger, "touchmove", onMove);
if (ThrowPropsPlugin) {
ThrowPropsPlugin.untrack(scrollProxy || target, (xyMode ? "x,y" : rotationMode ? "rotation" : "top,left"));
}
if (scrollProxy) {
scrollProxy.disable();
}
+ i = _updateQueue.length;
+ while (--i > -1) {
+ if (_updateQueue[i] === update) {
+ _updateQueue.splice(i, 1);
+ }
+ }
this.isDragging = false;
if (dragging) {
- dispatchEvent(this, "dragend", "onDragEnd");
+ _dispatchEvent(this, "dragend", "onDragEnd");
}
};
if (type.indexOf("scroll") !== -1) {
scrollProxy = this.scrollProxy = new ScrollProxy(target);
- if (target._gsTransform && target._gsTransform.z === 0.01) {
- TweenLite.set(target, {z:0}); //if the element and the ScrollProxy's content share the same z transform, some Webkit browsers ignore mouse clicks on it.
- TweenLite.set(target, {z:0});
- }
- target.style.overflowY = allowY ? "auto" : "hidden";
- target.style.overflowX = allowX ? "auto" : "hidden";
+ //a bug in many Android devices' stock browser causes scrollTop to get forced back to 0 after it is altered via JS, so we set overflow to "hidden" on mobile/touch devices (they hide the scroll bar anyway). That works around the bug. (This bug is discussed at https://code.google.com/p/android/issues/detail?id=19625)
+ target.style.overflowY = (allowY && !_isTouchDevice) ? "auto" : "hidden";
+ target.style.overflowX = (allowX && !_isTouchDevice) ? "auto" : "hidden";
target = scrollProxy.content;
}
// prevent IE from trying to drag an image and prevent text selection in IE
- target.ondragstart = doc.onselectstart = target.onselectstart = emptyFunc;
- TweenLite.set(target, {z:"+=0.01"}); //improve performance by forcing a GPU layer when possible
+ trigger.ondragstart = trigger.onselectstart = _emptyFunc;
+ if (vars.force3D !== false) {
+ TweenLite.set(target, {force3D:true}); //improve performance by forcing a GPU layer when possible
+ }
if (rotationMode) {
killProps.rotation = 1;
} else {
@@ -712,10 +768,10 @@
}
}
if (rotationMode) {
- tempVars = tempVarsRotation;
+ tempVars = _tempVarsRotation;
cssVars = tempVars.css;
} else if (xyMode) {
- tempVars = (allowX && allowY) ? tempVarsXY : allowX ? tempVarsX : tempVarsY;
+ tempVars = (allowX && allowY) ? _tempVarsXY : allowX ? _tempVarsX : _tempVarsY;
cssVars = tempVars.css;
}
this.isDragging = false;
@@ -724,14 +780,25 @@
p = Draggable.prototype = new EventDispatcher();
p.constructor = Draggable;
- Draggable.version = "0.6.0";
+ Draggable.version = "0.7.0";
Draggable.zIndex = 1000;
+ TweenLite.ticker.addEventListener("tick", function() {
+ var i = _updateQueue.length;
+ while (--i > -1) {
+ _updateQueue[i]();
+ }
+ });
+
+ _addListener(_doc, "touchcancel", function() {
+ //some older Android devices intermittently stop dispatching "touchmove" events if we don't listen for "touchcancel" on the document. Very strange indeed.
+ });
+
Draggable.create = function(targets, vars) {
if (typeof(targets) === "string") {
targets = TweenLite.selector(targets);
}
- var a = isArrayLike(targets) ? flattenArray(targets) : [targets],
+ var a = _isArrayLike(targets) ? _flattenArray(targets) : [targets],
i = a.length;
while (--i > -1) {
a[i] = new Draggable(a[i], vars);