6 var XUI_ScrollBox_current,
\r
7 XUI_ScrollBox_indicatorV,
\r
8 XUI_ScrollBox_indicatorH;
\r
10 function XUI_ScrollBox_start( scrollBox ){
\r
12 if( scrollBox.hasVScroll ){
\r
13 if( !XUI_ScrollBox_indicatorV ){
\r
14 XUI_ScrollBox_indicatorV = X_Doc_create( 'div' )[ 'className' ]( 'ScrollBox-IndicatorV' );
\r
16 if( XUI_ScrollBox_current )
\r
17 XUI_ScrollBox_current[ 'unlisten' ]( [ X_EVENT_CANCELED, XUI_Event.SCROLL_END ], XUI_ScrollBox_indicatorV, XUI_ScrollBox_indicatorHandleEvent );
\r
19 scrollBox.xnode[ 'append' ]( XUI_ScrollBox_indicatorV );
\r
20 XUI_ScrollBox_indicatorV[ 'animate' ](
\r
23 900, 'circular', 300
\r
26 [ 'listenOnce' ]( [ X_EVENT_CANCELED, XUI_Event.SCROLL_END ], XUI_ScrollBox_indicatorV, XUI_ScrollBox_indicatorHandleEvent );
\r
28 if( XUI_ScrollBox_indicatorV ){
\r
29 XUI_ScrollBox_indicatorV[ 'remove' ]();
\r
32 if( scrollBox.hasHScroll ){
\r
33 if( !XUI_ScrollBox_indicatorH ){
\r
34 XUI_ScrollBox_indicatorH = X_Doc_create( 'div' )[ 'className' ]( 'ScrollBox-IndicatorH' );
\r
36 if( XUI_ScrollBox_current )
\r
37 XUI_ScrollBox_current[ 'unlisten' ]( [ X_EVENT_CANCELED, XUI_Event.SCROLL_END ], XUI_ScrollBox_indicatorH, XUI_ScrollBox_indicatorHandleEvent );
\r
38 scrollBox.xnode[ 'append' ]( XUI_ScrollBox_indicatorH );
\r
39 XUI_ScrollBox_indicatorH[ 'animate' ](
\r
42 900, 'circular', 300
\r
45 [ 'listenOnce' ]( [ X_EVENT_CANCELED, XUI_Event.SCROLL_END ], XUI_ScrollBox_indicatorH, XUI_ScrollBox_indicatorHandleEvent );
\r
47 if( XUI_ScrollBox_indicatorH ){
\r
48 XUI_ScrollBox_indicatorH[ 'remove' ]();
\r
50 XUI_ScrollBox_current = scrollBox;
\r
53 function XUI_ScrollBox_indicatorHandleEvent( e ){
\r
55 case X_EVENT_CANCELED :
\r
56 case XUI_Event.SCROLL_END :
\r
57 console.log( '-fadeout-' );
\r
61 900, 'circular', 300
\r
68 var X_UI_ScrollBox_SUPPORT_ATTRS = {
\r
69 // スクロール開始するために必要な移動距離、縦か横、どちらか制限する場合、より重要
\r
70 directionLockThreshold : [ 10, XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.LENGTH ],
\r
71 scrollXEnabled : [ true, XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.BOOLEAN ],
\r
72 scrollYEnabled : [ true, XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.BOOLEAN ],
\r
73 scrollEnabled : [ true, XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.BOOLEAN ],
\r
74 bounceEnabled : [ true, XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.BOOLEAN ],
\r
75 bounceTime : [ 300, XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.TIME ],
\r
76 useWheel : [ true, XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.BOOLEAN ],
\r
77 useKey : [ true, XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.BOOLEAN ],
\r
78 hasScrollShadow : [ true, XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.BOOLEAN ],
\r
79 scrollShadowColor : [ '#000', XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.COLOR ]
\r
82 var XUI_ScrollBox = XUI_ChromeBox.inherits(
\r
86 layout : XUI_Layout_Canvas,
\r
88 directionLockThreshold : 10,
\r
89 scrollXEnabled : true,
\r
90 scrollYEnabled : true,
\r
91 scrollEnabled : true,
\r
92 bounceEnabled : true,
\r
93 momentumEnabled : true,
\r
97 hasScrollShadow : true,
\r
98 scrollShadowColor : '#000',
\r
104 directionLocked : '',
\r
107 isInTransition : false,
\r
109 hasHScroll : false,
\r
110 hasVScroll : false,
\r
114 requestFrameID : 0,
\r
120 scrollXMax : 0, // px
\r
121 scrollYMax : 0, // px
\r
122 scrollXRatio : 0, // この値は scroll 不要になっても保持される。 scroll 必要時に参照される
\r
126 absStartX : 0, // px
\r
127 absStartY : 0, // px
\r
132 directionX : 0, // -1, 0, 1
\r
133 directionY : 0, // -1, 0, 1
\r
135 lastScrollWidth : 0,
\r
136 lastScrollHeight : 0,
\r
140 _containerNode : null,
\r
141 xnodeSlider : null,
\r
143 Constructor : function( user, layout, args ){
\r
144 this[ 'Super' ]( user, layout, args );
\r
145 this._containerNode = X_Pair_get( this.containerNode );
\r
146 this.xnodeSlider = this._containerNode.xnode[ 'className' ]( 'ScrollSlider' )[ 'listen' ]( X_EVENT_ANIME_END, this, X_UI_ScrollBox_onAnimeEnd );
\r
147 this.xnode[ 'className' ]( 'ScrollBox' );
\r
150 creationComplete : function(){
\r
151 XUI_Box.prototype.creationComplete.apply( this, arguments );
\r
154 calculate : function(){
\r
155 this.lastScrollWidth = this._containerNode.boxWidth;
\r
156 this.lastScrollHeight = this._containerNode.boxHeight;
\r
157 this.lastBoxWidth = this.boxWidth;
\r
158 this.lastBoxHeight = this.boxHeight;
\r
160 XUI_Box.prototype.calculate.apply( this, arguments );
\r
162 // TODO root の layout_complete 後に。
\r
163 // TODO calculate 前に scroll の解放。
\r
166 this.lastScrollWidth !== this._containerNode.boxWidth ||
\r
167 this.lastScrollHeight !== this._containerNode.boxHeight ||
\r
168 this.lastBoxWidth !== this.boxWidth || this.lastBoxHeight !== this.boxHeight
\r
170 console.log( 'scroll - calc' );
\r
171 XUI_rootData[ 'listenOnce' ]( XUI_Event.LAYOUT_COMPLETE, this, X_UI_ScrollBox_onLayoutComplete );
\r
175 scrollTo : function( x, y, opt_time, opt_easing, opt_release ){
\r
176 //if( this.scrollX === x && this.scrollY === y ) return;
\r
178 opt_time = 0 <= opt_time ? opt_time : 0;
\r
179 opt_easing = opt_easing || 'circular';
\r
180 opt_release = 0 <= opt_release ? opt_release : 300;
\r
182 this.isInTransition = 0 < opt_time;
\r
184 X_UI_ScrollBox_translate( this, x, y, opt_time, opt_easing, opt_release );
\r
187 _remove : function(){
\r
188 XUI_AbstractUINode.prototype._remove.apply( this, arguments );
\r
190 if( this.scrolling ){
\r
192 this[ 'unlisten' ]( XUI_Event._POINTER_DOWN, X_UI_ScrollBox_onStart )
\r
193 [ 'unlisten' ]( XUI_Event.DRAG, X_UI_ScrollBox_onMove )
\r
194 [ 'unlisten' ]( XUI_Event.DRAG_END, X_UI_ScrollBox_onEnd );
\r
195 XUI_rootData[ 'unlisten' ]( XUI_Event.LAYOUT_BEFORE, this, X_UI_ScrollBox_onLayoutBefore );
\r
197 XUI_rootData[ 'unlisten' ]( XUI_Event.LAYOUT_COMPLETE, this, X_UI_ScrollBox_onLayoutComplete );
\r
198 this[ 'unlisten' ]( XUI_Event.SCROLL_END, XUI_rootData, XUI_rootData.calculate );
\r
200 this.xnodeSlider[ 'stop' ]();
\r
207 function X_UI_ScrollBox_onLayoutBefore( e ){
\r
208 if( e[ 'cancelable' ] && this.isInTransition && X_Node_Anime_translateZ ){
\r
209 this[ 'listenOnce' ]( XUI_Event.SCROLL_END, XUI_rootData, XUI_rootData.calculate );
\r
210 return X_CALLBACK_PREVENT_DEFAULT;
\r
212 this.scrollXRatio = this.scrollX / this.scrollXMax;
\r
213 this.scrollYRatio = this.scrollY / this.scrollYMax;
\r
214 this.xnodeSlider[ 'stop' ]();
\r
215 this.isInTransition = false;
\r
216 return X_CALLBACK_NONE;
\r
219 function X_UI_ScrollBox_onLayoutComplete( e ){
\r
220 // scroll の停止、GPU の解除
\r
221 var font = this.fontSize = this.xnodeSlider[ 'call' ]( 'fontSize' );
\r
223 this.scrollXMax = ( this.boxWidth - this._containerNode.boxWidth ) * font | 0;
\r
224 this.scrollYMax = ( this.boxHeight - this._containerNode.boxHeight ) * font | 0;
\r
226 this.hasHScroll = this.scrollXEnabled && ( this.scrollXMax < -1 ); // < 0 だと
\r
227 this.hasVScroll = this.scrollYEnabled && ( this.scrollYMax < -1 );
\r
229 if( !this.hasHScroll ){
\r
230 this.scrollXMax = 0;
\r
233 if( !this.hasVScroll ){
\r
234 this.scrollYMax = 0;
\r
237 delete this.endTime;
\r
238 delete this.directionX;
\r
239 delete this.directionY;
\r
241 X_UI_ScrollBox_resetPosition( this, 0 );
\r
243 if( this.hasHScroll || this.hasVScroll ){
\r
245 if( this.scrolling ){
\r
246 X_UI_ScrollBox_translate( this, this.scrollXMax * this.scrollXRatio, this.scrollYMax * this.scrollYRatio, 100, '', 300 );
\r
249 this[ 'listen' ]( XUI_Event._POINTER_DOWN, X_UI_ScrollBox_onStart )
\r
250 [ 'listen' ]( XUI_Event.DRAG, X_UI_ScrollBox_onMove )
\r
251 [ 'listen' ]( XUI_Event.DRAG_END, X_UI_ScrollBox_onEnd );
\r
252 XUI_rootData[ 'listen' ]( XUI_Event.LAYOUT_BEFORE, this, X_UI_ScrollBox_onLayoutBefore );
\r
254 X_UI_ScrollBox_translate( this, this.scrollXMax * this.scrollXRatio, this.scrollYMax * this.scrollYRatio, 100, '', 300 );
\r
255 this.scrolling = true;
\r
259 if( this.scrolling ){
\r
261 this[ 'unlisten' ]( XUI_Event._POINTER_DOWN, X_UI_ScrollBox_onStart )
\r
262 [ 'unlisten' ]( XUI_Event.DRAG, X_UI_ScrollBox_onMove )
\r
263 [ 'unlisten' ]( XUI_Event.DRAG_END, X_UI_ScrollBox_onEnd );
\r
264 XUI_rootData[ 'unlisten' ]( XUI_Event.LAYOUT_BEFORE, this, X_UI_ScrollBox_onLayoutBefore );
\r
266 ( this.scrollX !== 0 || this.scrollY !== 0 ) && X_UI_ScrollBox_translate( this, 0, 0, 100, '', 300 );
\r
268 delete this.scrolling;
\r
269 delete this.scrollXRatio;
\r
270 delete this.scrollYRatio;
\r
274 // TODO use scrollLeft, scrollTop
\r
275 function X_UI_ScrollBox_translate( that, x, y, opt_time, opt_easing, opt_release ){
\r
276 var scrollBoxH = that.fontSize * that.boxHeight,
\r
277 scrollBoxW = that.fontSize * that.boxWidth,
\r
278 indicatorH, indicatorW;
\r
280 opt_time = 0 <= opt_time ? opt_time : 0;
\r
281 opt_easing = opt_easing === '' ? '' : opt_easing || 'circular';
\r
282 opt_release = 0 <= opt_release ? opt_release : 300;
\r
284 that.xnodeSlider[ 'animate' ](
\r
293 opt_time, opt_easing, opt_release
\r
296 if( X_UA[ 'IE' ] < 6 ){
\r
297 XUI_ScrollBox_indicatorV && XUI_ScrollBox_indicatorV[ 'css' ]( 'left', ( scrollBoxW - that.fontSize * 0.6 | 0 ) + 'px' );
\r
298 XUI_ScrollBox_indicatorH && XUI_ScrollBox_indicatorH[ 'css' ]( 'top' , ( scrollBoxH - that.fontSize * 0.6 | 0 ) + 'px' );
\r
301 if( that.hasVScroll && XUI_ScrollBox_indicatorV ){
\r
302 indicatorH = scrollBoxH * scrollBoxH / ( - that.scrollYMax + scrollBoxH );
\r
303 scrollBoxH -= indicatorH;
\r
305 XUI_ScrollBox_indicatorV
\r
307 height : ( indicatorH | 0 ) + 'px'
\r
311 y : scrollBoxH * that.scrollY / that.scrollYMax
\r
314 y : scrollBoxH * y / that.scrollYMax,
\r
317 opt_time, opt_easing, opt_release
\r
320 if( that.hasHScroll && XUI_ScrollBox_indicatorH ){
\r
321 indicatorW = scrollBoxW * scrollBoxW / ( - that.scrollXMax + scrollBoxW );
\r
322 scrollBoxW -= indicatorW;
\r
323 XUI_ScrollBox_indicatorH
\r
325 width : ( indicatorW | 0 ) + 'px'
\r
329 x : scrollBoxW * that.scrollX / that.scrollXMax
\r
332 x : scrollBoxW * x / that.scrollXMax,
\r
335 opt_time, opt_easing, opt_release
\r
340 that.scrollXEm = x / that.fontSize;
\r
342 that.scrollYEm = y / that.fontSize;
\r
345 function X_UI_ScrollBox_onStart( e ){
\r
346 var ret = X_CALLBACK_NONE;
\r
348 if( !this.scrollEnabled || ( this.initiated && e.pointerType !== this.initiated ) ){
\r
352 this.initiated = e.pointerType;
\r
353 this.moved = false;
\r
356 this.directionX = 0;
\r
357 this.directionY = 0;
\r
358 this.directionLocked = '';
\r
359 this.startTime = X_Timer_now();
\r
362 if( this.isInTransition ){
\r
363 this.isInTransition = false;
\r
364 //console.log( '-1-' );
\r
365 this[ 'dispatch' ]( XUI_Event.SCROLL_END );
\r
367 this.xnodeSlider[ 'stop' ]();
\r
370 this.startX = this.scrollX;
\r
371 this.startY = this.scrollY;
\r
372 this.absStartX = this.scrollX;
\r
373 this.absStartY = this.scrollY;
\r
374 this.pointX = e.pageX;
\r
375 this.pointY = e.pageY;
\r
377 console.log( 'scrollstart ' + e.pageY + e.target.className() );
\r
379 return ret | X_CALLBACK_PREVENT_DEFAULT;
\r
382 function X_UI_ScrollBox_onMove( e ){
\r
383 var ret = X_CALLBACK_NONE,
\r
384 deltaX, deltaY, timestamp,
\r
386 absDistX, absDistY;
\r
387 // 規定以上の move でスクロール開始
\r
389 //console.log( 'scrollmove ' + e.buttons + ' ' + e.button );
\r
391 if( !this.scrollEnabled || e.pointerType !== this.initiated ){
\r
396 if( !this.xnodeSlider[ '_anime' ] ){
\r
397 //console.log( 'gpuレイヤーの用意 ' + e.pageY );
\r
398 //console.log( 'mov1 x:' + this.scrollX + ' y:' + this.scrollY );
\r
399 X_UI_ScrollBox_translate( this, this.scrollX, this.scrollY, 0, '', 300 );
\r
403 deltaX = e.pageX - this.pointX;
\r
404 deltaY = e.pageY - this.pointY;
\r
405 timestamp = X_Timer_now();
\r
407 this.pointX = e.pageX;
\r
408 this.pointY = e.pageY;
\r
410 this.distX += deltaX;
\r
411 this.distY += deltaY;
\r
412 absDistX = Math.abs(this.distX);
\r
413 absDistY = Math.abs(this.distY);
\r
415 // We need to move at least 10 pixels for the scrolling to initiate
\r
416 if( 300 < timestamp - this.endTime && ( absDistX < 10 && absDistY < 10 ) ){
\r
420 // If you are scrolling in one direction lock the other
\r
421 if( !this.directionLocked ){
\r
422 if( absDistX > absDistY + this.directionLockThreshold ){
\r
423 this.directionLocked = 'h'; // lock horizontally
\r
425 if( absDistY >= absDistX + this.directionLockThreshold ){
\r
426 this.directionLocked = 'v'; // lock vertically
\r
428 this.directionLocked = 'n'; // no lock
\r
432 if( this.directionLocked === 'h' ){
\r
435 if( this.directionLocked === 'v' ){
\r
439 deltaX = this.hasHScroll ? deltaX : 0;
\r
440 deltaY = this.hasVScroll ? deltaY : 0;
\r
443 this[ 'dispatch' ]( XUI_Event.SCROLL_BEFORE_MOVE );
\r
445 this.minusX = deltaX;
\r
446 this.minusY = deltaY;
\r
448 XUI_ScrollBox_start( this );
\r
450 this[ 'dispatch' ]( XUI_Event.SCROLL_MOVE );
\r
453 newX = this.scrollX + deltaX;// - this.minusX;
\r
454 newY = this.scrollY + deltaY;// - this.minusY;
\r
456 // Slow down if outside of the boundaries
\r
457 if( 0 < newX || newX < this.scrollXMax ){
\r
458 newX = this.bounceEnabled ? this.scrollX + ( deltaX ) / 3 : 0 < newX ? 0 : this.scrollXMax;
\r
461 if( 0 < newY || newY < this.scrollYMax ){
\r
462 //console.log( 'slow... ' + newY + ' ' + this.scrollYMax );
\r
463 newY = this.bounceEnabled ? this.scrollY + ( deltaY ) / 3 : 0 < newY ? 0 : this.scrollYMax;
\r
466 this.directionX = 0 < deltaX ? -1 : deltaX < 0 ? 1 : 0;
\r
467 this.directionY = 0 < deltaY ? -1 : deltaY < 0 ? 1 : 0;
\r
469 //console.log( 'mov2 x:' + newX + ' y:' + newY );
\r
470 X_UI_ScrollBox_translate( this, newX, newY, 0, '', 300 );
\r
472 if( 300 < timestamp - this.startTime ){
\r
473 this.startTime = timestamp;
\r
474 this.startX = this.scrollX;
\r
475 this.startY = this.scrollY;
\r
478 return ret | X_CALLBACK_PREVENT_DEFAULT | X_CALLBACK_CAPTURE_POINTER;
\r
481 function X_UI_ScrollBox_onEnd( e ){
\r
482 var ret = X_CALLBACK_NONE,
\r
486 momentumX, momentumY,
\r
487 duration, distanceX, distanceY;
\r
489 //console.log( e.type + ' onend ' + XUI_Event.POINTER_OUT );
\r
491 if( !this.scrollEnabled || e.pointerType !== this.initiated ){
\r
492 //console.log( e.type + ' onend 1 ' + e.pointerType + ' ' + this.initiated );
\r
496 delete this.isInTransition;
\r
497 delete this.initiated;
\r
498 this.endTime = X_Timer_now();
\r
500 duration = this.endTime - this.startTime;
\r
501 newX = Math.round( this.scrollX );
\r
502 newY = Math.round( this.scrollY );
\r
503 distanceX = Math.abs(newX - this.startX);
\r
504 distanceY = Math.abs(newY - this.startY);
\r
506 // reset if we are outside of the boundaries
\r
507 if( X_UI_ScrollBox_resetPosition( this, this.bounceTime ) ){
\r
508 //console.log( e.type + ' onend 2 ' + XUI_Event.POINTER_OUT );
\r
509 return ret | X_CALLBACK_PREVENT_DEFAULT | X_CALLBACK_RELEASE_POINTER;
\r
512 // we scrolled less than 10 pixels
\r
514 this[ 'dispatch' ]( X_EVENT_CANCELED );
\r
515 //console.log( 'we scrolled less than 10 pixels ' + e.pageY );
\r
516 return ret | X_CALLBACK_PREVENT_DEFAULT | X_CALLBACK_RELEASE_POINTER;
\r
519 // start momentum animation if needed
\r
520 if( this.momentumEnabled && duration < 300 ){
\r
521 momentumX = this.hasHScroll ?
\r
522 X_UI_ScrollBox_momentum( this.scrollX, this.startX, duration, this.scrollXMax, this.bounceEnabled ? this.boxWidth * this.fontSize : 0, this.deceleration ) :
\r
523 { destination: newX, duration: 0 };
\r
524 momentumY = this.hasVScroll ?
\r
525 X_UI_ScrollBox_momentum( this.scrollY, this.startY, duration, this.scrollYMax, this.bounceEnabled ? this.boxHeight * this.fontSize : 0, this.deceleration ) :
\r
526 { destination: newY, duration: 0 };
\r
527 newX = momentumX.destination;
\r
528 newY = momentumY.destination;
\r
529 time = Math.max( momentumX.duration, momentumY.duration ) | 0;
\r
530 this.isInTransition = true;
\r
532 //console.log( '慣性無し' );
\r
535 if( newX != this.scrollX || newY != this.scrollY ){
\r
536 // change easing function when scroller goes out of the boundaries
\r
537 if( 0 < newX || newX < this.scrollXMax || 0 < newY || newY < this.scrollYMax ){
\r
538 easing = 'quadratic';
\r
541 //console.log( 'end2 x:' + newX + ' y:' + newY + '<-y:' + this.scrollY + ' t:' + time );
\r
542 this.scrollTo( newX, newY, time, easing, 1000 );
\r
544 //console.log( 'end1 x:' + newX + ' y:' + newY );
\r
545 this.scrollTo( newX, newY, 0, '', 1000 ); // ensures that the last position is rounded
\r
546 //console.log( '-3-' );
\r
547 this[ 'dispatch' ]( XUI_Event.SCROLL_END );
\r
550 return ret | X_CALLBACK_PREVENT_DEFAULT | X_CALLBACK_RELEASE_POINTER;
\r
553 function X_UI_ScrollBox_resetPosition( that, time ){
\r
554 var x = that.scrollX,
\r
559 if( !that.hasHScroll || 0 < that.scrollX ){
\r
562 if( that.scrollX < that.scrollXMax ){
\r
563 x = that.scrollXMax;
\r
566 if( !that.hasVScroll || 0 < that.scrollY ){
\r
569 if( that.scrollY < that.scrollYMax ){
\r
570 y = that.scrollYMax;
\r
573 if( x === that.scrollX && y === that.scrollY ){
\r
574 //console.log( 'no バウンド y:' + y + ' max:' + that.scrollYMax );
\r
578 //console.log( ' ===> resetPosition - バウンド!' );
\r
579 //console.log( ' x:' + x + ' y:' + y );
\r
580 that.scrollTo( x, y, time, that.bounceEasing, 1000 );
\r
585 function X_UI_ScrollBox_onAnimeEnd( e ){
\r
586 if( e.target !== this.xnodeSlider ){
\r
587 console.log( '- not much -' );
\r
590 if( e.target === this.xnodeSlider && this.isInTransition && !X_UI_ScrollBox_resetPosition( this, this.bounceTime ) ){
\r
591 this.isInTransition = false;
\r
592 //console.log( '-2-' );
\r
593 this[ 'dispatch' ]( XUI_Event.SCROLL_END );
\r
595 //console.log(' -2.1- '+this.isInTransition );
\r
596 return X_CALLBACK_NONE;
\r
599 function X_UI_ScrollBox_momentum( current, start, time, lowerMargin, wrapperSize, deceleration ){
\r
600 var distance = current - start,
\r
601 speed = Math.abs( distance ) / time,
\r
605 deceleration = deceleration === undefined ? 0.0006 : deceleration;
\r
607 destination = current + ( speed * speed ) / ( 2 * deceleration ) * ( distance < 0 ? -1 : 1 );
\r
608 duration = speed / deceleration;
\r
610 if( destination < lowerMargin ){
\r
611 destination = wrapperSize ? lowerMargin - ( wrapperSize / 2.5 * ( speed / 8 ) ) : lowerMargin;
\r
612 distance = Math.abs( destination - current );
\r
613 duration = distance / speed;
\r
615 if ( destination > 0 ) {
\r
616 destination = wrapperSize ? wrapperSize / 2.5 * ( speed / 8 ) : 0;
\r
617 distance = Math.abs( current ) + destination;
\r
618 duration = distance / speed;
\r
622 destination : Math.round( destination ),
\r
623 duration : duration
\r
627 X.UI.ScrollBox = X.UI.ChromeBox.inherits(
\r
631 Constructor : function(){
\r
632 var supports, slider;
\r
634 if( XUI_ScrollBox.prototype.usableAttrs === XUI_ChromeBox.prototype.usableAttrs ){
\r
635 XUI_ScrollBox.prototype.usableAttrs = supports = XUI_Attr_createAttrDef( XUI_Attr_Support, X_UI_ScrollBox_SUPPORT_ATTRS );
\r
637 XUI_ScrollBox.prototype.attrClass = XUI_Attr_preset( XUI_Box.prototype.attrClass, supports, { width : '100%', height : '100%', bgColor : 0x111111 } );
\r
641 XUI_Layout_Vertical,
\r
643 name : 'ScrollBox-Scroller',
\r
644 role : 'container',
\r
651 l = arguments.length, i = 0, j = 1,
\r
654 for( ; i < l; ++i ){
\r
655 arg = arguments[ i ];
\r
656 if( arg[ 'instanceOf' ] && arg[ 'instanceOf' ]( XUI_LayoutBase ) ){
\r
659 if( arg[ 'instanceOf' ] && arg[ 'instanceOf' ]( X.UI.AbstractUINode ) ){
\r
662 if( X_Type_isObject( arg ) ){
\r
663 args[ ++j ] = attr = arg;
\r
664 slider = attr.scrollSlider;
\r
674 slider || X.UI.VBox.apply( 0, args )
\r
679 //attr && this.attr( attr );
\r
681 scrollX : function(){
\r
684 scrollY : function(){
\r
687 scrollWidth : function(){
\r
690 scrollHeight : function(){
\r
693 scrollTo : function( nodeOrX, y ){
\r