OSDN Git Service

Version 0.6.133, fix for closure compiler - ADVANCED_OPTIMIZATIONS
[pettanr/clientJs.git] / 0.6.x / js / 01_core / 16_XViewPort.js
index 8f65140..21a3547 100644 (file)
@@ -9,10 +9,10 @@ var X_ViewPort_readyState,
        X_ViewPort_vScrollbarSize,
        X_ViewPort_hScrollbarSize,
        
-       X_Dom_detectFontSize = !( X.UA.IE < 9 || X.UA.iOS ) && function(){
+       X_Dom_detectFontSize = !( X_UA[ 'IE' ] < 9 || X_UA[ 'iOS' ] ) && function(){
                        var size = X_Node_fontSizeNode._rawObject.offsetHeight;
                        if( X_ViewPort_baseFontSize !== size ){
-                               X_ViewPort_baseFontSize && X_ViewPort.asyncDispatch( { type : X.Event.BASE_FONT_RESIZED, fontSize : size, w : X_ViewPort_width, h : X_ViewPort_height } );
+                               X_ViewPort_baseFontSize && X_ViewPort.asyncDispatch( X_Event.BASE_FONT_RESIZED );
                                X_ViewPort_baseFontSize = size;
                        };
        },
@@ -20,7 +20,7 @@ var X_ViewPort_readyState,
        X_ViewPort_orientationFlag,     
        X_Dom_orientationchange = window[ 'orientation' ] !== undefined && function( e ){
                X_ViewPort_orientationFlag = true;
-               !X.UA.Android && X_ViewPort_resize();
+               !X_UA[ 'Android' ] && X_ViewPort_resize();
                //console.log( '-- orientationchange : ' + X.ViewPort.getSize[ 0 ] + ' ' + X.ViewPort.getSize[ 1 ] );
        },
        
@@ -31,37 +31,49 @@ X_ViewPort = X_Class_override(
        {
 
                handleEvent : function( e ){
-                       var href;
+                       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;
                                        
-                                       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.unlisten();
-                                       X_ViewPort_document.unlisten();
-                                       X_Node__actualRemove( X_Node_html, true );
+                                       //X_System.dispatch( X_Event.SHUT_DOWN );
                                        break;
+
                                case 'visibilitychange' :
-                                       X_ViewPort.dispatch( { type : ( 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 );
                                        break;
                                case 'webkitvisibilitychange' :
-                                       X_ViewPort.dispatch( { type : ( 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' :
-                                       X_ViewPort_active = true;
-                                       X_ViewPort.dispatch( X.Event.VIEW_ACTIVATE );
+                                       if( !X_ViewPort_active ){
+                                               X_ViewPort_active = true;
+                                               X_ViewPort.dispatch( X_Event.VIEW_ACTIVATE );
+                                       };
                                        break;
+
                                case 'pagehide' :
                                case 'blur' :
-                                       X_ViewPort_active = false;
-                                       X_ViewPort.dispatch( X.Event.VIEW_DEACTIVATE );
+                                       if( X_ViewPort_active ){
+                                               X_ViewPort_active = false;
+                                               X_ViewPort.dispatch( X_Event.VIEW_DEACTIVATE );                         
+                                       };
                                        break;
                        };
                }
@@ -70,15 +82,21 @@ X_ViewPort = X_Class_override(
 );
 
 
+/**
+ * window に相当する ViewPort 情報を提供するオブジェクト。
+ * @namespace X.ViewPort
+ * @alias X.ViewPort
+ */
 X.ViewPort = {
        
        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 : type, w : X_ViewPort_width, h : X_ViewPort_height } );
+                       X_ViewPort.asyncDispatch( type );
                };
+               // ie8-では keydown -> documentへ
                type && arg1 && X_ViewPort.listen( type, arg1, arg2, arg3 );
                return X.ViewPort;
        },
@@ -89,7 +107,7 @@ X.ViewPort = {
                        /*
                         * X.Event.XDOM_READY 以後に listen した場合の対策
                         */
-                       X_ViewPort.asyncDispatch( { type : type, w : X_ViewPort_width, h : X_ViewPort_height } );
+                       X_ViewPort.asyncDispatch( type );
                };
                type && arg1 && X_ViewPort.listenOnce( type, arg1, arg2, arg3 );
                return X.ViewPort;
@@ -113,7 +131,9 @@ X.ViewPort = {
                
        },
        
-       /* 要素が視界に入った  http://remysharp.com/2009/01/26/element-in-view-event-plugin/ */
+       /* 要素が視界に入った  http://remysharp.com/2009/01/26/element-in-view-event-plugin/
+        * TODO -> Node.call('inView')
+        */
        inView : function( elm ){
                
        },
@@ -132,8 +152,8 @@ X.ViewPort = {
        //http://onozaty.hatenablog.com/entry/20060803/p1
        // Safari2.0.4では標準・互換どちらも document.body
                
-               X_Node_body._updateTimerID && X_Node_startUpdate();
-               /*X.UA.Opera ?
+               X_Node_updateTimerID && X_Node_startUpdate();
+               /*X_UA[ 'Opera' ] ?
                        ( document.documentElement && document.documentElement.clientWidth ?
                                new Function( 'return[document.documentElement.clientWidth,document.documentElement.clientHeight]' ) :
                                new Function( 'return[document.body.clientWidth,document.body.clientHeight]' )
@@ -147,16 +167,16 @@ X.ViewPort = {
        getScrollPosition :
                window.pageXOffset !== undefined ?
                        ( function(){
-                               X_Node_body._updateTimerID && X_Node_startUpdate();
+                               X_Node_updateTimerID && X_Node_startUpdate();
                                return[ window.pageXOffset, window.pageYOffset ];
                        } ) :
                window.scrollLeft  !== undefined ?
                        ( function(){
-                               X_Node_body._updateTimerID && X_Node_startUpdate();
+                               X_Node_updateTimerID && X_Node_startUpdate();
                                return[ window.scrollLeft, window.scrollTop ];
                        } ) :
                        ( function(){
-                               X_Node_body._updateTimerID && X_Node_startUpdate();
+                               X_Node_updateTimerID && X_Node_startUpdate();
                                // body は Safari2-
                                return[ X_ViewPort_rootElement.scrollLeft || document.body.scrollLeft, X_ViewPort_rootElement.scrollTop || document.body.scrollTop ];
                        } ),
@@ -166,7 +186,7 @@ X.ViewPort = {
        },
        
        getBaseFontSize : function(){
-               if( X_Node_body._updateTimerID ){
+               if( X_Node_updateTimerID ){
                        X_Node_startUpdate();
                        return X_ViewPort_baseFontSize = X_Node_fontSizeNode._rawObject.offsetHeight;
                };
@@ -204,7 +224,7 @@ X.ViewPort = {
  */
                var X_ViewPort_resize =
                        // iOS もループで回す,,,iOS3.1.3, iOS6 で確認
-                       X.UA.IE < 9 || X.UA.iOS ?
+                       X_UA[ 'IE' ] < 9 || X_UA[ 'iOS' ] ?
                                (function(){
                                        var size;
                                        if( !X_ViewPort_lock ){
@@ -219,7 +239,7 @@ X.ViewPort = {
                                        
                                        size = X_Node_fontSizeNode._rawObject.offsetHeight;
                                        if( X_ViewPort_baseFontSize !== size ){
-                                               X_ViewPort_baseFontSize && X_ViewPort.asyncDispatch( { type : X.Event.BASE_FONT_RESIZED, fontSize : size, w : X_ViewPort_width, h : X_ViewPort_height  } );
+                                               X_ViewPort_baseFontSize && X_ViewPort.asyncDispatch( X_Event.BASE_FONT_RESIZED );
                                                X_ViewPort_baseFontSize = size;
                                        };
                                        
@@ -240,11 +260,11 @@ X.ViewPort = {
                        } else {
                                console.log( '-- detectFinishResizing : ' + X_Timer_now() );
                                
-                               X_ViewPort.asyncDispatch( { type : X.Event.VIEW_RESIZED, fontSize : X_ViewPort_baseFontSize, w : X_ViewPort_width, h : X_ViewPort_height } );
+                               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 } );
                                };
                        };
                };
@@ -252,6 +272,8 @@ X.ViewPort = {
                X_TEMP.onDomContentLoaded = function(){
                        var s, size, elmHtml, elmHead, elmBody, html, head, body;
                        
+                       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;
                        
@@ -272,22 +294,21 @@ 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;
+                       
                        head = X.Doc.head = X_Node_head = elmHead && new Node( elmHead );
                
                        body = X.Doc.body = X_Node_body = new Node( elmBody );
-                       
-                       body._root   = html._root = head._root = body;// _root は html だろ
+
                        body.parent  = head.parent = html;
-                       html._xnodes = [ head, body ];                  
-                       
-                       Node.root = body; // 後方互換
+                       html._xnodes = [ head, body ];
                        
-                       html.appendTo = html.appendToRoot = html.before = html.after = html.clone = html.remove = html.destroy = html.prevNode = html.nextNode =
+                       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 =
-                       head.appendTo = head.appendToRoot = head.before = head.after = head.clone = head.remove = head.destroy = head.prevNode = head.nextNode =
-                       head.empty = head.html = head.text =
-                       body.appendTo = body.appendToRoot = body.before = body.after = body.clone = body.remove = body.destroy = body.prevNode = body.nextNode = new Function( 'return this' );
+                       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;
@@ -297,10 +318,10 @@ X.ViewPort = {
                        
                        X_ViewPort.listenOnce( X_TEMP.SYSTEM_EVENT_XTREE, function(){
                                X_ViewPort_readyState = X_TEMP.SYSTEM_EVENT_INIT;
-                               //X.UA.Opera7 && alert( 'bc' );
+                               //X_UA[ 'Opera7' ] && alert( 'bc' );
                                X_Node_body.appendAt( 0,
-                                       X_Node_systemNode = Node.create( 'div', { 'class' : 'hidden-system-node' } ),
-                                       X_Node_fontSizeNode = Node.create( 'div', { 'class' : 'hidden-system-node' } ).cssText( 'line-height:1;height:1em;' ).text( 'X' )
+                                       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_startUpdate();
 
@@ -336,11 +357,11 @@ X.ViewPort = {
                                
                                //
                                if( X_Dom_orientationchange ){
-                                       X_ViewPort.listen( 'orientationchange', X_Dom_orientationchange );
+                                       X_EventDispatcher_systemListen( X_ViewPort, 'orientationchange', X_Dom_orientationchange );
                                };
                                
                                if( X_Dom_detectFontSize ){
-                                       X_ViewPort.listen( 'resize', X_ViewPort_resize );
+                                       X_EventDispatcher_systemListen( X_ViewPort, 'resize', X_ViewPort_resize );
                                        X.Timer.add( 333, X_Dom_detectFontSize );
                                } else {
                                        X.Timer.add( 333, X_ViewPort_resize );
@@ -348,38 +369,38 @@ X.ViewPort = {
                                
                                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 ] } );
                        } );
 
-                       console.log( X_ViewPort.asyncDispatch( X_TEMP.SYSTEM_EVENT_PRE_INIT ) );        
+                       X_ViewPort.asyncDispatch( X_TEMP.SYSTEM_EVENT_PRE_INIT );       
 
-                       X_ViewPort
-                               .listen( 'beforeunload', X_ViewPort )
-                               .listenOnce( 'unload', X_ViewPort );
+
+                       X_EventDispatcher_systemListen( X_ViewPort, [ 'beforeunload', 'unload' ] );
 
 //ブラウザの戻るボタンで戻ったときに呼ばれるイベントとかキャッシュとかそこらへんのこと
 //http://d.hatena.ne.jp/koumiya/20080916/1221580149
 
-                       if( document[ 'hidden' ] !== undefined ) {// iOS 7+
-                               X_ViewPort_document.listen( 'visibilitychange', X_ViewPort );
+                       if( document[ 'hidden' ] !== undefined ){// iOS 7+
+                               X_EventDispatcher_systemListen( X_ViewPort_document, 'visibilitychange', X_ViewPort );
+                       } else
+                       if( document[ 'mozHidden' ] !== undefined ){
+                               X_EventDispatcher_systemListen( X_ViewPort_document, 'mozvisibilitychange', X_ViewPort );
                        } else
-                       if( document[ 'webkitHidden' ] !== undefined ) {
-                               X_ViewPort_document.listen( 'webkitvisibilitychange', X_ViewPort );
+                       if( document[ 'webkitHidden' ] !== undefined ){
+                               X_EventDispatcher_systemListen( X_ViewPort_document, 'webkitvisibilitychange', X_ViewPort );
                        } else
-                       if( X.UA.iOS && window[ 'onpageshow' ] !== undefined ) {
-                               X_ViewPort.listen( 'pageshow', X_ViewPort )
-                                                       .listen( 'pagehide', X_ViewPort );      
+                       if( X_UA[ 'iOS' ] && window[ 'onpageshow' ] !== undefined ){
+                               X_EventDispatcher_systemListen( X_ViewPort, [ 'pageshow', 'pagehide' ] );
                        } else {
-                               X_ViewPort.listen( 'focus', X_ViewPort )
-                                                       .listen( 'blur', X_ViewPort );
+                               X_EventDispatcher_systemListen( X_ViewPort, [ 'focus', 'blur' ] );
                        };
 
                        return X_Callback_UN_LISTEN;
                };
 
                function X_ViewPort_getWindowSize(){
-                       return X.UA.IE ?
+                       return X_UA[ 'IE' ] ?
                                [ X_ViewPort_rootElement.clientWidth, X_ViewPort_rootElement.clientHeight ] :
                                [ window.innerWidth, window.innerHeight ];
                };
@@ -400,7 +421,7 @@ console.log( 'X.Dom dom:w3c=' + X_UA_DOM.W3C + ' ev:w3c=' + X_UA_EVENT.W3C );
 if( X_UA_EVENT.W3C ){
        X_ViewPort_document.listenOnce( 'DOMContentLoaded', X_TEMP.onDomContentLoaded );
 } else
-if( 6 <= X.UA.IE && X.inHead ){
+if( 6 <= X_UA[ 'IE' ] && X.inHead ){
        // if this script in Head
        document.write( "<script id=__ie_onload defer src=javascript:void(0)><\/script>" );
        X_TEMP._script = document.getElementById( "__ie_onload" );
@@ -417,7 +438,7 @@ 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
+if( X_UA[ 'WebKit' ] || X_UA[ 'Safari' ]  < 3 ){ // sniff
        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();