OSDN Git Service

Version 0.6.179, fix X.Audio & X.AudioSprite.
[pettanr/clientJs.git] / 0.6.x / js / 01_core / 21_XViewPort.js
index c1a1760..a89df05 100644 (file)
@@ -51,7 +51,7 @@ X_ViewPort = X_Class_override(
                                        X_ViewPort[ 'dispatch' ]( X_EVENT_UNLOAD );
                                //alert('unload');
                                        X_ViewPort_document[ 'kill' ]();
-                                       this[ 'kill' ]();
+                                       X_ViewPort[ 'kill' ]();
                                        
                                        //X_System[ 'dispatch' ]( X_EVENT_SHUT_DOWN );
                                        break;
@@ -75,7 +75,7 @@ X_ViewPort = X_Class_override(
        
                                case 'blur' :
                                case 'focusout' :
-                                       if( X_UA[ 'IE' ] < 9 ){
+                                       if( 5 < X_UA[ 'IE' ] && X_UA[ 'IE' ] < 9 ){
                                                xnode = X_Node_getXNode( document.activeElement );
                                                if( xnode ){
                                                        xnode[ 'listenOnce' ]( [ 'focus', 'blur' ], X_ViewPort_detectFocusForIE );
@@ -107,15 +107,23 @@ X_ViewPort = X_Class_override(
 );
 
 function X_ViewPort_detectFocusForIE( e ){
-       console.log( 'iefix! ' + e.type + ':' + this.attr( 'tag' ) + ' isActive?:' + ( this[ '_rawObject' ] === document.activeElement ) );
-       
+       //console.log( 'iefix! ' + e.type + ':' + this.attr( 'tag' ) + ' isActive?:' + ( this[ '_rawObject' ] === document.activeElement ) );
+       var elmActive = X_Script_try( X_Object_find, [ document, 'activeElement' ] );
        X_ViewPort_active = e.type === 'focus';
        
-       if( this[ '_rawObject' ] !== document.activeElement ){
+       
+       if( elmActive && this[ '_rawObject' ] !== elmActive ){
                this[ 'unlisten' ]( X_ViewPort_active ? 'blur' : 'focus', X_ViewPort_detectFocusForIE );
+               console.log( '>>>>>> activeElement 取得 不一致 ' + this._tag );
+       } else
+       if( !elmActive ){
+               console.log( '******** activeElement 取得のエラー' );
+       } else if( elmActive ){
+               console.log( '>>>>>> activeElement 取得' );
        };
+
        if( X_ViewPort_activeTimerID ){
-               X_ViewPort_activeTimerID = X_Timer_remove( X_ViewPort_activeTimerID );
+               X_Timer_remove( X_ViewPort_activeTimerID );
        };
        X_ViewPort_activeTimerID = X_Timer_once( 16, X_ViewPort_changeFocus );
        
@@ -248,11 +256,11 @@ X[ 'ViewPort' ] = {
        },
 //https://developer.mozilla.org/en-US/docs/Web/API/Element.getBoundingClientRect
 //use window.pageXOffset and window.pageYOffset instead of window.scrollX and window.scrollY
-//(((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
+//(((t = document.documentElement) || (t = X_elmBody.parentNode)) && typeof t.ScrollLeft == 'number' ? t : X_elmBody).ScrollLeft;
+//(((t = document.documentElement) || (t = X_elmBody.parentNode)) && typeof t.ScrollTop == 'number' ? t : X_elmBody).ScrollTop
        
-       /*
-        * TODO X.Doc へ
+       // TODO X.Doc へ
+       /**
         * @alias X.ViewPort.getDocumentSize
         */
        'getDocumentSize' : function(){
@@ -265,7 +273,7 @@ X[ 'ViewPort' ] = {
                /*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]' )
+                               new Function( 'return[X_elmBody.clientWidth,X_elmBody.clientHeight]' )
                        ) :*/                   
                return [
                        X_ViewPort_rootElement.scrollWidth  || X_ViewPort_rootElement.offsetWidth,
@@ -291,7 +299,7 @@ X[ 'ViewPort' ] = {
                        ( function(){
                                X_Node_updateTimerID && X_Node_startUpdate();
                                // body は Safari2-
-                               return[ X_ViewPort_scrollX = X_ViewPort_rootElement.scrollLeft || document.body.scrollLeft, X_ViewPort_scrollY = X_ViewPort_rootElement.scrollTop || document.body.scrollTop ];
+                               return[ X_ViewPort_scrollX = X_ViewPort_rootElement.scrollLeft || X_elmBody.scrollLeft, X_ViewPort_scrollY = X_ViewPort_rootElement.scrollTop || X_elmBody.scrollTop ];
                        } ),
 
        /**
@@ -407,7 +415,7 @@ X[ 'ViewPort' ] = {
                };
 
                X_TEMP.onDomContentLoaded = function(){
-                       var s, size, elmHtml, elmHead, elmBody, html, head, body;
+                       var html, head, body;
                        
                        console.log( '> X_TEMP.onDomContentLoaded rs:' + X_ViewPort_readyState );
                        
@@ -417,25 +425,17 @@ X[ 'ViewPort' ] = {
                        // DOMContentLoaded の無いブラウザで X_TEMP.onDomContentLoaded への参照が残り続けるのを回避
                        X_TEMP.onDomContentLoaded && X_ViewPort_document[ 'unlisten' ]( 'DOMContentLoaded', X_TEMP.onDomContentLoaded );
                        delete X_TEMP.onDomContentLoaded;
-                       
-                       elmHtml = document.documentElement ||
-                               X_UA_DOM.W3C ? document.getElementsByTagName( 'html' )[ 0 ] :
-                               X_UA_DOM.IE4 ? document.all.tags( 'html' )[ 0 ] : null;
-                       
-                       elmHead = 
-                               X_UA_DOM.W3C ? document.getElementsByTagName( 'head' )[ 0 ] :
-                               X_UA_DOM.IE4 ? document.all.tags( 'head' )[ 0 ] : null;
 
-                       elmBody = document.body;
+                       X_elmBody = document.body;
 
-                       X_ViewPort_rootElement = document.compatMode !== 'CSS1Compat' ? elmBody : elmHtml || elmBody;
+                       X_ViewPort_rootElement = document.compatMode !== 'CSS1Compat' ? X_elmBody : X_elmHtml || X_elmBody;
 
        /**
         * Node( documentElement )
         * @alias X.Doc.html
         * @type {Node}
         */
-                       X[ 'Doc' ][ 'html' ] = html = X_Node_html = elmHtml && Node( elmHtml )[ 'removeClass' ]( 'js-disabled' )[ 'addClass' ]( X_UA_classNameForHTML );
+                       X[ 'Doc' ][ 'html' ] = html = X_Node_html = X_elmHtml && Node( X_elmHtml )[ 'removeClass' ]( 'js-disabled' )[ 'addClass' ]( X_UA_classNameForHTML );
                        html[ '_flags' ] |= X_NodeFlags_IN_TREE;
 
        /**
@@ -443,14 +443,14 @@ X[ 'ViewPort' ] = {
         * @alias X.Doc.head
         * @type {Node}
         */                     
-                       X[ 'Doc' ][ 'head' ] = head = X_Node_head = elmHead && Node( elmHead );
+                       X[ 'Doc' ][ 'head' ] = head = X_Node_head = X_elmHead && Node( X_elmHead );
 
        /**
         * Node( documentElement )
         * @alias X.Doc.body
         * @type {Node}
         */             
-                       X[ 'Doc' ][ 'body' ] = body = X_Node_body = Node( elmBody );
+                       X[ 'Doc' ][ 'body' ] = body = X_Node_body = Node( X_elmBody );
 
                        body[ 'parent ' ] = head[ 'parent' ] = html;
                        html[ '_xnodes' ] = [ head, body ];
@@ -458,13 +458,13 @@ X[ 'ViewPort' ] = {
                        html[ 'appendTo' ] = html[ 'prev' ] = html[ 'next' ] = html[ 'clone' ] = html[ 'remove' ] = html[ 'kill' ] =
                        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[ 'prev' ] = head[ 'next' ] = head[ 'clone' ] = head[ 'remove' ] = head[ 'kill' ] =
+                       head[ 'appendTo' ] = head[ 'prev' ] = head[ 'clone' ] = head[ 'remove' ] = head[ 'kill' ] =
                        head[ 'createText' ] = head[ 'createTextAt' ] = head[ 'empty' ] = head[ 'html' ] = head[ 'text' ] = head[ 'css' ] = head[ 'cssText' ] =
-                       body[ 'appendTo' ] = body[ 'prev' ] = body[ 'next' ] = body[ 'clone' ] = body[ 'remove' ] = body[ 'kill' ] = new Function( 'return this' );
+                       body[ 'appendTo' ] = body[ 'next' ] = body[ 'clone' ] = body[ 'remove' ] = body[ 'kill' ] = 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;
+                               if( X_TEMP.X_Dom_useBuilder ) X_TEMP.X_Dom_useBuilder = !!X_elmBody.children.length;
                                !X_TEMP.X_Dom_useBuilder && X_ViewPort[ 'asyncDispatch' ]( X_EVENT_XTREE_READY );
                        } );
                        
@@ -484,24 +484,23 @@ X[ 'ViewPort' ] = {
                                var size = X_ViewPort_getWindowSize(),
                                
                                // http://jsdo.it/imaya/kTYg
-                                       body = document.body,
-                                       defaultOverflow = document.body.style.overflow,
+                                       defaultOverflow = X_elmBody.style.overflow,
                                        w, h;
                        
                                X_ViewPort_width  = size[ 0 ];
                                X_ViewPort_height = size[ 1 ];
                        
-                               body.style.overflow = 'hidden';
-                               w = body.clientWidth;
-                               h = body.clientHeight;
+                               X_elmBody.style.overflow = 'hidden';
+                               w = X_elmBody.clientWidth;
+                               h = X_elmBody.clientHeight;
                        
-                               body.style.overflow = 'scroll';
-                               w -= body.clientWidth;
-                               h -= body.clientHeight;
+                               X_elmBody.style.overflow = 'scroll';
+                               w -= X_elmBody.clientWidth;
+                               h -= X_elmBody.clientHeight;
                        
-                               if( !w ) w = body.offsetWidth  - body.clientWidth;
-                               if( !h ) h = body.offsetHeight - body.clientHeight;
-                               body.style.overflow = defaultOverflow; 
+                               if( !w ) w = X_elmBody.offsetWidth  - X_elmBody.clientWidth;
+                               if( !h ) h = X_elmBody.offsetHeight - X_elmBody.clientHeight;
+                               X_elmBody.style.overflow = defaultOverflow; 
                        
                                X_ViewPort_vScrollbarSize = w;
                                X_ViewPort_hScrollbarSize = h;
@@ -538,13 +537,10 @@ X[ 'ViewPort' ] = {
 console.log( '------------------->' );
 
                        if( document[ 'webkitHidden' ] !== undefined ){
-                               console.log( '--> has webkitvisibilitychange' );
                                X_EventDispatcher_systemListen( X_ViewPort_document, 'webkitvisibilitychange', X_ViewPort );
                        } else
                        if( document[ 'hidden' ] !== undefined ){// iOS 7+
-                               console.log( '--> has visibilitychange' );
                                X_EventDispatcher_systemListen( X_ViewPort_document, 'visibilitychange', X_ViewPort );
-                               document.onvisibilitychange = function(){ console.log( '!!!!!!!!!!!!!!!!' ) };
                        } else
                        if( document[ 'msHidden' ] !== undefined ){
                                X_EventDispatcher_systemListen( X_ViewPort_document, 'msvisibilitychange', X_ViewPort );
@@ -554,12 +550,10 @@ console.log( '------------------->' );
                        };
                        
                        if( window[ 'onpageshow' ] !== undefined ){
-                               console.log( '-------------------> pageshow, pagehide' );
                                X_EventDispatcher_systemListen( X_ViewPort, [ 'pageshow', 'pagehide' ] );
                        };
                        
                        if( document[ 'onfocusin' ] !== undefined ){
-                               console.log( '-------------------> focusin, focusout' );
                                // https://github.com/ai/visibilityjs/blob/master/lib/visibility.fallback.js
                                X_EventDispatcher_systemListen( X_ViewPort_document, [ 'focusin', 'focusout' ], X_ViewPort );
                        };
@@ -595,13 +589,13 @@ if( X_UA_EVENT.W3C ){
 } else
 if( 6 <= X_UA[ 'IE' ] && X[ 'inHead' ] && !X_UA[ 'ieExeComError' ] ){ // standalone の除外 ->  && !X_UA[ 'ieExeComError' ]
        // if this script in Head
-       document.write( '<script id=__ieonload defer src=javascript:void(0)></script>' );
-       X_TEMP._script = document.getElementById( '__ieonload' );
+       //document.write( '<script id=__ieonload defer src=javascript:void(0)></script>' );
+       //X_TEMP._script = document.getElementById( '__ieonload' );
        
        // 上のコードはスタンドアローン版ie6でエラー
-    //X_TEMP._script = document.createElement( '<script id=__ieonload defer src=javascript:void(0)></script>' ) ;
-    //document.getElementsByTagName( 'head' )[ 0 ].appendChild( X_TEMP._script );
-    
+    X_TEMP._script = document.createElement( '<script id=__ieonload defer src=javascript:void(0)></script>' );
+    X_elmHead.appendChild( X_TEMP._script );
+
        X_TEMP._script.onreadystatechange = function(){
                var s = X_TEMP._script;
                if( s && s.readyState === 'complete' ){