OSDN Git Service

Version 0.6.134, add comments for closure compiler.
[pettanr/clientJs.git] / 0.6.x / js / 01_core / 16_XViewPort.js
index 21a3547..d31a5fe 100644 (file)
@@ -10,9 +10,9 @@ var X_ViewPort_readyState,
        X_ViewPort_hScrollbarSize,
        
        X_Dom_detectFontSize = !( X_UA[ 'IE' ] < 9 || X_UA[ 'iOS' ] ) && function(){
-                       var size = X_Node_fontSizeNode._rawObject.offsetHeight;
+                       var size = X_Node_fontSizeNode[ '_rawObject' ].offsetHeight;
                        if( X_ViewPort_baseFontSize !== size ){
-                               X_ViewPort_baseFontSize && X_ViewPort.asyncDispatch( X_Event.BASE_FONT_RESIZED );
+                               X_ViewPort_baseFontSize && X_ViewPort[ 'asyncDispatch' ]( X_EVENT_BASE_FONT_RESIZED );
                                X_ViewPort_baseFontSize = size;
                        };
        },
@@ -24,47 +24,47 @@ var X_ViewPort_readyState,
                //console.log( '-- orientationchange : ' + X.ViewPort.getSize[ 0 ] + ' ' + X.ViewPort.getSize[ 1 ] );
        },
        
