var X_ViewPort_readyState,
- X_ViewPort_active = ( window.parent === window ) || !window.parent, // parent は frameに読み込まれた場合のieのerror回避
+ X_ViewPort_active = ( window.parent === window ) || !window.parent, // parent は frameに読み込まれた場合のieのerror回避
X_ViewPort_activeTimerID,
X_ViewPort_rootElement,
X_ViewPort_lock,
{
'handleEvent' : function( e ){
- var href, i, name, active = false, xnode;
+ var href, i, name, active = false, elm, xnode;
switch( e.type ){
case 'beforeunload' :
- // ie では a href='javascript' な要素でも 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;
+ if( X_Type_isString( href ) && !href.toLowerCase().indexOf( 'javascript:' ) ) return X_CALLBACK_PREVENT_DEFAULT | X_CALLBACK_STOP_PROPAGATION;
return X_ViewPort[ 'dispatch' ]( X_EVENT_BEFORE_UNLOAD );
//https://developer.mozilla.org/ja/docs/Web/JavaScript/A_re-introduction_to_JavaScript
//Firefox 1.5 の bfcache が無効になりますので、他に理由がない限り Firefox では unload リスナを登録するべきではないことに注意してください。
X_ViewPort[ 'dispatch' ]( X_EVENT_UNLOAD );
- //alert('unload');
+ //alert('unload');
X_ViewPort_document[ 'kill' ]();
- this[ 'kill' ]();
-
+ X_ViewPort[ 'kill' ]();
//X_System[ 'dispatch' ]( X_EVENT_SHUT_DOWN );
break;
case 'blur' :
case 'focusout' :
- if( X_UA[ 'IE' ] < 9 ){
- xnode = X_Node_getXNode( document.activeElement );
+ if( X_UA[ 'IE' ] < 9 && ( elm = FocusUtility_getFocusedElement() ) ){
+ xnode = X_Node_getXNode( elm );
if( xnode ){
xnode[ 'listenOnce' ]( [ 'focus', 'blur' ], X_ViewPort_detectFocusForIE );
//break;
);
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 = FocusUtility_getFocusedElement();
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 );
};
+// TODO EventDispatcherProxy
/**
* window に相当する ViewPort 情報を提供するオブジェクト。
* @namespace 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(){
// http://orera.g.hatena.ne.jp/edvakf/20100515/1273908051
//http://onozaty.hatenablog.com/entry/20060803/p1
// Safari2.0.4では標準・互換どちらも document.body
+ // http://hisasann.com/housetect/2008/08/jqueryheightwidthopera95.html このdocument.body[ "client" + name ]はおそらくOpera9.5未満のバージョンで有効なんじゃないかな?
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]' )
+ new Function( 'return[X_elmBody.clientWidth,X_elmBody.clientHeight]' )
) :*/
return [
X_ViewPort_rootElement.scrollWidth || X_ViewPort_rootElement.offsetWidth,
( 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 ];
} ),
/**
* http://sssslide.com/www.slideshare.net/hiroakiwakamatsu/ss-12718639
*
*
- * getBoundingClientRect で fontsize の調査
+ * getBoundingClientRect で fontsize の調査
*/
var X_ViewPort_resize =
// iOS もループで回す,,,iOS3.1.3, iOS6 で確認
};
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 );
// 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 )
+ * X.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.split( '.' ).join( '_' ) );
html[ '_flags' ] |= X_NodeFlags_IN_TREE;
/**
- * Node( head )
+ * X.Node( head )
* @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 )
+ * X.Node( body )
* @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 ];
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;
!X_TEMP.X_Dom_useBuilder && X_ViewPort[ 'asyncDispatch' ]( X_EVENT_XTREE_READY );
} );
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;
- if( h <= 0 ){ // ie6, ie11, firefox で 負の値が返る
+ if( h <= 0 ){ // ie6, ie11, firefox で 負の値が返る
console.log( 'invalid hScrollbarSize: ' + h );
X_ViewPort_hScrollbarSize = w;
};
//
if( X_ViewPort_orientationchange ){
- X_EventDispatcher_systemListen( X_ViewPort, 'orientationchange', X_ViewPort_orientationchange );
+ X_ViewPort[ 'listen' ]( 'orientationchange', X_ViewPort_orientationchange );
};
if( X_ViewPort_detectFontSize ){
- X_EventDispatcher_systemListen( X_ViewPort, 'resize', X_ViewPort_resize );
+ X_ViewPort[ 'listen' ]( 'resize', X_ViewPort_resize );
X_Timer_add( 333, X_ViewPort_detectFontSize );
} else {
X_Timer_add( 333, X_ViewPort_resize );
X_ViewPort[ 'asyncDispatch' ]( X_ViewPort_readyState = X_EVENT_XDOM_READY );
} );
- X_ViewPort[ 'asyncDispatch' ]( X_EVENT_PRE_INIT );
-
-
- X_EventDispatcher_systemListen( X_ViewPort, [ 'beforeunload', 'unload' ] );
+ if( X_TEMP.X_Dom_useBuilder ) X_TEMP.X_Dom_useBuilder = !!X_elmBody.children.length;
+ X_ViewPort[ 'asyncDispatch' ]( X_EVENT_PRE_INIT );
-//ブラウザの戻るボタンで戻ったときに呼ばれるイベントとかキャッシュとかそこらへんのこと
-//http://d.hatena.ne.jp/koumiya/20080916/1221580149
+ X_ViewPort[ 'listen' ]( [ 'beforeunload', 'unload' ] );
-console.log( '------------------->' );
+ //ブラウザの戻るボタンで戻ったときに呼ばれるイベントとかキャッシュとかそこらへんのこと
+ //http://d.hatena.ne.jp/koumiya/20080916/1221580149
- 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( '!!!!!!!!!!!!!!!!' ) };
+ X_ViewPort_document[ 'listen' ]( 'visibilitychange', X_ViewPort );
+ } else
+ if( document[ 'webkitHidden' ] !== undefined ){
+ X_ViewPort_document[ 'listen' ]( 'webkitvisibilitychange', X_ViewPort );
} else
if( document[ 'msHidden' ] !== undefined ){
- X_EventDispatcher_systemListen( X_ViewPort_document, 'msvisibilitychange', X_ViewPort );
+ X_ViewPort_document[ 'listen' ]( 'msvisibilitychange', X_ViewPort );
} else
if( document[ 'mozHidden' ] !== undefined ){
- X_EventDispatcher_systemListen( X_ViewPort_document, 'mozvisibilitychange', X_ViewPort );
+ // TODO Firefox + Android2 でブラウザにフォーカスが戻ったことが判らない...
+ X_ViewPort_document[ 'listen' ]( 'mozvisibilitychange', X_ViewPort );
};
if( window[ 'onpageshow' ] !== undefined ){
- console.log( '-------------------> pageshow, pagehide' );
- X_EventDispatcher_systemListen( X_ViewPort, [ 'pageshow', 'pagehide' ] );
+ X_ViewPort[ 'listen' ]( [ '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 );
+ X_ViewPort_document[ 'listen' ]( [ 'focusin', 'focusout' ], X_ViewPort );
};
- X_EventDispatcher_systemListen( X_ViewPort, [ 'focus', 'blur' ] );
+ // TODO activeElement が無い対策
+ if( !FocusUtility_docActiveElmSupport ){
+ X_ViewPort[ 'listen' ]( 'focus', X_ViewPort_fixActiveElm );
+ };
+
+ X_ViewPort[ 'listen' ]( [ 'focus', 'blur' ] );
return X_CALLBACK_UN_LISTEN;
};
+ function X_ViewPort_fixActiveElm( e ){
+ // textNode を修正して elm にする処理は EventDisptcher に入っている
+ FocusUtility_fixActiveElm = e.target[ '_rawObject' ];
+ };
+
function X_ViewPort_getWindowSize(){
return X_UA[ 'IE' ] ? // Opera10.1 では ズーム時に表示領域のサイズが取れない!
[ X_ViewPort_rootElement.clientWidth, X_ViewPort_rootElement.clientHeight ] :
if( X_UA_EVENT.W3C ){
X_ViewPort_document[ 'listenOnce' ]( 'DOMContentLoaded', X_TEMP.onDomContentLoaded );
} else
-if( 6 <= X_UA[ 'IE' ] && X[ 'inHead' ] && !X_UA[ 'ieExeComError' ] ){ // standalone の除外 -> && !X_UA[ 'ieExeComError' ]
+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' ){