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