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( XUI_ScrollBox_current && XUI_ScrollBox_current !== scrollBox ){
\r
13 XUI_ScrollBox_indicatorV &&
\r
14 XUI_ScrollBox_current[ 'unlisten' ]( [ X_EVENT_CANCELED, XUI_Event.SCROLL_END ], XUI_ScrollBox_indicatorV, XUI_ScrollBox_indicatorHandleEvent );
\r
16 XUI_ScrollBox_indicatorH &&
\r
17 XUI_ScrollBox_current[ 'unlisten' ]( [ X_EVENT_CANCELED, XUI_Event.SCROLL_END ], XUI_ScrollBox_indicatorH, XUI_ScrollBox_indicatorHandleEvent );
\r
20 if( scrollBox && scrollBox.hasVScroll ){
\r
21 if( !XUI_ScrollBox_indicatorV ){
\r
22 XUI_ScrollBox_indicatorV = X_Doc_create( 'div' )[ 'className' ]( 'ScrollBox-IndicatorV' );
\r
24 if( scrollBox.xnode !== XUI_ScrollBox_indicatorV.parent ){
\r
25 console.log( '*** Scroll Indicator add ***' );
\r
26 scrollBox.xnode[ 'append' ]( XUI_ScrollBox_indicatorV );
\r
27 XUI_ScrollBox_indicatorV[ 'animate' ](
\r
30 900, 'circular', 300
\r
33 [ 'listen' ]( [ X_EVENT_CANCELED, XUI_Event.SCROLL_END ], XUI_ScrollBox_indicatorV, XUI_ScrollBox_indicatorHandleEvent );
\r
36 if( XUI_ScrollBox_indicatorV ){
\r
37 console.log( '*** Scroll Indicator remove ***' );
\r
38 XUI_ScrollBox_indicatorV[ 'remove' ]();
\r
41 if( scrollBox && scrollBox.hasHScroll ){
\r
42 if( !XUI_ScrollBox_indicatorH ){
\r
43 XUI_ScrollBox_indicatorH = X_Doc_create( 'div' )[ 'className' ]( 'ScrollBox-IndicatorH' );
\r
45 if( scrollBox.xnode !== XUI_ScrollBox_indicatorH.parent ){
\r
46 scrollBox.xnode[ 'append' ]( XUI_ScrollBox_indicatorH );
\r
47 XUI_ScrollBox_indicatorH[ 'animate' ](
\r
50 900, 'circular', 300
\r
53 [ 'listen' ]( [ X_EVENT_CANCELED, XUI_Event.SCROLL_END ], XUI_ScrollBox_indicatorH, XUI_ScrollBox_indicatorHandleEvent );
\r
56 if( XUI_ScrollBox_indicatorH ){
\r
57 XUI_ScrollBox_indicatorH[ 'remove' ]();
\r
60 XUI_ScrollBox_current = scrollBox;
\r
63 function XUI_ScrollBox_indicatorHandleEvent( e ){
\r
65 case X_EVENT_CANCELED :
\r
66 case XUI_Event.SCROLL_END :
\r
67 console.log( '-fadeout-' );
\r
71 900, 'circular', 300
\r
78 var X_UI_ScrollBox_SUPPORT_ATTRS = {
\r
79 // スクロール開始するために必要な移動距離、縦か横、どちらか制限する場合、より重要
\r
80 directionLockThreshold : [ 10, XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.LENGTH ],
\r
81 scrollXEnabled : [ true, XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.BOOLEAN ],
\r
82 scrollYEnabled : [ true, XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.BOOLEAN ],
\r
83 scrollEnabled : [ true, XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.BOOLEAN ],
\r
84 bounceEnabled : [ true, XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.BOOLEAN ],
\r
85 bounceTime : [ 300, XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.TIME ],
\r
86 useWheel : [ true, XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.BOOLEAN ],
\r
87 useKey : [ true, XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.BOOLEAN ],
\r
88 hasScrollShadow : [ true, XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.BOOLEAN ],
\r
89 scrollShadowColor : [ '#000', XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.COLOR ]
\r
92 var XUI_ScrollBox = XUI_ChromeBox.inherits(
\r
96 layout : XUI_Layout_Canvas,
\r
98 directionLockThreshold : 10,
\r
99 scrollXEnabled : true,
\r
100 scrollYEnabled : true,
\r
101 scrollEnabled : true,
\r
102 bounceEnabled : true,
\r
103 momentumEnabled : true,
\r
107 hasScrollShadow : true,
\r
108 scrollShadowColor : '#000',
\r
114 directionLocked : '',
\r
117 isInTransition : false,
\r
119 hasHScroll : false,
\r
120 hasVScroll : false,
\r
124 requestFrameID : 0,
\r
130 scrollXMax : 0, // px
\r
131 scrollYMax : 0, // px
\r
132 scrollXRatio : 0, // この値は scroll 不要になっても保持される。 scroll 必要時に参照される
\r
136 absStartX : 0, // px
\r
137 absStartY : 0, // px
\r
142 directionX : 0, // -1, 0, 1
\r
143 directionY : 0, // -1, 0, 1
\r
145 lastScrollWidth : 0,
\r
146 lastScrollHeight : 0,
\r
150 _containerNode : null,
\r
151 xnodeSlider : null,
\r
153 Constructor : function( user, layout, args ){
\r
154 this[ 'Super' ]( user, layout, args );
\r
155 this._containerNode = X_Pair_get( this.containerNode );
\r
156 this.xnodeSlider = this._containerNode.xnode[ 'className' ]( 'ScrollSlider' )[ 'listen' ]( X_EVENT_ANIME_END, this, X_UI_ScrollBox_onAnimeEnd );
\r
157 this.xnode[ 'className' ]( 'ScrollBox' );
\r
160 creationComplete : function(){
\r
161 XUI_Box.prototype.creationComplete.apply( this, arguments );
\r
164 calculate : function(){
\r
165 this.lastScrollWidth = this._containerNode.boxWidth;
\r
166 this.lastScrollHeight = this._containerNode.boxHeight;
\r
167 this.lastBoxWidth = this.boxWidth;
\r
168 this.lastBoxHeight = this.boxHeight;
\r
170 XUI_Box.prototype.calculate.apply( this, arguments );
\r
172 // TODO root の layout_complete 後に。
\r
173 // TODO calculate 前に scroll の解放。
\r
176 this.lastScrollWidth !== this._containerNode.boxWidth ||
\r
177 this.lastScrollHeight !== this._containerNode.boxHeight ||
\r
178 this.lastBoxWidth !== this.boxWidth || this.lastBoxHeight !== this.boxHeight
\r
180 console.log( 'scroll - calc' );
\r
181 XUI_rootData[ 'listenOnce' ]( XUI_Event.LAYOUT_COMPLETE, this, X_UI_ScrollBox_onLayoutComplete );
\r
185 scrollTo : function( x, y, opt_time, opt_easing, opt_release ){
\r
186 //if( this.scrollX === x && this.scrollY === y ) return;
\r
188 opt_time = 0 <= opt_time ? opt_time : 0;
\r
189 opt_easing = opt_easing || 'circular';
\r
190 opt_release = 0 <= opt_release ? opt_release : 300;
\r
192 this.isInTransition = 0 < opt_time;
\r
194 X_UI_ScrollBox_translate( this, x, y, opt_time, opt_easing, opt_release );
\r
197 _remove : function(){
\r
198 XUI_AbstractUINode.prototype._remove.apply( this, arguments );
\r
200 if( this.scrolling ){
\r
202 this[ 'unlisten' ]( XUI_Event._POINTER_DOWN, X_UI_ScrollBox_onStart )
\r
203 [ 'unlisten' ]( XUI_Event.DRAG, X_UI_ScrollBox_onMove )
\r
204 [ 'unlisten' ]( XUI_Event.DRAG_END, X_UI_ScrollBox_onEnd );
\r
205 XUI_rootData[ 'unlisten' ]( XUI_Event.LAYOUT_BEFORE, this, X_UI_ScrollBox_onLayoutBefore );
\r
207 XUI_rootData[ 'unlisten' ]( XUI_Event.LAYOUT_COMPLETE, this, X_UI_ScrollBox_onLayoutComplete );
\r
208 this[ 'unlisten' ]( XUI_Event.SCROLL_END, XUI_rootData, XUI_rootData.calculate );
\r
210 this.xnodeSlider[ 'stop' ]();
\r
212 XUI_ScrollBox_current === this && XUI_ScrollBox_start( null );
\r
214 this.scrolling = false;
\r
221 function X_UI_ScrollBox_onLayoutBefore( e ){
\r
222 if( e[ 'cancelable' ] && this.isInTransition && X_NodeAnime_translateZ ){
\r
223 this[ 'listenOnce' ]( XUI_Event.SCROLL_END, XUI_rootData, XUI_rootData.calculate );
\r
224 return X_CALLBACK_PREVENT_DEFAULT;
\r
226 this.scrollXRatio = this.scrollX / this.scrollXMax;
\r
227 this.scrollYRatio = this.scrollY / this.scrollYMax;
\r
228 this.xnodeSlider[ 'stop' ]();
\r
229 this.isInTransition = false;
\r
230 return X_CALLBACK_NONE;
\r
233 function X_UI_ScrollBox_onLayoutComplete( e ){
\r
234 // scroll の停止、GPU の解除
\r
235 var font = this.fontSize = this.xnodeSlider[ 'call' ]( 'fontSize' );
\r
237 this.scrollXMax = ( this.boxWidth - this._containerNode.boxWidth ) * font | 0;
\r
238 this.scrollYMax = ( this.boxHeight - this._containerNode.boxHeight ) * font | 0;
\r
240 this.hasHScroll = this.scrollXEnabled && ( this.scrollXMax < -1 ); // < 0 だと
\r
241 this.hasVScroll = this.scrollYEnabled && ( this.scrollYMax < -1 );
\r
243 if( !this.hasHScroll ){
\r
244 this.scrollXMax = 0;
\r
247 if( !this.hasVScroll ){
\r
248 this.scrollYMax = 0;
\r
251 delete this.endTime;
\r
252 delete this.directionX;
\r
253 delete this.directionY;
\r
255 X_UI_ScrollBox_resetPosition( this, 0 );
\r
257 if( this.hasHScroll || this.hasVScroll ){
\r
259 if( this.scrolling ){
\r
260 X_UI_ScrollBox_translate( this, this.scrollXMax * this.scrollXRatio, this.scrollYMax * this.scrollYRatio, 100, '', 300 );
\r
263 this[ 'listen' ]( XUI_Event._POINTER_DOWN, X_UI_ScrollBox_onStart )
\r
264 [ 'listen' ]( XUI_Event.DRAG, X_UI_ScrollBox_onMove )
\r
265 [ 'listen' ]( XUI_Event.DRAG_END, X_UI_ScrollBox_onEnd );
\r
266 XUI_rootData[ 'listen' ]( XUI_Event.LAYOUT_BEFORE, this, X_UI_ScrollBox_onLayoutBefore );
\r
268 X_UI_ScrollBox_translate( this, this.scrollXMax * this.scrollXRatio, this.scrollYMax * this.scrollYRatio, 100, '', 300 );
\r
269 this.scrolling = true;
\r
273 if( this.scrolling ){
\r
275 this[ 'unlisten' ]( XUI_Event._POINTER_DOWN, X_UI_ScrollBox_onStart )
\r
276 [ 'unlisten' ]( XUI_Event.DRAG, X_UI_ScrollBox_onMove )
\r
277 [ 'unlisten' ]( XUI_Event.DRAG_END, X_UI_ScrollBox_onEnd );
\r
278 XUI_rootData[ 'unlisten' ]( XUI_Event.LAYOUT_BEFORE, this, X_UI_ScrollBox_onLayoutBefore );
\r
280 ( this.scrollX !== 0 || this.scrollY !== 0 ) && X_UI_ScrollBox_translate( this, 0, 0, 100, '', 300 );
\r
282 delete this.scrolling;
\r
283 delete this.scrollXRatio;
\r
284 delete this.scrollYRatio;
\r
288 // TODO use scrollLeft, scrollTop
\r
289 function X_UI_ScrollBox_translate( that, x, y, opt_time, opt_easing, opt_release ){
\r
290 var scrollBoxH = that.fontSize * that.boxHeight,
\r
291 scrollBoxW = that.fontSize * that.boxWidth,
\r
292 indicatorH, indicatorW;
\r
294 opt_time = 0 <= opt_time ? opt_time : 0;
\r
295 opt_easing = opt_easing === '' ? '' : opt_easing || 'circular';
\r
296 opt_release = 0 <= opt_release ? opt_release : 300;
\r
298 that.xnodeSlider[ 'animate' ](
\r
307 opt_time, opt_easing, opt_release
\r
310 if( X_UA[ 'IE' ] < 6 ){
\r
311 XUI_ScrollBox_indicatorV && XUI_ScrollBox_indicatorV[ 'css' ]( 'left', ( scrollBoxW - that.fontSize * 0.6 | 0 ) + 'px' );
\r
312 XUI_ScrollBox_indicatorH && XUI_ScrollBox_indicatorH[ 'css' ]( 'top' , ( scrollBoxH - that.fontSize * 0.6 | 0 ) + 'px' );
\r
315 if( that.hasVScroll && XUI_ScrollBox_indicatorV && XUI_ScrollBox_indicatorV.parent === that.xnode ){
\r
316 indicatorH = scrollBoxH * scrollBoxH / ( - that.scrollYMax + scrollBoxH );
\r
317 scrollBoxH -= indicatorH;
\r
319 XUI_ScrollBox_indicatorV
\r
321 height : ( indicatorH | 0 ) + 'px'
\r
325 y : scrollBoxH * that.scrollY / that.scrollYMax
\r
328 y : scrollBoxH * y / that.scrollYMax,
\r
331 opt_time, opt_easing, opt_release
\r
334 if( that.hasHScroll && XUI_ScrollBox_indicatorH && XUI_ScrollBox_indicatorH.parent === that.xnode ){
\r
335 indicatorW = scrollBoxW * scrollBoxW / ( - that.scrollXMax + scrollBoxW );
\r
336 scrollBoxW -= indicatorW;
\r
337 XUI_ScrollBox_indicatorH
\r
339 width : ( indicatorW | 0 ) + 'px'
\r
343 x : scrollBoxW * that.scrollX / that.scrollXMax
\r
346 x : scrollBoxW * x / that.scrollXMax,
\r
349 opt_time, opt_easing, opt_release
\r
354 that.scrollXEm = x / that.fontSize;
\r
356 that.scrollYEm = y / that.fontSize;
\r
359 function X_UI_ScrollBox_onStart( e ){
\r
360 var ret = X_CALLBACK_NONE;
\r
362 if( !this.scrollEnabled || ( this.initiated && e.pointerType !== this.initiated ) ){
\r
366 this.initiated = e.pointerType;
\r
367 this.moved = false;
\r
370 this.directionX = 0;
\r
371 this.directionY = 0;
\r
372 this.directionLocked = '';
\r
373 this.startTime = X_Timer_now();
\r
376 if( this.isInTransition ){
\r
377 this.isInTransition = false;
\r
378 //console.log( '-1-' );
\r
379 this[ 'dispatch' ]( XUI_Event.SCROLL_END );
\r
381 this.xnodeSlider[ 'stop' ]();
\r
384 this.startX = this.scrollX;
\r
385 this.startY = this.scrollY;
\r
386 this.absStartX = this.scrollX;
\r
387 this.absStartY = this.scrollY;
\r
388 this.pointX = e.pageX;
\r
389 this.pointY = e.pageY;
\r
391 console.log( 'scrollstart ' + e.pageY + e.target.className() );
\r
393 return ret | X_CALLBACK_PREVENT_DEFAULT;
\r
396 function X_UI_ScrollBox_onMove( e ){
\r
397 var ret = X_CALLBACK_NONE,
\r
398 deltaX, deltaY, timestamp,
\r
400 absDistX, absDistY;
\r
401 // 規定以上の move でスクロール開始
\r
403 //console.log( 'scrollmove ' + e.buttons + ' ' + e.button );
\r
405 if( !this.scrollEnabled || e.pointerType !== this.initiated ){
\r
410 if( !this.xnodeSlider[ '_anime' ] || !this.xnodeSlider[ '_anime' ].phase ){
\r
411 //console.log( 'gpuレイヤーの用意 ' + e.pageY );
\r
412 //console.log( 'mov1 x:' + this.scrollX + ' y:' + this.scrollY );
\r
413 X_UI_ScrollBox_translate( this, this.scrollX, this.scrollY, 0, '', 300 );
\r
417 deltaX = e.pageX - this.pointX;
\r
418 deltaY = e.pageY - this.pointY;
\r
419 timestamp = X_Timer_now();
\r
421 this.pointX = e.pageX;
\r
422 this.pointY = e.pageY;
\r
424 this.distX += deltaX;
\r
425 this.distY += deltaY;
\r
426 absDistX = Math.abs(this.distX);
\r
427 absDistY = Math.abs(this.distY);
\r
429 // We need to move at least 10 pixels for the scrolling to initiate
\r
430 if( 300 < timestamp - this.endTime && ( absDistX < 10 && absDistY < 10 ) ){
\r
434 // If you are scrolling in one direction lock the other
\r
435 if( !this.directionLocked ){
\r
436 if( absDistX > absDistY + this.directionLockThreshold ){
\r
437 this.directionLocked = 'h'; // lock horizontally
\r
439 if( absDistY >= absDistX + this.directionLockThreshold ){
\r
440 this.directionLocked = 'v'; // lock vertically
\r
442 this.directionLocked = 'n'; // no lock
\r
446 if( this.directionLocked === 'h' ){
\r
449 if( this.directionLocked === 'v' ){
\r
453 deltaX = this.hasHScroll ? deltaX : 0;
\r
454 deltaY = this.hasVScroll ? deltaY : 0;
\r
457 this[ 'dispatch' ]( XUI_Event.SCROLL_BEFORE_MOVE );
\r
459 this.minusX = deltaX;
\r
460 this.minusY = deltaY;
\r
462 XUI_ScrollBox_start( this );
\r
464 this[ 'dispatch' ]( XUI_Event.SCROLL_MOVE );
\r
467 newX = this.scrollX + deltaX;// - this.minusX;
\r
468 newY = this.scrollY + deltaY;// - this.minusY;
\r
470 // Slow down if outside of the boundaries
\r
471 if( 0 < newX || newX < this.scrollXMax ){
\r
472 newX = this.bounceEnabled ? this.scrollX + ( deltaX ) / 3 : 0 < newX ? 0 : this.scrollXMax;
\r
475 if( 0 < newY || newY < this.scrollYMax ){
\r
476 //console.log( 'slow... ' + newY + ' ' + this.scrollYMax );
\r
477 newY = this.bounceEnabled ? this.scrollY + ( deltaY ) / 3 : 0 < newY ? 0 : this.scrollYMax;
\r
480 this.directionX = 0 < deltaX ? -1 : deltaX < 0 ? 1 : 0;
\r
481 this.directionY = 0 < deltaY ? -1 : deltaY < 0 ? 1 : 0;
\r
483 //console.log( 'mov2 x:' + newX + ' y:' + newY );
\r
484 X_UI_ScrollBox_translate( this, newX, newY, 0, '', 300 );
\r
486 if( 300 < timestamp - this.startTime ){
\r
487 this.startTime = timestamp;
\r
488 this.startX = this.scrollX;
\r
489 this.startY = this.scrollY;
\r
492 return ret | X_CALLBACK_PREVENT_DEFAULT | X_CALLBACK_CAPTURE_POINTER;
\r
495 function X_UI_ScrollBox_onEnd( e ){
\r
496 var ret = X_CALLBACK_NONE,
\r
500 momentumX, momentumY,
\r
501 duration, distanceX, distanceY;
\r
503 //console.log( e.type + ' onend ' + XUI_Event.POINTER_OUT );
\r
505 if( !this.scrollEnabled || e.pointerType !== this.initiated ){
\r
506 //console.log( e.type + ' onend 1 ' + e.pointerType + ' ' + this.initiated );
\r
510 delete this.isInTransition;
\r
511 delete this.initiated;
\r
512 this.endTime = X_Timer_now();
\r
514 duration = this.endTime - this.startTime;
\r
515 newX = Math.round( this.scrollX );
\r
516 newY = Math.round( this.scrollY );
\r
517 distanceX = Math.abs(newX - this.startX);
\r
518 distanceY = Math.abs(newY - this.startY);
\r
520 // reset if we are outside of the boundaries
\r
521 if( X_UI_ScrollBox_resetPosition( this, this.bounceTime ) ){
\r
522 //console.log( e.type + ' onend 2 ' + XUI_Event.POINTER_OUT );
\r
523 return ret | X_CALLBACK_PREVENT_DEFAULT | X_CALLBACK_RELEASE_POINTER;
\r
526 // we scrolled less than 10 pixels
\r
528 this[ 'dispatch' ]( X_EVENT_CANCELED );
\r
529 //console.log( 'we scrolled less than 10 pixels ' + e.pageY );
\r
530 return ret | X_CALLBACK_PREVENT_DEFAULT | X_CALLBACK_RELEASE_POINTER;
\r
533 // start momentum animation if needed
\r
534 if( this.momentumEnabled && duration < 300 ){
\r
535 momentumX = this.hasHScroll ?
\r
536 X_UI_ScrollBox_momentum( this.scrollX, this.startX, duration, this.scrollXMax, this.bounceEnabled ? this.boxWidth * this.fontSize : 0, this.deceleration ) :
\r
537 { destination: newX, duration: 0 };
\r
538 momentumY = this.hasVScroll ?
\r
539 X_UI_ScrollBox_momentum( this.scrollY, this.startY, duration, this.scrollYMax, this.bounceEnabled ? this.boxHeight * this.fontSize : 0, this.deceleration ) :
\r
540 { destination: newY, duration: 0 };
\r
541 newX = momentumX.destination;
\r
542 newY = momentumY.destination;
\r
543 time = Math.max( momentumX.duration, momentumY.duration ) | 0;
\r
544 this.isInTransition = true;
\r
546 //console.log( '慣性無し' );
\r
549 if( newX != this.scrollX || newY != this.scrollY ){
\r
550 // change easing function when scroller goes out of the boundaries
\r
551 if( 0 < newX || newX < this.scrollXMax || 0 < newY || newY < this.scrollYMax ){
\r
552 easing = 'quadratic';
\r
555 //console.log( 'end2 x:' + newX + ' y:' + newY + '<-y:' + this.scrollY + ' t:' + time );
\r
556 this.scrollTo( newX, newY, time, easing, 1000 );
\r
558 //console.log( 'end1 x:' + newX + ' y:' + newY );
\r
559 this.scrollTo( newX, newY, 0, '', 1000 ); // ensures that the last position is rounded
\r
560 //console.log( '-3-' );
\r
561 this[ 'dispatch' ]( XUI_Event.SCROLL_END );
\r
564 return ret | X_CALLBACK_PREVENT_DEFAULT | X_CALLBACK_RELEASE_POINTER;
\r
567 function X_UI_ScrollBox_resetPosition( that, time ){
\r
568 var x = that.scrollX,
\r
573 if( !that.hasHScroll || 0 < that.scrollX ){
\r
576 if( that.scrollX < that.scrollXMax ){
\r
577 x = that.scrollXMax;
\r
580 if( !that.hasVScroll || 0 < that.scrollY ){
\r
583 if( that.scrollY < that.scrollYMax ){
\r
584 y = that.scrollYMax;
\r
587 if( x === that.scrollX && y === that.scrollY ){
\r
588 //console.log( 'no バウンド y:' + y + ' max:' + that.scrollYMax );
\r
592 //console.log( ' ===> resetPosition - バウンド!' );
\r
593 //console.log( ' x:' + x + ' y:' + y );
\r
594 that.scrollTo( x, y, time, that.bounceEasing, 1000 );
\r
599 function X_UI_ScrollBox_onAnimeEnd( e ){
\r
600 if( e.target !== this.xnodeSlider ){
\r
601 console.log( '- not much -' );
\r
604 if( e.target === this.xnodeSlider && this.isInTransition && !X_UI_ScrollBox_resetPosition( this, this.bounceTime ) ){
\r
605 this.isInTransition = false;
\r
606 //console.log( '-2-' );
\r
607 this[ 'dispatch' ]( XUI_Event.SCROLL_END );
\r
609 //console.log(' -2.1- '+this.isInTransition );
\r
610 return X_CALLBACK_NONE;
\r
613 function X_UI_ScrollBox_momentum( current, start, time, lowerMargin, wrapperSize, deceleration ){
\r
614 var distance = current - start,
\r
615 speed = Math.abs( distance ) / time,
\r
619 deceleration = deceleration === undefined ? 0.0006 : deceleration;
\r
621 destination = current + ( speed * speed ) / ( 2 * deceleration ) * ( distance < 0 ? -1 : 1 );
\r
622 duration = speed / deceleration;
\r
624 if( destination < lowerMargin ){
\r
625 destination = wrapperSize ? lowerMargin - ( wrapperSize / 2.5 * ( speed / 8 ) ) : lowerMargin;
\r
626 distance = Math.abs( destination - current );
\r
627 duration = distance / speed;
\r
629 if ( destination > 0 ) {
\r
630 destination = wrapperSize ? wrapperSize / 2.5 * ( speed / 8 ) : 0;
\r
631 distance = Math.abs( current ) + destination;
\r
632 duration = distance / speed;
\r
636 destination : Math.round( destination ),
\r
637 duration : duration
\r
641 X.UI.ScrollBox = X.UI.ChromeBox.inherits(
\r
645 Constructor : function(){
\r
646 var supports, slider;
\r
648 if( XUI_ScrollBox.prototype.usableAttrs === XUI_ChromeBox.prototype.usableAttrs ){
\r
649 XUI_ScrollBox.prototype.usableAttrs = supports = XUI_Attr_createAttrDef( XUI_Attr_Support, X_UI_ScrollBox_SUPPORT_ATTRS );
\r
651 XUI_ScrollBox.prototype.attrClass = XUI_Attr_preset( XUI_Box.prototype.attrClass, supports, { width : '100%', height : '100%', bgColor : 0x111111 } );
\r
655 XUI_Layout_Vertical,
\r
657 name : 'ScrollBox-Scroller',
\r
658 role : 'container',
\r
665 l = arguments.length, i = 0, j = 1,
\r
668 for( ; i < l; ++i ){
\r
669 arg = arguments[ i ];
\r
670 if( arg[ 'instanceOf' ] && arg[ 'instanceOf' ]( XUI_LayoutBase ) ){
\r
673 if( arg[ 'instanceOf' ] && arg[ 'instanceOf' ]( X.UI.AbstractUINode ) ){
\r
676 if( X_Type_isObject( arg ) ){
\r
677 args[ ++j ] = attr = arg;
\r
678 slider = attr.scrollSlider;
\r
688 slider || X.UI.VBox.apply( 0, args )
\r
693 //attr && this.attr( attr );
\r
695 scrollX : function(){
\r
698 scrollY : function(){
\r
701 scrollWidth : function(){
\r
704 scrollHeight : function(){
\r
707 scrollTo : function( nodeOrX, y ){
\r