scrollview-base-min.js revision 2fa5097a3aeeb55f42fc08ca26084a36c7d69dcb
YUI.add("scrollview-base",function(C){var D=C.ClassNameManager.getClassName,K="scrollview",H={scrollbar:D(K,"scrollbar"),vertical:D(K,"vertical"),horizontal:D(K,"horizontal"),child:D(K,"child"),top:D(K,"top"),bottom:D(K,"bottom"),middle:D(K,"middle"),showing:D(K,"showing")},A="scrollStart",F="scrollChange",P="scrollEnd",L="flick",E="ui",I="scrollY",J="scrollX",N="bounce",M="boundingBox",O="contentBox",B=C.TransitionNative.supported;C.Node.DOM_EVENTS.DOMSubtreeModified=true;function G(){G.superclass.constructor.apply(this,arguments);}C.ScrollView=C.extend(G,C.Widget,{initializer:function(){this._createEvents();},_createEvents:function(){this.publish(A);this.publish(F);this.publish(P);this.publish(L);},_uiSizeCB:function(){},_transitionEnded:function(){this.fire(P);},bindUI:function(){this.get(M).on("gesturemovestart",C.bind(this._onGestureMoveStart,this));var Q=this.get(O);Q.on("transitionend",C.bind(this._transitionEnded,this),false);if(B){Q.on("DOMSubtreeModified",C.bind(this._uiDimensionsChange,this));}Q.on("flick",C.bind(this._flick,this),{minDistance:0});this.after({"scrollYChange":this._afterScrollYChange,"scrollXChange":this._afterScrollXChange,"heightChange":this._afterHeightChange,"widthChange":this._afterWidthChange,"renderedChange":function(){C.later(0,this,"_uiDimensionsChange");}});},syncUI:function(){this.scrollTo(this.get(J),this.get(I));},scrollTo:function(R,X,T,W){var Q=this.get(O),S=R*-1,V=X*-1,U;if(R!==this.get(J)){this.set(J,R,{src:E});}if(X!==this.get(I)){this.set(I,X,{src:E});}U={easing:W||G.EASING,duration:T/1000};if(B){U.transform="translate("+S+"px,"+V+"px)";}else{U.easing="ease-out";U.left=S+"px";U.top=V+"px";}Q.transition(U);},_onGestureMoveStart:function(Q){this._killTimer();var R=this.get(M);this._moveEvt=R.on("gesturemove",C.bind(this._onGestureMove,this));this._moveEndEvt=R.on("gesturemoveend",C.bind(this._onGestureMoveEnd,this));this._moveStartY=Q.clientY+this.get(I);this._moveStartX=Q.clientX+this.get(J);this._moveStartTime=(new Date()).getTime();this._moveStartClientY=Q.clientY;this._moveStartClientX=Q.clientX;this._isDragging=false;this._snapToEdge=false;},_onGestureMove:function(Q){this._isDragging=true;this._moveEndClientY=Q.clientY;this._moveEndClientX=Q.clientX;this._lastMoved=(new Date()).getTime();if(this._scrollsVertical){this.set(I,-(Q.clientY-this._moveStartY));}if(this._scrollsHorizontal){this.set(J,-(Q.clientX-this._moveStartX));}},_onGestureMoveEnd:function(V){var X=this._minScrollY,T=this._maxScrollY,Q=this._minScrollX,U=this._maxScrollX,S=this._scrollsVertical?this._moveStartClientY:this._moveStartClientX,R=this._scrollsVertical?this._moveEndClientY:this._moveEndClientX,W=S-R;this._moveEvt.detach();this._moveEndEvt.detach();this._scrolledHalfway=false;this._snapToEdge=false;this._isDragging=false;if(this._scrollsHorizontal&&Math.abs(W)>(this.get("width")/2)){this._scrolledHalfway=true;this._scrolledForward=W>0;}if(this._scrollsVertical&&Math.abs(W)>(this.get("height")/2)){this._scrolledHalfway=true;this._scrolledForward=W>0;}if(this._scrollsVertical&&this.get(I)<X){this._snapToEdge=true;this.set(I,X);}if(this._scrollsHorizontal&&this.get(J)<Q){this._snapToEdge=true;this.set(J,Q);}if(this.get(I)>T){this._snapToEdge=true;this.set(I,T);}if(this.get(J)>U){this._snapToEdge=true;this.set(J,U);}if(this._snapToEdge){return;}if(+(new Date())-this._moveStartTime>100){this.fire(P,{staleScroll:true});return;}},_afterScrollYChange:function(Q){if(Q.src!==E){this._uiScrollY(Q.newVal,Q.duration,Q.easing);}},_uiScrollY:function(R,Q,S){Q=Q||this._snapToEdge?400:0;S=S||this._snapToEdge?G.SNAP_EASING:null;this.scrollTo(this.get(J),R,Q,S);},_afterScrollXChange:function(Q){if(Q.src!==E){this._uiScrollX(Q.newVal,Q.duration,Q.easing);}},_uiScrollX:function(R,Q,S){Q=Q||this._snapToEdge?400:0;S=S||this._snapToEdge?G.SNAP_EASING:null;this.scrollTo(R,this.get(I),Q,S);},_afterHeightChange:function(){this._uiDimensionsChange();},_afterWidthChange:function(){this._uiDimensionsChange();},_uiDimensionsChange:function(){var R=this.get(O),V=this.get(M),Q=this.get("height"),U=this.get("width"),T=V.get("scrollHeight"),S=V.get("scrollWidth");if(Q&&T>Q){this._scrollsVertical=true;this._maxScrollY=T-Q;this._minScrollY=0;V.addClass(D("scroll-v"));}if(U&&S>U){this._scrollsHorizontal=true;this._maxScrollX=S-U;this._minScrollX=0;V.addClass(this.getClassName("scroll-h"));}},_flick:function(R){var Q=R.flick;this._currentVelocity=Q.velocity*Q.direction;this._flicking=true;this._flickFrame();this.fire(L);},_flickFrame:function(){var U=this.get(I),S=this._maxScrollY,W=this._minScrollY,V=this.get(J),T=this._maxScrollX,Q=this._minScrollX,R=G.FRAME_STEP;this._currentVelocity=(this._currentVelocity*this.get("deceleration"));if(this._scrollsVertical){U=this.get(I)-(this._currentVelocity*R);}if(this._scrollsHorizontal){V=this.get(J)-(this._currentVelocity*R);}if(Math.abs(this._currentVelocity).toFixed(4)<=0.015){this._flicking=false;this._killTimer(!(this._exceededYBoundary||this._exceededXBoundary));if(this._scrollsVertical){if(U<W){this._snapToEdge=true;this.set(I,W);}else{if(U>S){this._snapToEdge=true;this.set(I,S);}}}if(this._scrollsHorizontal){if(V<Q){this._snapToEdge=true;this.set(J,Q);}else{if(V>T){this._snapToEdge=true;this.set(J,T);}}}return;}if(this._scrollsVertical&&(U<W||U>S)){this._exceededYBoundary=true;this._currentVelocity*=this.get(N);}if(this._scrollsHorizontal&&(V<Q||V>T)){this._exceededXBoundary=true;this._currentVelocity*=this.get(N);}if(this._scrollsVertical){this.set(I,U);}if(this._scrollsHorizontal){this.set(J,V);}this._flickTimer=C.later(G.FRAME_STEP,this,"_flickFrame");},_killTimer:function(Q){if(this._flickTimer){this._flickTimer.cancel();}if(Q){this.fire(P);}},_setScrollX:function(U){var S=this.get(N),R=G.BOUNCE_RANGE,T=S?-R:0,Q=S?this._maxScrollX+R:this._maxScrollX;if(!S||!this._isDragging){if(U<T){U=T;}else{if(U>Q){U=Q;}}}return U;},_setScrollY:function(U){var S=this.get(N),R=G.BOUNCE_RANGE,T=S?-R:0,Q=S?this._maxScrollY+R:this._maxScrollY;if(!S||!this._isDragging){if(U<T){U=T;
}else{if(U>Q){U=Q;}}}return U;}},{NAME:"scrollview",ATTRS:{scrollY:{value:0,setter:"_setScrollY"},scrollX:{value:0,setter:"_setScrollX"},deceleration:{value:0.98},bounce:{value:0.7}},CLASS_NAMES:H,UI_SRC:E,BOUNCE_RANGE:150,FRAME_STEP:10,EASING:"cubic-bezier(0, 0.1, 0, 1.0)",SNAP_EASING:"ease-out"});},"@VERSION@",{skinnable:true,requires:["widget","event-gestures","transition"]});