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