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
28 'from' : { opacity : 0 },
\r
29 'to' : { opacity : 0.5 },
\r
31 'easing' : 'circular',
\r
35 [ 'listen' ]( [ X_EVENT_CANCELED, XUI_Event.SCROLL_END ], XUI_ScrollBox_indicatorV, XUI_ScrollBox_indicatorHandleEvent );
\r
38 if( XUI_ScrollBox_indicatorV ){
\r
39 console.log( '*** Scroll Indicator remove ***' );
\r
40 XUI_ScrollBox_indicatorV[ 'remove' ]();
\r
43 if( scrollBox && scrollBox.hasHScroll ){
\r
44 if( !XUI_ScrollBox_indicatorH ){
\r
45 XUI_ScrollBox_indicatorH = X_Doc_create( 'div' )[ 'className' ]( 'ScrollBox-IndicatorH' );
\r
47 if( scrollBox.xnode !== XUI_ScrollBox_indicatorH.parent ){
\r
48 scrollBox.xnode[ 'append' ]( XUI_ScrollBox_indicatorH );
\r
49 XUI_ScrollBox_indicatorH[ 'animate' ]({
\r
50 'from' : { opacity : 0 },
\r
51 'to' : { opacity : 0.5 },
\r
53 'easing' : 'circular',
\r
57 [ 'listen' ]( [ X_EVENT_CANCELED, XUI_Event.SCROLL_END ], XUI_ScrollBox_indicatorH, XUI_ScrollBox_indicatorHandleEvent );
\r
60 if( XUI_ScrollBox_indicatorH ){
\r
61 XUI_ScrollBox_indicatorH[ 'remove' ]();
\r
64 XUI_ScrollBox_current = scrollBox;
\r
67 function XUI_ScrollBox_indicatorHandleEvent( e ){
\r
69 case X_EVENT_CANCELED :
\r
70 case XUI_Event.SCROLL_END :
\r
71 console.log( '-fadeout-' );
\r
73 'from' : { opacity : 0.5 },
\r
74 'to' : { opacity : 0 },
\r
76 'easing' : 'circular',
\r
84 var X_UI_ScrollBox_SUPPORT_ATTRS = {
\r
85 // スクロール開始するために必要な移動距離、縦か横、どちらか制限する場合、より重要
\r
86 directionLockThreshold : [ 10, XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.LENGTH ],
\r
87 scrollXEnabled : [ true, XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.BOOLEAN ],
\r
88 scrollYEnabled : [ true, XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.BOOLEAN ],
\r
89 scrollEnabled : [ true, XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.BOOLEAN ],
\r
90 bounceEnabled : [ true, XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.BOOLEAN ],
\r
91 bounceTime : [ 300, XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.TIME ],
\r
92 useWheel : [ true, XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.BOOLEAN ],
\r
93 useKey : [ true, XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.BOOLEAN ],
\r
94 hasScrollShadow : [ true, XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.BOOLEAN ],
\r
95 scrollShadowColor : [ '#000', XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.COLOR ]
\r
98 var XUI_ScrollBox = XUI_ChromeBox.inherits(
\r
102 layout : XUI_Layout_Canvas,
\r
104 directionLockThreshold : 10,
\r
105 scrollXEnabled : true,
\r
106 scrollYEnabled : true,
\r
107 scrollEnabled : true,
\r
108 bounceEnabled : true,
\r
109 momentumEnabled : true,
\r
113 hasScrollShadow : true,
\r
114 scrollShadowColor : '#000',
\r
120 directionLocked : '',
\r
123 isInTransition : false,
\r
125 hasHScroll : false,
\r
126 hasVScroll : false,
\r
130 requestFrameID : 0,
\r
136 scrollXMax : 0, // px
\r
137 scrollYMax : 0, // px
\r
138 scrollXRatio : 0, // この値は scroll 不要になっても保持される。 scroll 必要時に参照される
\r
142 absStartX : 0, // px
\r
143 absStartY : 0, // px
\r
148 directionX : 0, // -1, 0, 1
\r
149 directionY : 0, // -1, 0, 1
\r
151 lastScrollWidth : 0,
\r
152 lastScrollHeight : 0,
\r
156 _containerNode : null,
\r
157 xnodeSlider : null,
\r
159 Constructor : function( user, layout, args ){
\r
160 this[ 'Super' ]( user, layout, args );
\r
161 this._containerNode = X_Pair_get( this.containerNode );
\r
162 this.xnodeSlider = this._containerNode.xnode[ 'className' ]( 'ScrollSlider' )[ 'listen' ]( X_EVENT_ANIME_END, this, X_UI_ScrollBox_onAnimeEnd );
\r
163 this.xnode[ 'className' ]( 'ScrollBox' );
\r
166 creationComplete : function(){
\r
167 XUI_Box.prototype.creationComplete.apply( this, arguments );
\r
170 calculate : function(){
\r
171 this.lastScrollWidth = this._containerNode.boxWidth;
\r
172 this.lastScrollHeight = this._containerNode.boxHeight;
\r
173 this.lastBoxWidth = this.boxWidth;
\r
174 this.lastBoxHeight = this.boxHeight;
\r
176 XUI_Box.prototype.calculate.apply( this, arguments );
\r
178 // TODO root の layout_complete 後に。
\r
179 // TODO calculate 前に scroll の解放。
\r
182 this.lastScrollWidth !== this._containerNode.boxWidth ||
\r
183 this.lastScrollHeight !== this._containerNode.boxHeight ||
\r
184 this.lastBoxWidth !== this.boxWidth || this.lastBoxHeight !== this.boxHeight
\r
186 console.log( 'scroll - calc' );
\r
187 XUI_rootData[ 'listenOnce' ]( XUI_Event.LAYOUT_COMPLETE, this, X_UI_ScrollBox_onLayoutComplete );
\r
191 scrollTo : function( x, y, opt_time, opt_easing, opt_release ){
\r
192 //if( this.scrollX === x && this.scrollY === y ) return;
\r
194 opt_time = 0 <= opt_time ? opt_time : 0;
\r
195 opt_easing = opt_easing || 'circular';
\r
196 opt_release = 0 <= opt_release ? opt_release : 300;
\r
198 this.isInTransition = 0 < opt_time;
\r
200 X_UI_ScrollBox_translate( this, x, y, opt_time, opt_easing, opt_release );
\r
203 _remove : function(){
\r
204 XUI_AbstractUINode.prototype._remove.apply( this, arguments );
\r
206 if( this.scrolling ){
\r
208 this[ 'unlisten' ]( XUI_Event._POINTER_DOWN, X_UI_ScrollBox_onStart )
\r
209 [ 'unlisten' ]( XUI_Event.DRAG, X_UI_ScrollBox_onMove )
\r
210 [ 'unlisten' ]( XUI_Event.DRAG_END, X_UI_ScrollBox_onEnd );
\r
211 XUI_rootData[ 'unlisten' ]( XUI_Event.LAYOUT_BEFORE, this, X_UI_ScrollBox_onLayoutBefore );
\r
213 XUI_rootData[ 'unlisten' ]( XUI_Event.LAYOUT_COMPLETE, this, X_UI_ScrollBox_onLayoutComplete );
\r
214 this[ 'unlisten' ]( XUI_Event.SCROLL_END, XUI_rootData, XUI_rootData.calculate );
\r
216 this.xnodeSlider[ 'stop' ]();
\r
218 XUI_ScrollBox_current === this && XUI_ScrollBox_start( null );
\r
220 this.scrolling = false;
\r
227 function X_UI_ScrollBox_onLayoutBefore( e ){
\r
228 if( e[ 'cancelable' ] && this.isInTransition && X_NodeAnime_translateZ ){
\r
229 this[ 'listenOnce' ]( XUI_Event.SCROLL_END, XUI_rootData, XUI_rootData.calculate );
\r
230 return X_CALLBACK_PREVENT_DEFAULT;
\r
232 this.scrollXRatio = this.scrollX / this.scrollXMax;
\r
233 this.scrollYRatio = this.scrollY / this.scrollYMax;
\r
234 this.xnodeSlider[ 'stop' ]();
\r
235 this.isInTransition = false;
\r
236 return X_CALLBACK_NONE;
\r
239 function X_UI_ScrollBox_onLayoutComplete( e ){
\r
240 // scroll の停止、GPU の解除
\r
241 var font = this.fontSize = this.xnodeSlider[ 'call' ]( 'fontSize' );
\r
243 this.scrollXMax = ( this.boxWidth - this._containerNode.boxWidth ) * font | 0;
\r
244 this.scrollYMax = ( this.boxHeight - this._containerNode.boxHeight ) * font | 0;
\r
246 this.hasHScroll = this.scrollXEnabled && ( this.scrollXMax < -1 ); // < 0 だと
\r
247 this.hasVScroll = this.scrollYEnabled && ( this.scrollYMax < -1 );
\r
249 if( !this.hasHScroll ){
\r
250 this.scrollXMax = 0;
\r
253 if( !this.hasVScroll ){
\r
254 this.scrollYMax = 0;
\r
257 delete this.endTime;
\r
258 delete this.directionX;
\r
259 delete this.directionY;
\r
261 X_UI_ScrollBox_resetPosition( this, 0 );
\r
263 if( this.hasHScroll || this.hasVScroll ){
\r
265 if( this.scrolling ){
\r
266 X_UI_ScrollBox_translate( this, this.scrollXMax * this.scrollXRatio, this.scrollYMax * this.scrollYRatio, 100, '', 300 );
\r
269 this[ 'listen' ]( XUI_Event._POINTER_DOWN, X_UI_ScrollBox_onStart )
\r
270 [ 'listen' ]( XUI_Event.DRAG, X_UI_ScrollBox_onMove )
\r
271 [ 'listen' ]( XUI_Event.DRAG_END, X_UI_ScrollBox_onEnd );
\r
272 XUI_rootData[ 'listen' ]( XUI_Event.LAYOUT_BEFORE, this, X_UI_ScrollBox_onLayoutBefore );
\r
274 X_UI_ScrollBox_translate( this, this.scrollXMax * this.scrollXRatio, this.scrollYMax * this.scrollYRatio, 100, '', 300 );
\r
275 this.scrolling = true;
\r
279 if( this.scrolling ){
\r
281 this[ 'unlisten' ]( XUI_Event._POINTER_DOWN, X_UI_ScrollBox_onStart )
\r
282 [ 'unlisten' ]( XUI_Event.DRAG, X_UI_ScrollBox_onMove )
\r
283 [ 'unlisten' ]( XUI_Event.DRAG_END, X_UI_ScrollBox_onEnd );
\r
284 XUI_rootData[ 'unlisten' ]( XUI_Event.LAYOUT_BEFORE, this, X_UI_ScrollBox_onLayoutBefore );
\r
286 ( this.scrollX !== 0 || this.scrollY !== 0 ) && X_UI_ScrollBox_translate( this, 0, 0, 100, '', 300 );
\r
288 delete this.scrolling;
\r
289 delete this.scrollXRatio;
\r
290 delete this.scrollYRatio;
\r
294 // TODO use scrollLeft, scrollTop
\r
295 function X_UI_ScrollBox_translate( that, x, y, opt_time, opt_easing, opt_release ){
\r
296 var scrollBoxH = that.fontSize * that.boxHeight,
\r
297 scrollBoxW = that.fontSize * that.boxWidth,
\r
298 indicatorH, indicatorW;
\r
300 opt_time = 0 <= opt_time ? opt_time : 0;
\r
301 opt_easing = opt_easing === '' ? '' : opt_easing || 'circular';
\r
302 opt_release = 0 <= opt_release ? opt_release : 300;
\r
304 that.xnodeSlider[ 'animate' ]({
\r
313 'duration' : opt_time,
\r
314 'easing' : opt_easing,
\r
315 'lazyRelease' : opt_release
\r
318 if( X_UA[ 'IE' ] < 6 ){
\r
319 XUI_ScrollBox_indicatorV && XUI_ScrollBox_indicatorV[ 'css' ]( 'left', ( scrollBoxW - that.fontSize * 0.6 | 0 ) + 'px' );
\r
320 XUI_ScrollBox_indicatorH && XUI_ScrollBox_indicatorH[ 'css' ]( 'top' , ( scrollBoxH - that.fontSize * 0.6 | 0 ) + 'px' );
\r
323 if( that.hasVScroll && XUI_ScrollBox_indicatorV && XUI_ScrollBox_indicatorV.parent === that.xnode ){
\r
324 indicatorH = scrollBoxH * scrollBoxH / ( - that.scrollYMax + scrollBoxH );
\r
325 scrollBoxH -= indicatorH;
\r
327 XUI_ScrollBox_indicatorV
\r
329 height : ( indicatorH | 0 ) + 'px'
\r
333 y : scrollBoxH * that.scrollY / that.scrollYMax },
\r
335 y : scrollBoxH * y / that.scrollYMax,
\r
338 'duration' : opt_time,
\r
339 'easing' : opt_easing,
\r
340 'lazyRelease' : opt_release
\r
343 if( that.hasHScroll && XUI_ScrollBox_indicatorH && XUI_ScrollBox_indicatorH.parent === that.xnode ){
\r
344 indicatorW = scrollBoxW * scrollBoxW / ( - that.scrollXMax + scrollBoxW );
\r
345 scrollBoxW -= indicatorW;
\r
346 XUI_ScrollBox_indicatorH
\r
348 width : ( indicatorW | 0 ) + 'px'
\r
352 x : scrollBoxW * that.scrollX / that.scrollXMax },
\r
354 x : scrollBoxW * x / that.scrollXMax,
\r
357 'duration' : opt_time,
\r
358 'easing' : opt_easing,
\r
359 'lazyRelease' : opt_release
\r
364 that.scrollXEm = x / that.fontSize;
\r
366 that.scrollYEm = y / that.fontSize;
\r
369 function X_UI_ScrollBox_onStart( e ){
\r
370 var ret = X_CALLBACK_NONE;
\r
372 if( !this.scrollEnabled || ( this.initiated && e.pointerType !== this.initiated ) ){
\r
376 this.initiated = e.pointerType;
\r
377 this.moved = false;
\r
380 this.directionX = 0;
\r
381 this.directionY = 0;
\r
382 this.directionLocked = '';
\r
383 this.startTime = X_Timer_now();
\r
386 if( this.isInTransition ){
\r
387 this.isInTransition = false;
\r
388 //console.log( '-1-' );
\r
389 this[ 'dispatch' ]( XUI_Event.SCROLL_END );
\r
391 this.xnodeSlider[ 'stop' ]();
\r
394 this.startX = this.scrollX;
\r
395 this.startY = this.scrollY;
\r
396 this.absStartX = this.scrollX;
\r
397 this.absStartY = this.scrollY;
\r
398 this.pointX = e.pageX;
\r
399 this.pointY = e.pageY;
\r
401 console.log( 'scrollstart ' + e.pageY + e.target.className() );
\r
403 return ret | X_CALLBACK_PREVENT_DEFAULT;
\r
406 function X_UI_ScrollBox_onMove( e ){
\r
407 var ret = X_CALLBACK_NONE,
\r
408 deltaX, deltaY, timestamp,
\r
410 absDistX, absDistY;
\r
411 // 規定以上の move でスクロール開始
\r
413 //console.log( 'scrollmove ' + e.buttons + ' ' + e.button );
\r
415 if( !this.scrollEnabled || e.pointerType !== this.initiated ){
\r
420 if( !this.xnodeSlider[ '_anime' ] || !this.xnodeSlider[ '_anime' ].phase ){
\r
421 //console.log( 'gpuレイヤーの用意 ' + e.pageY );
\r
422 //console.log( 'mov1 x:' + this.scrollX + ' y:' + this.scrollY );
\r
423 X_UI_ScrollBox_translate( this, this.scrollX, this.scrollY, 0, '', 300 );
\r
427 deltaX = e.pageX - this.pointX;
\r
428 deltaY = e.pageY - this.pointY;
\r
429 timestamp = X_Timer_now();
\r
431 this.pointX = e.pageX;
\r
432 this.pointY = e.pageY;
\r
434 this.distX += deltaX;
\r
435 this.distY += deltaY;
\r
436 absDistX = Math.abs(this.distX);
\r
437 absDistY = Math.abs(this.distY);
\r
439 // We need to move at least 10 pixels for the scrolling to initiate
\r
440 if( 300 < timestamp - this.endTime && ( absDistX < 10 && absDistY < 10 ) ){
\r
444 // If you are scrolling in one direction lock the other
\r
445 if( !this.directionLocked ){
\r
446 if( absDistX > absDistY + this.directionLockThreshold ){
\r
447 this.directionLocked = 'h'; // lock horizontally
\r
449 if( absDistY >= absDistX + this.directionLockThreshold ){
\r
450 this.directionLocked = 'v'; // lock vertically
\r
452 this.directionLocked = 'n'; // no lock
\r
456 if( this.directionLocked === 'h' ){
\r
459 if( this.directionLocked === 'v' ){
\r
463 deltaX = this.hasHScroll ? deltaX : 0;
\r
464 deltaY = this.hasVScroll ? deltaY : 0;
\r
467 this[ 'dispatch' ]( XUI_Event.SCROLL_BEFORE_MOVE );
\r
469 this.minusX = deltaX;
\r
470 this.minusY = deltaY;
\r
472 XUI_ScrollBox_start( this );
\r
474 this[ 'dispatch' ]( XUI_Event.SCROLL_MOVE );
\r
477 newX = this.scrollX + deltaX;// - this.minusX;
\r
478 newY = this.scrollY + deltaY;// - this.minusY;
\r
480 // Slow down if outside of the boundaries
\r
481 if( 0 < newX || newX < this.scrollXMax ){
\r
482 newX = this.bounceEnabled ? this.scrollX + ( deltaX ) / 3 : 0 < newX ? 0 : this.scrollXMax;
\r
485 if( 0 < newY || newY < this.scrollYMax ){
\r
486 //console.log( 'slow... ' + newY + ' ' + this.scrollYMax );
\r
487 newY = this.bounceEnabled ? this.scrollY + ( deltaY ) / 3 : 0 < newY ? 0 : this.scrollYMax;
\r
490 this.directionX = 0 < deltaX ? -1 : deltaX < 0 ? 1 : 0;
\r
491 this.directionY = 0 < deltaY ? -1 : deltaY < 0 ? 1 : 0;
\r
493 //console.log( 'mov2 x:' + newX + ' y:' + newY );
\r
494 X_UI_ScrollBox_translate( this, newX, newY, 0, '', 300 );
\r
496 if( 300 < timestamp - this.startTime ){
\r
497 this.startTime = timestamp;
\r
498 this.startX = this.scrollX;
\r
499 this.startY = this.scrollY;
\r
502 return ret | X_CALLBACK_PREVENT_DEFAULT | X_CALLBACK_CAPTURE_POINTER;
\r
505 function X_UI_ScrollBox_onEnd( e ){
\r
506 var ret = X_CALLBACK_NONE,
\r
510 momentumX, momentumY,
\r
511 duration, distanceX, distanceY;
\r
513 //console.log( e.type + ' onend ' + XUI_Event.POINTER_OUT );
\r
515 if( !this.scrollEnabled || e.pointerType !== this.initiated ){
\r
516 //console.log( e.type + ' onend 1 ' + e.pointerType + ' ' + this.initiated );
\r
520 delete this.isInTransition;
\r
521 delete this.initiated;
\r
522 this.endTime = X_Timer_now();
\r
524 duration = this.endTime - this.startTime;
\r
525 newX = Math.round( this.scrollX );
\r
526 newY = Math.round( this.scrollY );
\r
527 distanceX = Math.abs(newX - this.startX);
\r
528 distanceY = Math.abs(newY - this.startY);
\r
530 // reset if we are outside of the boundaries
\r
531 if( X_UI_ScrollBox_resetPosition( this, this.bounceTime ) ){
\r
532 //console.log( e.type + ' onend 2 ' + XUI_Event.POINTER_OUT );
\r
533 return ret | X_CALLBACK_PREVENT_DEFAULT | X_CALLBACK_RELEASE_POINTER;
\r
536 // we scrolled less than 10 pixels
\r
538 this[ 'dispatch' ]( X_EVENT_CANCELED );
\r
539 //console.log( 'we scrolled less than 10 pixels ' + e.pageY );
\r
540 return ret | X_CALLBACK_PREVENT_DEFAULT | X_CALLBACK_RELEASE_POINTER;
\r
543 // start momentum animation if needed
\r
544 if( this.momentumEnabled && duration < 300 ){
\r
545 momentumX = this.hasHScroll ?
\r
546 X_UI_ScrollBox_momentum( this.scrollX, this.startX, duration, this.scrollXMax, this.bounceEnabled ? this.boxWidth * this.fontSize : 0, this.deceleration ) :
\r
547 { destination: newX, duration: 0 };
\r
548 momentumY = this.hasVScroll ?
\r
549 X_UI_ScrollBox_momentum( this.scrollY, this.startY, duration, this.scrollYMax, this.bounceEnabled ? this.boxHeight * this.fontSize : 0, this.deceleration ) :
\r
550 { destination: newY, duration: 0 };
\r
551 newX = momentumX.destination;
\r
552 newY = momentumY.destination;
\r
553 time = Math.max( momentumX.duration, momentumY.duration ) | 0;
\r
554 this.isInTransition = true;
\r
556 //console.log( '慣性無し' );
\r
559 if( newX != this.scrollX || newY != this.scrollY ){
\r
560 // change easing function when scroller goes out of the boundaries
\r
561 if( 0 < newX || newX < this.scrollXMax || 0 < newY || newY < this.scrollYMax ){
\r
562 easing = 'quadratic';
\r
565 //console.log( 'end2 x:' + newX + ' y:' + newY + '<-y:' + this.scrollY + ' t:' + time );
\r
566 this.scrollTo( newX, newY, time, easing, 1000 );
\r
568 //console.log( 'end1 x:' + newX + ' y:' + newY );
\r
569 this.scrollTo( newX, newY, 0, '', 1000 ); // ensures that the last position is rounded
\r
570 //console.log( '-3-' );
\r
571 this[ 'dispatch' ]( XUI_Event.SCROLL_END );
\r
574 return ret | X_CALLBACK_PREVENT_DEFAULT | X_CALLBACK_RELEASE_POINTER;
\r
577 function X_UI_ScrollBox_resetPosition( that, time ){
\r
578 var x = that.scrollX,
\r
583 if( !that.hasHScroll || 0 < that.scrollX ){
\r
586 if( that.scrollX < that.scrollXMax ){
\r
587 x = that.scrollXMax;
\r
590 if( !that.hasVScroll || 0 < that.scrollY ){
\r
593 if( that.scrollY < that.scrollYMax ){
\r
594 y = that.scrollYMax;
\r
597 if( x === that.scrollX && y === that.scrollY ){
\r
598 //console.log( 'no バウンド y:' + y + ' max:' + that.scrollYMax );
\r
602 //console.log( ' ===> resetPosition - バウンド!' );
\r
603 //console.log( ' x:' + x + ' y:' + y );
\r
604 that.scrollTo( x, y, time, that.bounceEasing, 1000 );
\r
609 function X_UI_ScrollBox_onAnimeEnd( e ){
\r
610 if( this.isInTransition && !X_UI_ScrollBox_resetPosition( this, this.bounceTime ) ){
\r
611 this.isInTransition = false;
\r
612 //console.log( '-2-' );
\r
613 this[ 'dispatch' ]( XUI_Event.SCROLL_END );
\r
615 //console.log(' -2.1- '+this.isInTransition );
\r
616 return X_CALLBACK_NONE;
\r
619 function X_UI_ScrollBox_momentum( current, start, time, lowerMargin, wrapperSize, deceleration ){
\r
620 var distance = current - start,
\r
621 speed = Math.abs( distance ) / time,
\r
625 deceleration = deceleration === undefined ? 0.0006 : deceleration;
\r
627 destination = current + ( speed * speed ) / ( 2 * deceleration ) * ( distance < 0 ? -1 : 1 );
\r
628 duration = speed / deceleration;
\r
630 if( destination < lowerMargin ){
\r
631 destination = wrapperSize ? lowerMargin - ( wrapperSize / 2.5 * ( speed / 8 ) ) : lowerMargin;
\r
632 distance = Math.abs( destination - current );
\r
633 duration = distance / speed;
\r
635 if ( destination > 0 ) {
\r
636 destination = wrapperSize ? wrapperSize / 2.5 * ( speed / 8 ) : 0;
\r
637 distance = Math.abs( current ) + destination;
\r
638 duration = distance / speed;
\r
642 destination : Math.round( destination ),
\r
643 duration : duration
\r
647 X.UI.ScrollBox = X.UI.ChromeBox.inherits(
\r
651 Constructor : function(){
\r
652 var supports, slider;
\r
654 if( XUI_ScrollBox.prototype.usableAttrs === XUI_ChromeBox.prototype.usableAttrs ){
\r
655 XUI_ScrollBox.prototype.usableAttrs = supports = XUI_Attr_createAttrDef( XUI_Attr_Support, X_UI_ScrollBox_SUPPORT_ATTRS );
\r
657 XUI_ScrollBox.prototype.attrClass = XUI_Attr_preset( XUI_Box.prototype.attrClass, supports, { width : '100%', height : '100%', bgColor : 0x111111 } );
\r
661 XUI_Layout_Vertical,
\r
663 name : 'ScrollBox-Scroller',
\r
664 role : 'container',
\r
671 l = arguments.length, i = 0, j = 1,
\r
674 for( ; i < l; ++i ){
\r
675 arg = arguments[ i ];
\r
676 if( arg[ 'instanceOf' ] && arg[ 'instanceOf' ]( XUI_LayoutBase ) ){
\r
679 if( arg[ 'instanceOf' ] && arg[ 'instanceOf' ]( X.UI.AbstractUINode ) ){
\r
682 if( X_Type_isObject( arg ) ){
\r
683 args[ ++j ] = attr = arg;
\r
684 slider = attr.scrollSlider;
\r
694 slider || X.UI.VBox.apply( 0, args )
\r
699 //attr && this.attr( attr );
\r
701 scrollX : function(){
\r
704 scrollY : function(){
\r
707 scrollWidth : function(){
\r
710 scrollHeight : function(){
\r
713 scrollTo : function( nodeOrX, y ){
\r