OSDN Git Service

Version 0.6.191, fix X.UI.ScrollBox & X.UI.Gesture.
[pettanr/clientJs.git] / 0.6.x / js / 20_ui / 15_ScrollBox.js
index f2f6a27..323b95b 100644 (file)
@@ -42,6 +42,7 @@ function XUI_ScrollBox_indicatorHandleEvent( e ){
        switch( e.type ){\r
                case X_EVENT_CANCELED :\r
                case XUI_Event.SCROLL_END :\r
+                       console.log( '-fadeout-' );\r
                        this[ 'animate' ](\r
                                { opacity : 1 },\r
                                { opacity : 0 },\r
@@ -130,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
@@ -223,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
@@ -233,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
@@ -246,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
@@ -264,56 +273,57 @@ 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
                );\r
        };\r
        \r
-       that.scrollX = x;\r
-       that.scrollY = y;\r
+       that.scrollX   = x;\r
+       that.scrollXEm = x / that.fontSize;\r
+       that.scrollY   = y;\r
+       that.scrollYEm = y / that.fontSize;\r
 };\r
 \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
@@ -331,7 +341,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
@@ -344,10 +354,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_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
@@ -364,10 +371,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
@@ -462,11 +465,11 @@ function X_UI_ScrollBox_onEnd( e ){
                newX, newY,\r
                momentumX, momentumY,\r
                duration, distanceX, distanceY;\r
-                                               \r
-       this[ 'unlisten' ]( XUI_Event._POINTER_MOVE, this, X_UI_ScrollBox_onMove );\r
-       this[ 'unlisten' ]( [ XUI_Event._POINTER_UP, XUI_Event._POINTER_CANCEL ], this, X_UI_ScrollBox_onEnd );\r
+       \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
                return ret;\r
        };\r
 \r
@@ -482,14 +485,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
-               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
@@ -505,7 +509,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
@@ -514,15 +518,15 @@ function X_UI_ScrollBox_onEnd( e ){
                        easing = 'quadratic';\r
                };\r
 \r
-               console.log( 'end2 x:' + newX + ' y:' + newY + ' 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
@@ -546,23 +550,28 @@ 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
 };\r
 \r
 function X_UI_ScrollBox_onAnimeEnd( e ){\r
+       if( e.target !== this.xnodeSlider ){\r
+               console.log( '- not much -' );\r
+               console.dir(e);\r
+       };\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
        return X_CALLBACK_NONE;\r
 };\r
 \r
@@ -618,19 +627,19 @@ X.UI.ScrollBox = X.UI.ChromeBox.inherits(
                                                        minHeight : '100%'\r
                                                }\r
                                        ],\r
-                               i    = arguments.length,\r
+                               l    = arguments.length, i = 0, j = 1,\r
                                arg, attr;\r
                        \r
-                       for( ; i; ){\r
-                               arg = arguments[ --i ];\r
+                       for( ; i < l; ++i ){\r
+                               arg = arguments[ i ];\r
                                if( arg[ 'instanceOf' ] && arg[ 'instanceOf' ]( XUI_LayoutBase ) ){\r
                                        args[ 0 ] = arg;\r
                                } else\r
                                if( arg[ 'instanceOf' ] && arg[ 'instanceOf' ]( X.UI.AbstractUINode ) ){\r
-                                       args[ args.length ] = arg;\r
+                                       args[ ++j ] = arg;\r
                                } else\r
                                if( X_Type_isObject( arg ) ){\r
-                                       args[ args.length ] = attr = arg;\r
+                                       args[ ++j ] = attr = arg;\r
                                        slider = attr.scrollSlider;\r
                                };\r
                        };\r