scrollview-base-min.js revision beaf58250217db9662fba98450d8719de5e80834
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTrippYUI.add("scrollview-base",function(B){var F=B.ClassNameManager.getClassName,R="scrollview",Q={vertical:F(R,"vert"),horizontal:F(R,"horiz")},V="scrollEnd",H="flick",A=H,G="ui",J="left",M="top",E="px",K="scrollY",L="scrollX",C="bounce",P="x",O="y",S="boundingBox",I="contentBox",U="",N="0s",D=B.Transition.useNative;B.Node.DOM_EVENTS.DOMSubtreeModified=true;function T(){T.superclass.constructor.apply(this,arguments);}B.ScrollView=B.extend(T,B.Widget,{initializer:function(){this._createEvents();this._cb=this.get(I);this._bb=this.get(S);},_createEvents:function(){this.publish(V);this.publish(H);},_uiSizeCB:function(){},_transitionEnded:function(W){this.fire(V);},bindUI:function(){var W=this._cb,X=this.get(A);this._bb.on("gesturemovestart",B.bind(this._onGestureMoveStart,this));if(D){W.on("DOMSubtreeModified",B.bind(this._uiDimensionsChange,this));}if(X){W.on("flick",B.bind(this._flick,this),X);}this.after({"scrollYChange":this._afterScrollYChange,"scrollXChange":this._afterScrollXChange,"heightChange":this._afterHeightChange,"widthChange":this._afterWidthChange,"renderedChange":function(){B.later(0,this,"_uiDimensionsChange");}});},syncUI:function(){this.scrollTo(this.get(L),this.get(K));},scrollTo:function(f,e,a,d){var Z=this._cb,b=(f!==null),Y=(e!==null),X=(b)?f*-1:0,W=(Y)?e*-1:0,c,g=this._transEndCallback;a=a||0;d=d||T.EASING;if(b){this.set(L,f,{src:G});}if(Y){this.set(K,e,{src:G});}if(D){Z.setStyle(T._TRANSITION_DURATION,N);Z.setStyle(T._TRANSITION_PROPERTY,U);}if(a!==0){c={easing:d,duration:a/1000};if(D){c.transform="translate3D("+X+"px,"+W+"px, 0px)";}else{if(b){c.left=X+E;}if(Y){c.top=W+E;}}if(!g){g=this._transEndCallback=B.bind(this._transitionEnded,this);}Z.transition(c,g);}else{if(D){Z.setStyle("transform","translate3D("+X+"px,"+W+"px, 0px)");}else{if(b){Z.setStyle(J,X+E);}if(Y){Z.setStyle(M,W+E);}}}},_onGestureMoveStart:function(W){W.preventDefault();this._killTimer();var X=this._bb;this._moveEvt=X.on("gesturemove",B.bind(this._onGestureMove,this));this._moveEndEvt=X.on("gesturemoveend",B.bind(this._onGestureMoveEnd,this));this._moveStartY=W.clientY+this.get(K);this._moveStartX=W.clientX+this.get(L);this._moveStartTime=(new Date()).getTime();this._moveStartClientY=W.clientY;this._moveStartClientX=W.clientX;this._isDragging=false;this._flicking=false;this._snapToEdge=false;},_onGestureMove:function(W){W.preventDefault();this._isDragging=true;this._moveEndClientY=W.clientY;this._moveEndClientX=W.clientX;this._lastMoved=(new Date()).getTime();if(this._scrollsVertical){this.set(K,-(W.clientY-this._moveStartY));}if(this._scrollsHorizontal){this.set(L,-(W.clientX-this._moveStartX));}},_onGestureMoveEnd:function(b){b.preventDefault();var d=this._minScrollY,Z=this._maxScrollY,W=this._minScrollX,a=this._maxScrollX,Y=this._scrollsVertical?this._moveStartClientY:this._moveStartClientX,X=this._scrollsVertical?this._moveEndClientY:this._moveEndClientX,c=Y-X;this._moveEvt.detach();this._moveEndEvt.detach();this._scrolledHalfway=false;this._snapToEdge=false;this._isDragging=false;if(this._scrollsHorizontal&&Math.abs(c)>(this.get("width")/2)){this._scrolledHalfway=true;this._scrolledForward=c>0;}if(this._scrollsVertical&&Math.abs(c)>(this.get("height")/2)){this._scrolledHalfway=true;this._scrolledForward=c>0;}if(this._scrollsVertical&&this.get(K)<d){this._snapToEdge=true;this.set(K,d);}if(this._scrollsHorizontal&&this.get(L)<W){this._snapToEdge=true;this.set(L,W);}if(this.get(K)>Z){this._snapToEdge=true;this.set(K,Z);}if(this.get(L)>a){this._snapToEdge=true;this.set(L,a);}if(this._snapToEdge){return;}this.fire(V,{onGestureMoveEnd:true});return;},_afterScrollYChange:function(W){if(W.src!==G){this._uiScrollY(W.newVal,W.duration,W.easing);}},_uiScrollY:function(X,W,Y){W=W||this._snapToEdge?400:0;Y=Y||this._snapToEdge?T.SNAP_EASING:null;this.scrollTo(null,X,W,Y);},_afterScrollXChange:function(W){if(W.src!==G){this._uiScrollX(W.newVal,W.duration,W.easing);}},_uiScrollX:function(X,W,Y){W=W||this._snapToEdge?400:0;Y=Y||this._snapToEdge?T.SNAP_EASING:null;this.scrollTo(X,null,W,Y);},_afterHeightChange:function(){this._uiDimensionsChange();},_afterWidthChange:function(){this._uiDimensionsChange();},_uiDimensionsChange:function(){var a=this._bb,W=this.get("height"),Z=this.get("width"),Y=a.get("scrollHeight"),X=a.get("scrollWidth");if(W&&Y>W){this._scrollsVertical=true;this._maxScrollY=Y-W;this._minScrollY=0;this._scrollHeight=Y;a.addClass(T.CLASS_NAMES.vertical);}if(Z&&X>Z){this._scrollsHorizontal=true;this._maxScrollX=X-Z;this._minScrollX=0;this._scrollWidth=X;a.addClass(T.CLASS_NAMES.horizontal);}},_flick:function(X){var W=X.flick;this._currentVelocity=W.velocity;this._flicking=true;this._decelCached=this.get("deceleration");this._bounceCached=this.get("bounce");this._pastYEdge=false;this._pastXEdge=false;this._flickFrame();this.fire(H);},_flickFrame:function(){var g,X,a,W,Y,b,e=this._scrollsVertical,d=this._scrollsHorizontal,c=this._decelCached,f=this._bounceCached,Z=T.FRAME_STEP;if(e){X=this._maxScrollY;a=this._minScrollY;g=this.get(K)-(this._currentVelocity*Z);}if(d){Y=this._maxScrollX;b=this._minScrollX;W=this.get(L)-(this._currentVelocity*Z);}this._currentVelocity=(this._currentVelocity*c);if(Math.abs(this._currentVelocity).toFixed(4)<=0.015){this._flicking=false;this._killTimer(!(this._pastYEdge||this._pastXEdge));if(e){if(g<a){this._snapToEdge=true;this.set(K,a);}else{if(g>X){this._snapToEdge=true;this.set(K,X);}}}if(d){if(W<b){this._snapToEdge=true;this.set(L,b);}else{if(W>Y){this._snapToEdge=true;this.set(L,Y);}}}return;}if(e){if(g<a||g>X){this._pastYEdge=true;this._currentVelocity*=f;}this.set(K,g);}if(d){if(W<b||W>Y){this._pastXEdge=true;this._currentVelocity*=f;}this.set(L,W);}if(!this._flickTimer){this._flickTimer=B.later(Z,this,"_flickFrame",null,true);}},_killTimer:function(W){if(this._flickTimer){this._flickTimer.cancel();this._flickTimer=null;}if(W){this.fire(V);}},_setScroll:function(c,b){var Y=this._cachedBounce||this.get(C),X=T.BOUNCE_RANGE,a=(b==P)?this._maxScrollX:this._maxScrollY,Z=Y?-X:0,W=Y?a+X:a;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTrippif(!Y||!this._isDragging){if(c<Z){c=Z;}else{if(c>W){c=W;}}}return c;},_setScrollX:function(W){return this._setScroll(W,P);},_setScrollY:function(W){return this._setScroll(W,O);}},{NAME:"scrollview",ATTRS:{scrollY:{value:0,setter:"_setScrollY"},scrollX:{value:0,setter:"_setScrollX"},deceleration:{value:0.93},bounce:{value:0.1},flick:{value:{minDistance:10,minVelocity:0.3}}},CLASS_NAMES:Q,UI_SRC:G,BOUNCE_RANGE:150,FRAME_STEP:30,EASING:"cubic-bezier(0, 0.1, 0, 1.0)",SNAP_EASING:"ease-out",_TRANSITION_DURATION:"WebkitTransitionDuration",_TRANSITION_PROPERTY:"WebkitTransitionProperty"});},"@VERSION@",{skinnable:true,requires:["widget","event-gestures","transition"]});