-       X_ViewPort_document = new X.EventDispatcher( document ),
+       X_ViewPort_document = X_EventDispatcher( document ),
 
 X_ViewPort = X_Class_override(
-       new X.EventDispatcher( window ),
+       X_EventDispatcher( window ),
        {
 
-               handleEvent : function( e ){
+               'handleEvent' : function( e ){
                        var href, i, name;
                        
                        switch( e.type ){
                                case 'beforeunload' :
                                        // ie では a href="javascript" な要素でも beforeunload が起こる
-                                       href = e.target && e.target.attr && e.target.attr( 'href' );
-                                       if( href && href.indexOf && href.indexOf( 'javascript:' ) === 0 ) return X.Callback.PREVENT_DEFAULT | X.Callback.STOP_PROPAGATION;
+                                       href = e.target && e.target[ 'attr' ] && e.target[ 'attr' ]( 'href' );
+                                       if( href && href.indexOf && href.indexOf( 'javascript:' ) === 0 ) return X_Callback_PREVENT_DEFAULT | X_Callback_STOP_PROPAGATION;
                                        
-                                       return X_ViewPort.dispatch( X_Event.BEFORE_UNLOAD );
+                                       return X_ViewPort[ 'dispatch' ]( X_EVENT_BEFORE_UNLOAD );
                                        
                                case 'unload' :
-                                       X_ViewPort.dispatch( X_Event.UNLOAD );
+                                       X_ViewPort[ 'dispatch' ]( X_EVENT_UNLOAD );
                                //alert('unload');
-                                       X_ViewPort_document.kill();
-                                       this.kill();
+                                       X_ViewPort_document[ 'kill' ]();
+                                       this[ 'kill' ]();
                                        
-                                       //X_System.dispatch( X_Event.SHUT_DOWN );
+                                       //X_System[ 'dispatch' ]( X_EVENT_SHUT_DOWN );
                                        break;
 
                                case 'visibilitychange' :
-                                       X_ViewPort.dispatch( ( X_ViewPort_active = document[ 'hidden' ] ) ? X_Event.VIEW_DEACTIVATE : X_Event.VIEW_ACTIVATE );
+                                       X_ViewPort[ 'dispatch' ]( ( X_ViewPort_active = document[ 'hidden' ] ) ? X_EVENT_VIEW_DEACTIVATE : X_EVENT_VIEW_ACTIVATE );
                                        break;
                                case 'mozvisibilitychange' :
-                                       X_ViewPort.dispatch( ( X_ViewPort_active = document[ 'mozHidden' ] ) ? X_Event.VIEW_DEACTIVATE : X_Event.VIEW_ACTIVATE );
+                                       X_ViewPort[ 'dispatch' ]( ( X_ViewPort_active = document[ 'mozHidden' ] ) ? X_EVENT_VIEW_DEACTIVATE : X_EVENT_VIEW_ACTIVATE );
                                        break;
                                case 'webkitvisibilitychange' :
-                                       X_ViewPort.dispatch( ( X_ViewPort_active = document[ 'webkitHidden' ] ) ? X_Event.VIEW_DEACTIVATE : X_Event.VIEW_ACTIVATE );
+                                       X_ViewPort[ 'dispatch' ]( ( X_ViewPort_active = document[ 'webkitHidden' ] ) ? X_EVENT_VIEW_DEACTIVATE : X_EVENT_VIEW_ACTIVATE );
                                        break;
                                        
                                case 'pageshow' :
                                case 'focus' :
                                        if( !X_ViewPort_active ){
                                                X_ViewPort_active = true;
-                                               X_ViewPort.dispatch( X_Event.VIEW_ACTIVATE );
+                                               X_ViewPort[ 'dispatch' ]( X_EVENT_VIEW_ACTIVATE );
                                        };
                                        break;
 
@@ -72,7 +72,7 @@ X_ViewPort = X_Class_override(
                                case 'blur' :
                                        if( X_ViewPort_active ){
                                                X_ViewPort_active = false;
-                                               X_ViewPort.dispatch( X_Event.VIEW_DEACTIVATE );                         
+                                               X_ViewPort[ 'dispatch' ]( X_EVENT_VIEW_DEACTIVATE );                            
                                        };
                                        break;
                        };
@@ -89,56 +89,56 @@ X_ViewPort = X_Class_override(
  */
 X.ViewPort = {
        
-       listen : function( type, arg1, arg2, arg3 ){
+       'listen' : function( type, arg1, arg2, arg3 ){
                if( type <= X_ViewPort_readyState ){
                        /*
-                        * X_Event.XDOM_READY 以後に listen した場合の対策
+                        * X_EVENT_XDOM_READY 以後に listen した場合の対策
                         */
-                       X_ViewPort.asyncDispatch( type );
+                       X_ViewPort[ 'asyncDispatch' ]( type );
                };
                // ie8-では keydown -> documentへ
-               type && arg1 && X_ViewPort.listen( type, arg1, arg2, arg3 );
+               type && arg1 && X_ViewPort[ 'listen' ]( type, arg1, arg2, arg3 );
                return X.ViewPort;
        },
        
        
-       listenOnce : function( type, arg1, arg2, arg3 ){
+       'listenOnce' : function( type, arg1, arg2, arg3 ){
                if( type <= X_ViewPort_readyState ){
                        /*
                         * X.Event.XDOM_READY 以後に listen した場合の対策
                         */
-                       X_ViewPort.asyncDispatch( type );
+                       X_ViewPort[ 'asyncDispatch' ]( type );
                };
-               type && arg1 && X_ViewPort.listenOnce( type, arg1, arg2, arg3 );
+               type && arg1 && X_ViewPort[ 'listenOnce' ]( type, arg1, arg2, arg3 );
                return X.ViewPort;
        },
        
-       unlisten : function( type, arg1, arg2, arg3 ){
-               type && arg1 && X_ViewPort.unlisten( type, arg1, arg2, arg3 );
+       'unlisten' : function( type, arg1, arg2, arg3 ){
+               type && arg1 && X_ViewPort[ 'unlisten' ]( type, arg1, arg2, arg3 );
                return X.ViewPort;
        },
        
-       listening : function( type, arg1, arg2, arg3 ){
-               return X_ViewPort.listening( type, arg1, arg2, arg3 );
+       'listening' : function( type, arg1, arg2, arg3 ){
+               return X_ViewPort[ 'listening' ]( type, arg1, arg2, arg3 );
        },
        
        // hammer のテストファイルだけが使用
-       asyncDispatch : function(){
-               return X_ViewPort.asyncDispatch.apply( X_ViewPort, arguments );
+       'asyncDispatch' : function(){
+               return X_ViewPort[ 'asyncDispatch' ].apply( X_ViewPort, arguments );
        },
        
-       getPointerPosition : function(){
+       'getPointerPosition' : function(){
                
        },
        
        /* 要素が視界に入った  http://remysharp.com/2009/01/26/element-in-view-event-plugin/
         * TODO -> Node.call('inView')
         */
-       inView : function( elm ){
+       'inView' : function( elm ){
                
        },
        
-       getSize : function(){
+       'getSize' : function(){
                return [ X_ViewPort_width, X_ViewPort_height ];
        },
 //https://developer.mozilla.org/en-US/docs/Web/API/Element.getBoundingClientRect
@@ -146,7 +146,7 @@ X.ViewPort = {
 //(((t = document.documentElement) || (t = document.body.parentNode)) && typeof t.ScrollLeft == 'number' ? t : document.body).ScrollLeft;
 //(((t = document.documentElement) || (t = document.body.parentNode)) && typeof t.ScrollTop == 'number' ? t : document.body).ScrollTop
        
-       getDocumentSize : function(){
+       'getDocumentSize' : function(){
                // Opera は互換モードでは document.body.scrollHeight、標準モードでは document.documentElement.scrollHeight でページの高さが取れる。と思ってたんだけど、例外があった。
                // http://orera.g.hatena.ne.jp/edvakf/20100515/1273908051
        //http://onozaty.hatenablog.com/entry/20060803/p1
@@ -164,7 +164,7 @@ X.ViewPort = {
                ];
        },
        
-       getScrollPosition :
+       'getScrollPosition' :
                window.pageXOffset !== undefined ?
                        ( function(){
                                X_Node_updateTimerID && X_Node_startUpdate();
@@ -181,14 +181,14 @@ X.ViewPort = {
                                return[ X_ViewPort_rootElement.scrollLeft || document.body.scrollLeft, X_ViewPort_rootElement.scrollTop || document.body.scrollTop ];
                        } ),
 
-       getScrollbarSize : function(){
+       'getScrollbarSize' : function(){
                return [ X_ViewPort_vScrollbarSize, X_ViewPort_hScrollbarSize ];        
        },
        
-       getBaseFontSize : function(){
+       'getBaseFontSize' : function(){
                if( X_Node_updateTimerID ){
                        X_Node_startUpdate();
-                       return X_ViewPort_baseFontSize = X_Node_fontSizeNode._rawObject.offsetHeight;
+                       return X_ViewPort_baseFontSize = X_Node_fontSizeNode[ '_rawObject' ].offsetHeight;
                };
                return X_ViewPort_baseFontSize;
        }
@@ -232,14 +232,14 @@ X.ViewPort = {
                                                if( X_ViewPort_width !== size[ 0 ] || X_ViewPort_height !== size[ 1 ] ){
                                                        X_ViewPort_width = size[ 0 ];
                                                        X_ViewPort_height = size[ 1 ];
-                                                       X.Timer.once( 100, X_Dom_detectFinishResizing );
+                                                       X_Timer_once( 100, X_Dom_detectFinishResizing );
                                                        X_ViewPort_lock = true;
                                                };
                                        };
                                        
-                                       size = X_Node_fontSizeNode._rawObject.offsetHeight;
+                                       size = X_Node_fontSizeNode[ '_rawObject' ].offsetHeight;
                                        if( X_ViewPort_baseFontSize !== size ){
-                                               X_ViewPort_baseFontSize && X_ViewPort.asyncDispatch( X_Event.BASE_FONT_RESIZED );
+                                               X_ViewPort_baseFontSize && X_ViewPort[ 'asyncDispatch' ]( X_EVENT_BASE_FONT_RESIZED );
                                                X_ViewPort_baseFontSize = size;
                                        };
                                        
@@ -247,8 +247,8 @@ X.ViewPort = {
                                (function( e ){
                                        console.log( '-- resize : ' + X_Timer_now() );
                                        
-                                       !X_ViewPort_lock && ( X_ViewPort_lock = true ) && X.Timer.once( 100, X_Dom_detectFinishResizing );
-                                       return X.Callback.PREVENT_DEFAULT | X.Callback.STOP_PROPAGATION;
+                                       !X_ViewPort_lock && ( X_ViewPort_lock = true ) && X_Timer_once( 100, X_Dom_detectFinishResizing );
+                                       return X_Callback_PREVENT_DEFAULT | X_Callback_STOP_PROPAGATION;
                                });
                
                function X_Dom_detectFinishResizing(){
@@ -256,15 +256,15 @@ X.ViewPort = {
                        if( X_ViewPort_width !== size[ 0 ] || X_ViewPort_height !== size[ 1 ] ){
                                X_ViewPort_width  = size[ 0 ];
                                X_ViewPort_height = size[ 1 ];
-                               X.Timer.once( 100, X_Dom_detectFinishResizing );
+                               X_Timer_once( 100, X_Dom_detectFinishResizing );
                        } else {
                                console.log( '-- detectFinishResizing : ' + X_Timer_now() );
                                
-                               X_ViewPort.asyncDispatch( X_Event.VIEW_RESIZED );
+                               X_ViewPort[ 'asyncDispatch' ]( X_EVENT_VIEW_RESIZED );
                                X_ViewPort_lock = false;
                                if( X_ViewPort_orientationFlag ){
                                        X_ViewPort_orientationFlag = false;
-                                       X_ViewPort.asyncDispatch( 100, { type : X_Event.VIEW_TURNED, orientation : window.orientation } );
+                                       X_ViewPort[ 'asyncDispatch' ]( 100, { type : X_EVENT_VIEW_TURNED, orientation : window.orientation } );
                                };
                        };
                };
@@ -274,11 +274,11 @@ X.ViewPort = {
                        
                        console.log( '> X_TEMP.onDomContentLoaded rs:' + X_ViewPort_readyState );
                        
-                       if( X_TEMP.SYSTEM_EVENT_PRE_INIT <= X_ViewPort_readyState ) return X_Callback_UN_LISTEN;
-                       X_ViewPort_readyState = X_TEMP.SYSTEM_EVENT_PRE_INIT;
+                       if( X_EVENT_PRE_INIT <= X_ViewPort_readyState ) return X_Callback_UN_LISTEN;
+                       X_ViewPort_readyState = X_EVENT_PRE_INIT;
                        
                        // DOMContentLoaded の無いブラウザで X_TEMP.onDomContentLoaded への参照が残り続けるのを回避
-                       X_TEMP.onDomContentLoaded && X_ViewPort_document.unlisten( 'DOMContentLoaded', X_TEMP.onDomContentLoaded );
+                       X_TEMP.onDomContentLoaded && X_ViewPort_document[ 'unlisten' ]( 'DOMContentLoaded', X_TEMP.onDomContentLoaded );
                        delete X_TEMP.onDomContentLoaded;
                        
                        elmHtml = document.documentElement ||
@@ -293,42 +293,42 @@ X.ViewPort = {
 
                        X_ViewPort_rootElement = document.compatMode !== 'CSS1Compat' ? elmBody : elmHtml || elmBody;
 
-                       html = X.Doc.html = X_Node_html = elmHtml && new Node( elmHtml );
-                       html._flags |= X_Node_State.IN_TREE;
+                       html = X[ 'Doc' ][ 'html' ] = X_Node_html = elmHtml && new Node( elmHtml );
+                       html[ '_flags' ] |= X_Node_State.IN_TREE;
                        
-                       head = X.Doc.head = X_Node_head = elmHead && new Node( elmHead );
+                       head = X[ 'Doc' ][ 'head' ] = X_Node_head = elmHead && new Node( elmHead );
                
-                       body = X.Doc.body = X_Node_body = new Node( elmBody );
+                       body = X[ 'Doc' ][ 'body' ] = X_Node_body = new Node( elmBody );
 
-                       body.parent  = head.parent = html;
-                       html._xnodes = [ head, body ];
+                       body[ 'parent ' ] = head[ 'parent' ] = html;
+                       html[ '_xnodes' ] = [ head, body ];
                        
-                       html.appendTo = html.appendToRoot = html.before = html.after = html.clone = html.remove = html.destroy = html.prev = html.next =
-                       html.create = html.createText = html.createAt = html.createTextAt = html.append = html.appendAt = html.empty = html.html = html.text =
-                       html.css = html.cssText =
-                       head.appendTo = head.appendToRoot = head.before = head.after = head.clone = head.remove = head.destroy =
-                       head.createText = head.createTextAt = head.empty = head.html = head.text = head.css = head.cssText =
-                       body.appendTo = body.appendToRoot = body.before = body.after = body.clone = body.remove = body.destroy = new Function( 'return this' );
-
-                       X_ViewPort.listenOnce( X_TEMP.SYSTEM_EVENT_PRE_INIT, function(){
-                               X_ViewPort_readyState = X_TEMP.SYSTEM_EVENT_XTREE;
+                       html[ 'appendTo' ] = html[ 'before' ] = html[ 'after' ] = html[ 'clone' ] = html[ 'remove' ] = html[ 'destroy' ] = html[ 'prev' ] = html[ 'next' ] =
+                       html[ 'create' ] = html[ 'createText' ] = html[ 'createAt' ] = html[ 'createTextAt' ] = html[ 'append' ] = html[ 'appendAt' ] = html[ 'empty' ] = html[ 'html' ] = html[ 'text' ] =
+                       html[ 'css' ] = html[ 'cssText' ] =
+                       head[ 'appendTo' ] = head[ 'before' ] = head[ 'after' ] = head[ 'clone' ] = head[ 'remove' ] = head[ 'destroy' ] =
+                       head[ 'createText' ] = head[ 'createTextAt' ] = head[ 'empty' ] = head[ 'html' ] = head[ 'text' ] = head[ 'css' ] = head[ 'cssText' ] =
+                       body[ 'appendTo' ] = body[ 'before' ] = body[ 'after' ] = body[ 'clone' ] = body[ 'remove' ] = body[ 'destroy' ] = new Function( 'return this' );
+
+                       X_ViewPort[ 'listenOnce' ]( X_EVENT_PRE_INIT, function(){
+                               X_ViewPort_readyState = X_EVENT_XTREE_READY;
                                if( X_TEMP.X_Dom_useBuilder ) X_TEMP.X_Dom_useBuilder = !!document.body.children.length;
-                               !X_TEMP.X_Dom_useBuilder && X_ViewPort.asyncDispatch( X_TEMP.SYSTEM_EVENT_XTREE );
+                               !X_TEMP.X_Dom_useBuilder && X_ViewPort[ 'asyncDispatch' ]( X_EVENT_XTREE_READY );
                        } );
                        
-                       X_ViewPort.listenOnce( X_TEMP.SYSTEM_EVENT_XTREE, function(){
-                               X_ViewPort_readyState = X_TEMP.SYSTEM_EVENT_INIT;
+                       X_ViewPort[ 'listenOnce' ]( X_EVENT_XTREE_READY, function(){
+                               X_ViewPort_readyState = X_EVENT_INIT;
                                //X_UA[ 'Opera7' ] && alert( 'bc' );
-                               X_Node_body.appendAt( 0,
+                               X_Node_body[ 'appendAt' ]( 0,
                                        X_Node_systemNode = X_Doc_create( 'div', { 'class' : 'hidden-system-node' } ),
-                                       X_Node_fontSizeNode = X_Doc_create( 'div', { 'class' : 'hidden-system-node' } ).cssText( 'line-height:1;height:1em;' ).text( 'X' )
+                                       X_Node_fontSizeNode = X_Doc_create( 'div', { 'class' : 'hidden-system-node' } )[ 'cssText' ]( 'line-height:1;height:1em;' )[ 'text' ]( 'X' )
                                );
                                X_Node_startUpdate();
 
-                               X_ViewPort.asyncDispatch( X_TEMP.SYSTEM_EVENT_INIT );
+                               X_ViewPort[ 'asyncDispatch' ]( X_EVENT_INIT );
                        } );
 
-                       X_ViewPort.listenOnce( X_TEMP.SYSTEM_EVENT_INIT, function(){
+                       X_ViewPort[ 'listenOnce' ]( X_EVENT_INIT, function(){
                                var size = X_ViewPort_getWindowSize(),
                                
                                // http://jsdo.it/imaya/kTYg
@@ -362,18 +362,18 @@ X.ViewPort = {
                                
                                if( X_Dom_detectFontSize ){
                                        X_EventDispatcher_systemListen( X_ViewPort, 'resize', X_ViewPort_resize );
-                                       X.Timer.add( 333, X_Dom_detectFontSize );
+                                       X_Timer_add( 333, X_Dom_detectFontSize );
                                } else {
-                                       X.Timer.add( 333, X_ViewPort_resize );
+                                       X_Timer_add( 333, X_ViewPort_resize );
                                };
                                
-                               X_ViewPort_baseFontSize = X_Node_fontSizeNode._rawObject.offsetHeight;
+                               X_ViewPort_baseFontSize = X_Node_fontSizeNode[ '_rawObject' ].offsetHeight;
                                
-                               X_ViewPort_readyState = X_Event.XDOM_READY;
-                               X_ViewPort.asyncDispatch( { type : X_Event.XDOM_READY, w : X_ViewPort_width = size[ 0 ], h : X_ViewPort_height = size[ 1 ] } );
+                               X_ViewPort_readyState = X_EVENT_XDOM_READY;
+                               X_ViewPort[ 'asyncDispatch' ]( { type : X_EVENT_XDOM_READY, w : X_ViewPort_width = size[ 0 ], h : X_ViewPort_height = size[ 1 ] } );
                        } );
 
-                       X_ViewPort.asyncDispatch( X_TEMP.SYSTEM_EVENT_PRE_INIT );       
+                       X_ViewPort[ 'asyncDispatch' ]( X_EVENT_PRE_INIT );      
 
 
                        X_EventDispatcher_systemListen( X_ViewPort, [ 'beforeunload', 'unload' ] );
@@ -419,7 +419,7 @@ console.log( 'X.Dom dom:w3c=' + X_UA_DOM.W3C + ' ev:w3c=' + X_UA_EVENT.W3C );
 
 /* for ie9+/Mozilla/Opera9 */
 if( X_UA_EVENT.W3C ){
-       X_ViewPort_document.listenOnce( 'DOMContentLoaded', X_TEMP.onDomContentLoaded );
+       X_ViewPort_document[ 'listenOnce' ]( 'DOMContentLoaded', X_TEMP.onDomContentLoaded );
 } else
 if( 6 <= X_UA[ 'IE' ] && X.inHead ){
        // if this script in Head
@@ -428,7 +428,7 @@ if( 6 <= X_UA[ 'IE' ] && X.inHead ){
        X_TEMP._script.onreadystatechange = function(){
                var s = X_TEMP._script;
                if( s && s.readyState === 'complete' ){
-                       s.onreadystatechange = X.emptyFunction;
+                       s.onreadystatechange = X_emptyFunction;
                        s.onreadystatechange = null;
                        s.parentNode.removeChild( s );
                        delete X_TEMP._script;
@@ -439,11 +439,11 @@ if( 6 <= X_UA[ 'IE' ] && X.inHead ){
 // Re: onLoad doesn't work with Safari?
 // http://lists.apple.com/archives/web-dev/2003/Oct/msg00036.html
 if( X_UA[ 'WebKit' ] || X_UA[ 'Safari' ]  < 3 ){ // sniff
-       X.Timer.add( 16, function(){
+       X_Timer_add( 16, function(){
                if( !X_TEMP.onDomContentLoaded ) return X_Callback_UN_LISTEN;
                if( document.readyState === 'loaded' || document.readyState === 'complete' ) return X_TEMP.onDomContentLoaded();
        });
 };
 
 /* for other browsers */
-X_ViewPort.listenOnce( 'load', X_TEMP.onDomContentLoaded );
+X_ViewPort[ 'listenOnce' ]( 'load', X_TEMP.onDomContentLoaded );