OSDN Git Service

Version 0.6.190, fix X.UI.ScrollBox & X.UI.Gesture.
[pettanr/clientJs.git] / 0.6.x / js / 20_ui / 15_ScrollBox.js
index 2d160a1..4948a7b 100644 (file)
@@ -131,7 +131,7 @@ var XUI_ScrollBox = XUI_ChromeBox.inherits(
                Constructor : function( user, layout, args ){\r
                        this[ 'Super' ]( user, layout, args );\r
                        this._containerNode = X_Pair_get( this.containerNode );\r
-                       this.xnodeSlider = this._containerNode.xnode[ 'className' ]( 'ScrollSlider' ).listen( X_EVENT_ANIME_END, this, X_UI_ScrollBox_onAnimeEnd );\r
+                       this.xnodeSlider = this._containerNode.xnode[ 'className' ]( 'ScrollSlider' )[ 'listen' ]( X_EVENT_ANIME_END, this, X_UI_ScrollBox_onAnimeEnd );\r
                        this.xnode[ 'className' ]( 'ScrollBox' );\r
                },\r
                \r
@@ -224,7 +224,11 @@ function X_UI_ScrollBox_onLayoutComplete( e ){
                        X_UI_ScrollBox_translate( this, this.scrollXMax * this.scrollXRatio, this.scrollYMax * this.scrollYRatio, 100, '', 300 );\r
                } else {\r
                        // scroller 作る\r
-                       this[ 'listen' ]( XUI_Event._POINTER_DOWN, this, X_UI_ScrollBox_onStart );\r
+                       // shadow の listen には this が必要!\r
+                       // TODO AbstractUI の listen が悪い!\r
+                       this[ 'listen' ]( XUI_Event._POINTER_DOWN, this, X_UI_ScrollBox_onStart )\r
+                               [ 'listen' ]( XUI_Event.DRAG, this, X_UI_ScrollBox_onMove );\r
+       this[ 'listen' ]( XUI_Event.DRAG_END, this, X_UI_ScrollBox_onEnd );\r
                        X_UI_rootData[ 'listen' ]( XUI_Event.LAYOUT_BEFORE, this, X_UI_ScrollBox_onLayoutBefore );\r
                        \r
                        X_UI_ScrollBox_translate( this, this.scrollXMax * this.scrollXRatio, this.scrollYMax * this.scrollYRatio, 100, '', 300 );\r
@@ -234,7 +238,9 @@ function X_UI_ScrollBox_onLayoutComplete( e ){
        // scroll 不要\r
        if( this.scrolling ){\r
                // scroller 削除\r
-               this[ 'unlisten' ]( XUI_Event._POINTER_DOWN, this, X_UI_ScrollBox_onStart );\r
+               this[ 'unlisten' ]( XUI_Event._POINTER_DOWN, this, X_UI_ScrollBox_onStart )\r
+                       [ 'unlisten' ]( XUI_Event.DRAG, this, X_UI_ScrollBox_onMove );\r
+       this[ 'unlisten' ]( XUI_Event.DRAG_END, this, X_UI_ScrollBox_onEnd );\r
                X_UI_rootData[ 'unlisten' ]( XUI_Event.LAYOUT_BEFORE, this, X_UI_ScrollBox_onLayoutBefore );\r
                \r
                ( this.scrollX !== 0 || this.scrollY !== 0 ) && X_UI_ScrollBox_translate( this, 0, 0, 100, '', 300 );\r
@@ -247,7 +253,9 @@ function X_UI_ScrollBox_onLayoutComplete( e ){
 \r
 // TODO use scrollLeft, scrollTop\r
 function X_UI_ScrollBox_translate( that, x, y, opt_time, opt_easing, opt_release ){\r
-       var scrollBoxSize, indicatorSize;\r
+       var scrollBoxH = that.fontSize * that.boxHeight,\r
+               scrollBoxW = that.fontSize * that.boxWidth,\r
+               indicatorH, indicatorW;\r
        \r
        opt_time    = 0 <= opt_time ? opt_time : 0;\r
        opt_easing  = opt_easing === '' ? '' : opt_easing || 'circular';\r
@@ -265,39 +273,43 @@ function X_UI_ScrollBox_translate( that, x, y, opt_time, opt_easing, opt_release
                opt_time, opt_easing, opt_release\r
        );\r
 \r
+       if( X_UA[ 'IE' ] < 6 ){\r
+               XUI_ScrollBox_indicatorV && XUI_ScrollBox_indicatorV[ 'css' ]( 'left', ( scrollBoxW - that.fontSize * 0.6 | 0 ) + 'px' );\r
+               XUI_ScrollBox_indicatorH && XUI_ScrollBox_indicatorH[ 'css' ]( 'top' , ( scrollBoxH - that.fontSize * 0.6 | 0 ) + 'px' );\r
+       };\r
+\r
        if( that.hasVScroll && XUI_ScrollBox_indicatorV ){\r
-               scrollBoxSize = that.fontSize * that.boxHeight;\r
-               indicatorSize = scrollBoxSize * scrollBoxSize / ( - that.scrollYMax + scrollBoxSize );\r
-               scrollBoxSize -= indicatorSize;\r
+               indicatorH = scrollBoxH * scrollBoxH / ( - that.scrollYMax + scrollBoxH );\r
+               scrollBoxH -= indicatorH;\r
+\r
                XUI_ScrollBox_indicatorV\r
                        [ 'css' ]({\r
-                               height : ( indicatorSize | 0 ) + 'px'\r
+                               height : ( indicatorH | 0 ) + 'px'\r
                        })\r
                        [ 'animate' ](\r
                        {\r
-                               y : scrollBoxSize * that.scrollY / that.scrollYMax\r
+                               y : scrollBoxH * that.scrollY / that.scrollYMax\r
                        },\r
                        {\r
-                               y : scrollBoxSize * y / that.scrollYMax,\r
+                               y : scrollBoxH * y / that.scrollYMax,\r
                                opacity : 1\r
                        },\r
                        opt_time, opt_easing, opt_release\r
                );\r
        };\r
        if( that.hasHScroll && XUI_ScrollBox_indicatorH ){\r
-               scrollBoxSize = that.fontSize * that.boxWidth;\r
-               indicatorSize = scrollBoxSize * scrollBoxSize / ( - that.scrollXMax + scrollBoxSize );\r
-               scrollBoxSize -= indicatorSize;\r
+               indicatorW = scrollBoxW * scrollBoxW / ( - that.scrollXMax + scrollBoxW );\r
+               scrollBoxW -= indicatorW;\r
                XUI_ScrollBox_indicatorH\r
                        [ 'css' ]({\r
-                               width : ( indicatorSize | 0 ) + 'px'\r
+                               width : ( indicatorW | 0 ) + 'px'\r
                        })\r
                        [ 'animate' ](\r
                        {\r
-                               x : scrollBoxSize * that.scrollX / that.scrollXMax\r
+                               x : scrollBoxW * that.scrollX / that.scrollXMax\r
                        },\r
                        {\r
-                               x : scrollBoxSize * x / that.scrollXMax,\r
+                               x : scrollBoxW * x / that.scrollXMax,\r
                                opacity : 1\r
                        },\r
                        opt_time, opt_easing, opt_release\r
@@ -310,11 +322,6 @@ function X_UI_ScrollBox_translate( that, x, y, opt_time, opt_easing, opt_release
 \r
 function X_UI_ScrollBox_onStart( e ){\r
        var ret = X_CALLBACK_NONE;\r
-\r
-       // React to left mouse button only\r
-       if( e.pointerType === 'mouse' && e.button !== 0 ){\r
-               return ret;\r
-       };\r
        \r
        if( !this.scrollEnabled || ( this.initiated && e.pointerType !== this.initiated ) ){\r
                return ret;\r
@@ -332,7 +339,7 @@ function X_UI_ScrollBox_onStart( e ){
        // スクロール中の停止\r
        if( this.isInTransition ){\r
                this.isInTransition = false;\r
-               console.log( '-1-' );\r
+               //console.log( '-1-' );\r
                this[ 'dispatch' ]( XUI_Event.SCROLL_END );\r
                // TODO current位置\r
                this.xnodeSlider[ 'stop' ]();\r
@@ -345,10 +352,7 @@ function X_UI_ScrollBox_onStart( e ){
        this.pointX    = e.pageX;\r
        this.pointY    = e.pageY;\r
        \r
-       console.log( 'scrollstart ' + e.pageY );\r
-       \r
-       this[ 'listen' ]( XUI_Event._POINTER_MOVE, this, X_UI_ScrollBox_onMove );\r
-       this[ 'listen' ]( [ XUI_Event._POINTER_UP, XUI_Event.POINTER_OUT, XUI_Event._POINTER_CANCEL ], this, X_UI_ScrollBox_onEnd );\r
+       console.log( 'scrollstart ' + e.pageY + e.target.className() );\r
 \r
        return ret | X_CALLBACK_PREVENT_DEFAULT;\r
 };\r
@@ -365,10 +369,6 @@ function X_UI_ScrollBox_onMove( e ){
        if( !this.scrollEnabled || e.pointerType !== this.initiated ){\r
                return ret;\r
        };\r
-       \r
-       if( e.buttons !== 1 ){\r
-               return X_UI_ScrollBox_onEnd.call( this, e );\r
-       };\r
 \r
        // gpu の用意\r
        if( !this.xnodeSlider[ '_anime' ] ){\r
@@ -464,13 +464,10 @@ function X_UI_ScrollBox_onEnd( e ){
                momentumX, momentumY,\r
                duration, distanceX, distanceY;\r
        \r
-       console.log( e.type + ' onend ' + XUI_Event.POINTER_OUT  );\r
-                                       \r
-       this[ 'unlisten' ]( XUI_Event._POINTER_MOVE, this, X_UI_ScrollBox_onMove );\r
-       this[ 'unlisten' ]( [ XUI_Event._POINTER_UP, XUI_Event.POINTER_OUT, XUI_Event._POINTER_CANCEL ], this, X_UI_ScrollBox_onEnd );\r
+       //console.log( e.type + ' onend ' + XUI_Event.POINTER_OUT  );\r
        \r
        if( !this.scrollEnabled || e.pointerType !== this.initiated ){\r
-               console.log( e.type + ' onend 1 ' + e.pointerType + ' ' + this.initiated  );\r
+               //console.log( e.type + ' onend 1 ' + e.pointerType + ' ' + this.initiated  );\r
                return ret;\r
        };\r
 \r
@@ -486,15 +483,15 @@ function X_UI_ScrollBox_onEnd( e ){
 \r
        // reset if we are outside of the boundaries\r
        if( X_UI_ScrollBox_resetPosition( this, this.bounceTime ) ){\r
-               console.log( e.type + ' onend 2 ' + XUI_Event.POINTER_OUT  );\r
-               return ret;\r
+               //console.log( e.type + ' onend 2 ' + XUI_Event.POINTER_OUT  );\r
+               return ret | X_CALLBACK_PREVENT_DEFAULT | X_CALLBACK_RELEASE_POINTER;\r
        };\r
 \r
        // we scrolled less than 10 pixels\r
        if( !this.moved ){\r
                this[ 'dispatch' ]( X_EVENT_CANCELED );\r
-               console.log( 'we scrolled less than 10 pixels ' + e.pageY );\r
-               return ret;\r
+               //console.log( 'we scrolled less than 10 pixels ' + e.pageY );\r
+               return ret | X_CALLBACK_PREVENT_DEFAULT | X_CALLBACK_RELEASE_POINTER;\r
        };\r
 \r
        // start momentum animation if needed\r
@@ -510,7 +507,7 @@ function X_UI_ScrollBox_onEnd( e ){
                time = Math.max( momentumX.duration, momentumY.duration ) | 0;\r
                this.isInTransition = true;\r
        } else {\r
-               console.log( '慣性無し' );\r
+               //console.log( '慣性無し' );\r
        };\r
 \r
        if( newX != this.scrollX || newY != this.scrollY ){\r
@@ -519,15 +516,15 @@ function X_UI_ScrollBox_onEnd( e ){
                        easing = 'quadratic';\r
                };\r
 \r
-               console.log( 'end2 x:' + newX + ' y:' + newY + '<-y:' + this.scrollY + ' t:' + time );\r
+               //console.log( 'end2 x:' + newX + ' y:' + newY + '<-y:' + this.scrollY + ' t:' + time );\r
                this.scrollTo( newX, newY, time, easing, 1000 );\r
        } else {\r
-               console.log( 'end1 x:' + newX + ' y:' + newY );\r
+               //console.log( 'end1 x:' + newX + ' y:' + newY );\r
                this.scrollTo( newX, newY, 0, '', 1000 );       // ensures that the last position is rounded\r
-               console.log( '-3-' );\r
+               //console.log( '-3-' );\r
                this[ 'dispatch' ]( XUI_Event.SCROLL_END );             \r
        };\r
-       return ret;\r
+       return ret | X_CALLBACK_PREVENT_DEFAULT | X_CALLBACK_RELEASE_POINTER;\r
 };\r
 \r
 function X_UI_ScrollBox_resetPosition( that, time ){\r
@@ -551,12 +548,12 @@ function X_UI_ScrollBox_resetPosition( that, time ){
        };\r
 \r
        if( x === that.scrollX && y === that.scrollY ){\r
-               console.log( 'no バウンド y:' + y + ' max:' + that.scrollYMax );\r
+               //console.log( 'no バウンド y:' + y + ' max:' + that.scrollYMax );\r
                return false;\r
        };\r
 \r
-       console.log( ' ===> resetPosition - バウンド!' );\r
-       console.log( '      x:' + x + ' y:' + y );\r
+       //console.log( ' ===> resetPosition - バウンド!' );\r
+       //console.log( '      x:' + x + ' y:' + y );\r
        that.scrollTo( x, y, time, that.bounceEasing, 1000 );\r
 \r
        return true;\r
@@ -569,10 +566,10 @@ function X_UI_ScrollBox_onAnimeEnd( e ){
        };\r
        if( e.target === this.xnodeSlider && this.isInTransition && !X_UI_ScrollBox_resetPosition( this, this.bounceTime ) ){\r
                this.isInTransition = false;\r
-               console.log( '-2-' );\r
+               //console.log( '-2-' );\r
                this[ 'dispatch' ]( XUI_Event.SCROLL_END );\r
        };\r
-       console.log(' -2.1- '+this.isInTransition );\r
+       //console.log(' -2.1- '+this.isInTransition );\r
        return X_CALLBACK_NONE;\r
 };\r
 \r