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