From dd02887497fa95f13d112b7fc2e5e7aefd0ffb08 Mon Sep 17 00:00:00 2001 From: itozyun Date: Thu, 16 Oct 2014 16:56:31 +0900 Subject: [PATCH] Version 0.6.106, bugfix for X.EventDispatcher, cleanup X.Node, Image JSONP for Opera12(?)- and supporting Error Eventfor X.Net.JSONP. --- 0.6.x/js/01_core/13_XEventDispatcher.js | 7 +- 0.6.x/js/01_core/16_XViewPort.js | 79 ++++++++++++++--------- 0.6.x/js/02_dom/02_XNode.js | 54 ++++++++-------- 0.6.x/js/02_dom/03_XDomEvent.js | 6 +- 0.6.x/js/02_dom/04_XBoxModel.js | 22 +++---- 0.6.x/js/02_dom/05_XNodeAttr.js | 4 +- 0.6.x/js/02_dom/06_XNodeCSS.js | 99 ++++++++++++---------------- 0.6.x/js/02_dom/08_XNodeSelector.js | 5 +- 0.6.x/js/05_util/01_XNinjaIframe.js | 5 +- 0.6.x/js/06_net/02_XNetJSONP.js | 104 ++++++++++++++++-------------- 0.6.x/js/06_net/04_XNetImage.js | 16 ++--- 0.6.x/js/07_audio/01_XHTML5Audio.js | 14 ++-- 0.6.x/js/07_audio/02_XSilverlightAudio.js | 4 +- 13 files changed, 219 insertions(+), 200 deletions(-) diff --git a/0.6.x/js/01_core/13_XEventDispatcher.js b/0.6.x/js/01_core/13_XEventDispatcher.js index 19a52af..7ff83b3 100644 --- a/0.6.x/js/01_core/13_XEventDispatcher.js +++ b/0.6.x/js/01_core/13_XEventDispatcher.js @@ -57,6 +57,7 @@ X.EventDispatcher = * @memberof X.EventDispatcher */ + // TODO _rawObjectType EventTarget, XHR, Silverlight, ... /** * イベントリスナをイベント名(string)や数値(1~,フレームワーク内で定義)をキーとするArrayで記憶します。 * Arrayには、{k:種類,x:コンテキスト(thisObject),f:関数,s:サプリメントする引数の配列} というハッシュ、または関数が蓄えられています。 @@ -333,6 +334,8 @@ function X_EventDispatcher_dispatch( e ){ function X_EventDispatcher_listen( type, opt_arg1, opt_arg2, opt_arg3 ){ var list = this._listeners, i, raw, add, f; + + if( !type ) return this; if( this._dispatching ){ if( !this._reserves ) this._reserves = []; @@ -350,7 +353,7 @@ function X_EventDispatcher_listen( type, opt_arg1, opt_arg2, opt_arg3 ){ raw = this._rawObject || X_UA_DOM.IE4 && X_Node__ie4getRawNode( this ); add = raw && ( !list || !list[ type ] ) && X.Type.isString( type ); - if( this.listening( type, opt_arg1, opt_arg2, opt_arg3 ) ) return this; + if( this.listening( type, opt_arg1 || this, opt_arg2, opt_arg3 ) ) return this; if( !list ) list = this._listeners = {}; if( !( list = list[ type ] ) ) list = this._listeners[ type ] = []; @@ -374,6 +377,8 @@ function X_EventDispatcher_systemListen( that, type, opt_arg1, opt_arg2, opt_arg X_EventDispatcher_lock = false; }; +// TODO this.listen(type) は this リスナの登録なのに、this.unlisten(type)は全てのtypeの削除、と不一致 + /** * * @this {X.EventDispatcher} diff --git a/0.6.x/js/01_core/16_XViewPort.js b/0.6.x/js/01_core/16_XViewPort.js index 5161c23..6eb62df 100644 --- a/0.6.x/js/01_core/16_XViewPort.js +++ b/0.6.x/js/01_core/16_XViewPort.js @@ -12,7 +12,7 @@ var X_ViewPort_readyState, 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; }; }, @@ -25,6 +25,8 @@ var X_ViewPort_readyState, }, X_ViewPort_document = new X.EventDispatcher( document ), + + X_ViewPort_postMessageAccessKey = Math.random() * 10000 | 0, X_ViewPort = X_Class_override( new X.EventDispatcher( window ), @@ -34,34 +36,51 @@ X_ViewPort = X_Class_override( var href; 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 ); + case '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.asyncDispatch( ( X_ViewPort_active = document[ 'hidden' ] ) ? 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.asyncDispatch( ( 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.asyncDispatch( 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.asyncDispatch( X.Event.VIEW_DEACTIVATE ); + }; + break; + + // TODO + case 'message' : + if( e.origin !== X.URL.BASE_URL ){ + + } else { + e.data; + }; break; }; } @@ -77,8 +96,9 @@ X.ViewPort = { /* * 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 +109,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; @@ -132,7 +152,7 @@ X.ViewPort = { //http://onozaty.hatenablog.com/entry/20060803/p1 // Safari2.0.4では標準・互換どちらも document.body - X_Node_body._updateTimerID && X_Node_startUpdate(); + X_Node_updateTimerID && X_Node_startUpdate(); /*X_UA.Opera ? ( document.documentElement && document.documentElement.clientWidth ? new Function( 'return[document.documentElement.clientWidth,document.documentElement.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; }; @@ -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,7 +260,7 @@ 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; @@ -336,11 +356,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 ); @@ -354,25 +374,22 @@ X.ViewPort = { console.log( 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 ); + X_EventDispatcher_systemListen( X_ViewPort_document, 'visibilitychange', X_ViewPort ); } else if( document[ 'webkitHidden' ] !== undefined ) { - X_ViewPort_document.listen( 'webkitvisibilitychange', X_ViewPort ); + 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 ); + 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; diff --git a/0.6.x/js/02_dom/02_XNode.js b/0.6.x/js/02_dom/02_XNode.js index 233ee62..22c8f03 100644 --- a/0.6.x/js/02_dom/02_XNode.js +++ b/0.6.x/js/02_dom/02_XNode.js @@ -4,9 +4,9 @@ var CHILD_IS_DIRTY : 1, ID : 2, // width, height, x, y CONTENT : 4, // width, height, x, y textNode の内容 - CLASSNAME : 8, // _getCharSize, width, height, x, y - ATTR : 16, // _getCharSize, width, height, x, y - CSS : 32, // _getCharSize, width, height, x, y + CLASSNAME : 8, // X_Node_CSS_getCharSize, width, height, x, y + ATTR : 16, // X_Node_CSS_getCharSize, width, height, x, y + CSS : 32, // X_Node_CSS_getCharSize, width, height, x, y IE_FILTER : X_UA.IE < 9 && !X_UA.MacIE ? 64 : 0, UNKNOWN_TAG_FIX : 128, IE4_TEXTNODE_FIX : 256 @@ -15,8 +15,8 @@ var X_Node_State = { DESTROYED : 0, EXIST : 1, // XNODE_EXIDT, ELEMENT_EXIST - BELONG_TREE : 2, // HAS_PARENT, BELONG_TREE_XNODE, BELONG_TREE_ELEMENT - DISPLAY_NONE : 4, // VISIVILITY_HIDDEN & DISPALY_NONE + BELONG_TREE : 2, // HAS_PARENT, HAS_PARENT_ACTUAL, BELONG_TREE, BELONG_TREE_ACTUAL + DISPLAY_NONE : 4, // VISIVILITY_HIDDEN(opacity0), DISPALY_NONE DISPLAY_BLOCK : 8, // remove DISPLAY_INLINE : 16,// remove POSITION_ABSOLUTE : 32, @@ -46,11 +46,13 @@ var X_Node_useDocumentFragment = document.createDocumentFragment && ( !X_UA.IE || 5.5 <= X_UA.IE ) && document.createDocumentFragment(), - X_Node_newByTag = false, + X_Node_newByTag = false, - X_Node_newByText = false, + X_Node_newByText = false, - X_Node_outerXNode = null, + X_Node_outerXNode = null, + + X_Node_updateTimerID = 0, /* * Node( rawElement | rawTextnode | htmlString | textString ) */ @@ -960,21 +962,20 @@ function X_Node_each( func /*, opt_args */ ){ */ function X_Node_reserveUpdate(){ - var root = X_Node_body; - if( root && !root._updateTimerID ) root._updateTimerID = X.Timer.requestFrame( X_Node_startUpdate ); + if( !X_Node_updateTimerID ) X_Node_updateTimerID = X.Timer.requestFrame( X_Node_startUpdate ); }; function X_Node_startUpdate(){ var removal, i, xnode, tmp; - if( X_ViewPort_readyState < X_TEMP.SYSTEM_EVENT_INIT ){ - return; - }; - if( X_Node_body._updateTimerID ){ - X.Timer.cancelFrame( X_Node_body._updateTimerID ); - X_Node_body._updateTimerID = 0; - } else { + + if( !X_Node_updateTimerID || X_ViewPort_readyState < X_TEMP.SYSTEM_EVENT_INIT ){ return; }; + + X.Timer.cancelFrame( X_Node_updateTimerID ); + X_Node_updateTimerID = 0; + + // このイベントでサイズを取ると無限ループに // X_ViewPort._listeners && X_ViewPort._listeners[ X.Event.BEFORE_UPDATE ] && X_ViewPort.dispatch( X.Dom.Event.BEFORE_UPDATE ); @@ -1033,9 +1034,6 @@ var X_Node__commitUpdate = frg.appendChild( X_Node__actualCreate( xnodes[ i ], true ) ); }; elm.appendChild( frg ); - for( i = 0; i < l; ++i ){ - X_Node__actualCreate( xnodes[ i ], true ); - }; } else {*/ for( ; l; ){ next = X_Node__commitUpdate( xnodes[ --l ], elm, next ); @@ -1123,6 +1121,7 @@ var X_Node__updateRawNode = return; }; }; + // style // TODO display:none の場合、更新をスキップ if( that._dirty & X_Node_Dirty.CSS ){ @@ -1208,9 +1207,9 @@ var X_Node__updateRawNode = for( k in attrs ){ ( v = attrs[ k ] ) === undefined ? elm.removeAttribute( rename[ k ] || k ) : - that._tag === 'TEXTAREA' && k === 'value' ? - ( elm.innerText = v ) : - elm.setAttribute( rename[ k ] || k, X_Node_Attr_noValue[ k ] ? k : v ); // TODO X_Node_Attr_noValue[ k ] ? k : v + //that._tag === 'TEXTAREA' && k === 'value' ? + // ( elm.innerText = v ) : + elm.setAttribute( rename[ k ] || k, X_Node_Attr_noValue[ k ] ? k : v ); }; delete that._newAttrs; }; @@ -1398,9 +1397,9 @@ var X_Node__actualRemove = }; if( !elm ) return; - that._xnodeType === 1 && X_EventDispatcher_toggleAllEvents( that, false );// イベントの退避 - // elm.parentNode.tagName for ie7 + that._listeners && X_EventDispatcher_toggleAllEvents( that, false );// イベントの退避 if( !X_UA.MacIE ){ + // elm.parentNode.tagName for ie7 -> that.state & BELONG_TREE_ACTUAL !isChild && elm.parentNode && elm.parentNode.tagName && elm.parentNode.removeChild( elm ); } else { !isChild && elm.parentNode && elm.parentNode.tagName && X_TEMP._fixed_remove( elm, that ); @@ -1418,7 +1417,7 @@ var X_Node__actualRemove = }; if( !elm ) return; - that._xnodeType === 1 && X_EventDispatcher_toggleAllEvents( that, false );// イベントの退避 + that._listeners && X_EventDispatcher_toggleAllEvents( that, false );// イベントの退避 if( X_Node_Attr_HAS_VALUE[ that._tag ] && ( !that._newAttrs || !X_Object_inObject( 'value', that._newAttrs ) ) ){ that._attrs.value = elm.value; @@ -1429,3 +1428,6 @@ var X_Node__actualRemove = delete that._rawObject; }) : (function(){}); + +X_ViewPort.listenOnce( X.Event.UNLOAD, X_Node__actualRemove, [ X_Node_html, true ] ); + diff --git a/0.6.x/js/02_dom/03_XDomEvent.js b/0.6.x/js/02_dom/03_XDomEvent.js index c221472..540ed81 100644 --- a/0.6.x/js/02_dom/03_XDomEvent.js +++ b/0.6.x/js/02_dom/03_XDomEvent.js @@ -274,6 +274,9 @@ if( !X_UA.IE || 9 <= X_UA.IE ){ }; this.buttons = e.button; + this.deltaX = 0; + this.deltaY = e.wheelDelta / -120; + if( type = X_Event_toPointer[ originalType ] ){ this.type = type; this.clientX = e.clientX; @@ -297,9 +300,6 @@ if( !X_UA.IE || 9 <= X_UA.IE ){ // this.offsetX = e.x - e.srcElement.offsetLeft; // e.x はイベント発生要素の親要素を基準にした座標。 // this.offsetY = e.y - e.srcElement.offsetTop; //}; - - this.deltaX = 0; - this.deltaY = e.wheelDelta / -120; this.pointerId = 1; this.radiusX = 0; diff --git a/0.6.x/js/02_dom/04_XBoxModel.js b/0.6.x/js/02_dom/04_XBoxModel.js index 639ed3a..f7fa20b 100644 --- a/0.6.x/js/02_dom/04_XBoxModel.js +++ b/0.6.x/js/02_dom/04_XBoxModel.js @@ -53,7 +53,7 @@ Node.prototype.width = function(){ console.log( 'xnode.width() : no parent' ); return 0; }; - X_Node_body._updateTimerID && X_Node_startUpdate(); + X_Node_updateTimerID && X_Node_startUpdate(); if( !this._root ){ console.log( 'xnode.width() : not belong tree.' ); return 0; @@ -75,7 +75,7 @@ Node.prototype.height = function(){ console.log( 'xnode.height() : no parent' ); return 0; }; - X_Node_body._updateTimerID && X_Node_startUpdate(); + X_Node_updateTimerID && X_Node_startUpdate(); if( !this._root ){ console.log( 'xnode.height() : not belong tree.' ); return 0; @@ -97,7 +97,7 @@ Node.prototype.clientWidth = function(){ console.log( 'xnode.width() : no parent' ); return 0; }; - X_Node_body._updateTimerID && X_Node_startUpdate(); + X_Node_updateTimerID && X_Node_startUpdate(); if( !this._root ){ console.log( 'xnode.width() : not belong tree.' ); return 0; @@ -119,7 +119,7 @@ Node.prototype.clientHeight = function(){ console.log( 'xnode.height() : no parent' ); return 0; }; - X_Node_body._updateTimerID && X_Node_startUpdate(); + X_Node_updateTimerID && X_Node_startUpdate(); if( !this._root ){ console.log( 'xnode.height() : not belong tree.' ); return 0; @@ -141,7 +141,7 @@ Node.prototype.scrollWidth = function(){ console.log( 'xnode.width() : no parent' ); return 0; }; - X_Node_body._updateTimerID && X_Node_startUpdate(); + X_Node_updateTimerID && X_Node_startUpdate(); if( !this._root ){ console.log( 'xnode.width() : not belong tree.' ); return 0; @@ -163,7 +163,7 @@ Node.prototype.scrollHeight = function(){ console.log( 'xnode.height() : no parent' ); return 0; }; - X_Node_body._updateTimerID && X_Node_startUpdate(); + X_Node_updateTimerID && X_Node_startUpdate(); if( !this._root ){ console.log( 'xnode.height() : not belong tree.' ); return 0; @@ -185,7 +185,7 @@ Node.prototype.scrollLeft = function(){ console.log( 'xnode.scrollLeft() : no parent' ); return 0; }; - X_Node_body._updateTimerID && X_Node_startUpdate(); + X_Node_updateTimerID && X_Node_startUpdate(); if( !this._root ){ console.log( 'xnode.scrollLeft() : not belong tree.' ); return 0; @@ -207,7 +207,7 @@ Node.prototype.scrollTop = function(){ console.log( 'xnode.scrollTop() : no parent' ); return 0; }; - X_Node_body._updateTimerID && X_Node_startUpdate(); + X_Node_updateTimerID && X_Node_startUpdate(); if( !this._root ){ console.log( 'xnode.scrollTop() : not belong tree.' ); return 0; @@ -237,7 +237,7 @@ Node.prototype.x = function(){ console.log( 'xnode.x() : no parent' ); return 0; }; - X_Node_body._updateTimerID && X_Node_startUpdate(); + X_Node_updateTimerID && X_Node_startUpdate(); if( !this._root ){ console.log( 'xnode.x() : not belong tree.' ); return 0; @@ -260,7 +260,7 @@ Node.prototype.y = function(){ console.log( 'xnode.y() : no parent' ); return 0; }; - X_Node_body._updateTimerID && X_Node_startUpdate(); + X_Node_updateTimerID && X_Node_startUpdate(); if( !this._root ){ console.log( 'xnode.y() : not belong tree.' ); return 0; @@ -285,7 +285,7 @@ Node.prototype.offset = function( /* xnodeParent */ ){ console.log( 'xnode.offset() : no parent' ); return { x : 0, y : 0 }; }; - X_Node_body._updateTimerID && X_Node_startUpdate(); + X_Node_updateTimerID && X_Node_startUpdate(); if( !this._root ){ console.log( 'xnode.offset() : not belong tree.' ); return { x : 0, y : 0 }; diff --git a/0.6.x/js/02_dom/05_XNodeAttr.js b/0.6.x/js/02_dom/05_XNodeAttr.js index 6c23b0b..5a5f16f 100644 --- a/0.6.x/js/02_dom/05_XNodeAttr.js +++ b/0.6.x/js/02_dom/05_XNodeAttr.js @@ -45,7 +45,9 @@ X_Node_Attr_HAS_VALUE = { INPUT : true, TEXTAREA : true, SELECT : true, - BUTTON : true + BUTTON : true, + OBJECT : true, + PARAM : true // FlashVars が flash 側から書き換えられるケースがある }, X_Node_Attr_renameForTag = {}; diff --git a/0.6.x/js/02_dom/06_XNodeCSS.js b/0.6.x/js/02_dom/06_XNodeCSS.js index 7fa9641..f0f3309 100644 --- a/0.6.x/js/02_dom/06_XNodeCSS.js +++ b/0.6.x/js/02_dom/06_XNodeCSS.js @@ -367,7 +367,7 @@ X_Node_CSS_Property = X.Class.create( if( u !== 'px' ){ this.value = u === 'em' ? - v / this.xnode._getCharSize() : + v / X_Node_CSS_getCharSize( this.xnode ) : v / ( X_Node_CSS__UNIT_RATIO[ u ] || 1 ); }; }, @@ -392,7 +392,7 @@ X_Node_CSS_Property = X.Class.create( u === 'px' ? v : ( u === 'em' || ( u === '' && this.name === 'lineHeight' ) ) ? - v * this.xnode._getCharSize() : + v * X_Node_CSS_getCharSize( this.xnode ) : // u === '%' v / ( X_Node_CSS__UNIT_RATIO[ u ] || 1 ); }, @@ -1067,85 +1067,85 @@ Node.prototype.cssText = function( v ){ * TODO * body に css attr がセットされた場合には X_ViewPort_baseFontSize をクリア */ - -Node.prototype._getCharSize = +var +X_Node_CSS_getCharSize = window.getComputedStyle ? - (function(){ - X_Node_body._updateTimerID && X_Node_startUpdate(); - if( this === X_Node_body && X_ViewPort_baseFontSize ) return X_ViewPort_baseFontSize; - if( this._fontSize ) return this._fontSize; - return this._fontSize = parseFloat( getComputedStyle( this._rawObject, null ).fontSize ); + (function( that ){ + X_Node_updateTimerID && X_Node_startUpdate(); + if( that === X_Node_body && X_ViewPort_baseFontSize ) return X_ViewPort_baseFontSize; + if( that._fontSize ) return that._fontSize; + return that._fontSize = parseFloat( getComputedStyle( that._rawObject, null ).fontSize ); }) : document.defaultView && document.defaultView.getComputedStyle ? - (function(){ - X_Node_body._updateTimerID && X_Node_startUpdate(); - if( this === X_Node_body && X_ViewPort_baseFontSize ) return X_ViewPort_baseFontSize; - if( this._fontSize ) return this._fontSize; - return this._fontSize = parseFloat( document.defaultView.getComputedStyle( this._rawObject, null ).fontSize ); + (function( that ){ + X_Node_updateTimerID && X_Node_startUpdate(); + if( that === X_Node_body && X_ViewPort_baseFontSize ) return X_ViewPort_baseFontSize; + if( that._fontSize ) return that._fontSize; + return that._fontSize = parseFloat( document.defaultView.getComputedStyle( that._rawObject, null ).fontSize ); }) : 5.5 <= X_UA.IE ? - (function(){ + (function( that ){ var font, vu, v, u, _v; - X_Node_body._updateTimerID && X_Node_startUpdate(); - if( this === X_Node_body && X_ViewPort_baseFontSize ) return X_ViewPort_baseFontSize; - if( this._fontSize ) return this._fontSize; + X_Node_updateTimerID && X_Node_startUpdate(); + if( that === X_Node_body && X_ViewPort_baseFontSize ) return X_ViewPort_baseFontSize; + if( that._fontSize ) return that._fontSize; - font = this._rawObject.currentStyle.fontSize; - //font = this._css && this._css.fontSize || '1em'; + font = that._rawObject.currentStyle.fontSize; + //font = that._css && that._css.fontSize || '1em'; vu = X_Node_CSS__splitValueAndUnit( font ); v = vu[ 0 ]; u = vu[ 1 ]; if( v === 0 ){ - if( v = X_Node_CSS__FONT_SIZE_RATIO[ font ] ) return this._fontSize = v; + if( v = X_Node_CSS__FONT_SIZE_RATIO[ font ] ) return that._fontSize = v; } else { - if( _v = X_Node_CSS__UNIT_RATIO[ u ] ) return this._fontSize = v / _v; + if( _v = X_Node_CSS__UNIT_RATIO[ u ] ) return that._fontSize = v / _v; }; switch( u ){ case 'px' : - return this._fontSize = v; + return that._fontSize = v; case 'em' : // body まで辿ってしまった場合は? - if( this.parent ) return this._fontSize = this.parent._getCharSize() * v; + if( that.parent ) return that._fontSize = X_Node_CSS_getCharSize( that.parent ) * v; break; case '%' : // body まで辿ってしまった場合は? - if( this.parent ) return this._fontSize = this.parent._getCharSize() * v / 100; + if( that.parent ) return that._fontSize = X_Node_CSS_getCharSize( that.parent ) * v / 100; }; return 0; }) : X_UA_DOM.W3C ? - (function(){ + (function( that ){ var elm, v; - X_Node_body._updateTimerID && X_Node_startUpdate(); - if( this === X_Node_body && X_ViewPort_baseFontSize ) return X_ViewPort_baseFontSize; - if( this._fontSize ) return this._fontSize; + X_Node_updateTimerID && X_Node_startUpdate(); + if( that === X_Node_body && X_ViewPort_baseFontSize ) return X_ViewPort_baseFontSize; + if( that._fontSize ) return that._fontSize; - this._rawObject.appendChild( elm = document.createElement( 'span' ) ); + that._rawObject.appendChild( elm = document.createElement( 'span' ) ); elm.style.cssText = 'display:block;position:absolute;top:0;left:0;visivility:hidden;line-height:1;height:1em;'; elm.innerHTML = 'X'; v = elm.offsetHeight; - this._rawObject.removeChild( elm ); - return this._fontSize = v; + that._rawObject.removeChild( elm ); + return that._fontSize = v; }) : X_UA_DOM.IE4 ? - (function(){ + (function( that ){ var font, vu, v, u, _v; - X_Node_body._updateTimerID && X_Node_startUpdate(); - if( this === X_Node_body && X_ViewPort_baseFontSize ) return X_ViewPort_baseFontSize; - if( this._fontSize ) return this._fontSize; + X_Node_updateTimerID && X_Node_startUpdate(); + if( that === X_Node_body && X_ViewPort_baseFontSize ) return X_ViewPort_baseFontSize; + if( that._fontSize ) return that._fontSize; - if( this._css && ( font = this._css.fontSize ) ){ + if( that._css && ( font = that._css.fontSize ) ){ vu = X_Node_CSS__splitValueAndUnit( font ); v = vu[ 0 ]; u = vu[ 1 ]; if( v === 0 ){ - if( _v = X_Node_CSS__FONT_SIZE_RATIO[ font ] ) return this._fontSize = _v; + if( _v = X_Node_CSS__FONT_SIZE_RATIO[ font ] ) return that._fontSize = _v; } else { - if( _v = X_Node_CSS__UNIT_RATIO[ u ] ) return this._fontSize = v / _v; + if( _v = X_Node_CSS__UNIT_RATIO[ u ] ) return that._fontSize = v / _v; }; } else { v = 1; @@ -1154,31 +1154,18 @@ Node.prototype._getCharSize = switch( u ){ case 'px' : - return this._fontSize = v; + return that._fontSize = v; case 'em' : // body まで辿ってしまった場合は? - if( this.parent ) return this._fontSize = this.parent._getCharSize() * v; + if( that.parent ) return that._fontSize = X_Node_CSS_getCharSize( that.parent ) * v; break; case '%' : // body まで辿ってしまった場合は? - if( this.parent ) return this._fontSize = this.parent._getCharSize() * v / 100; + if( that.parent ) return that._fontSize = X_Node_CSS_getCharSize( that.parent ) * v / 100; }; return 0; }) : - // ie5? - (function(){ - var elm, v; - if( this === X_Node_body && X_ViewPort_baseFontSize ) return X_ViewPort_baseFontSize; - X_Node_body._updateTimerID && X_Node_startUpdate(); - if( this._fontSize ) return this._fontSize; - - elm = this._rawObject; - elm.insertAdjacentHTML( 'BeforeEnd', 'X' ); - elm = elm.children[ elm.children.length - 1 ]; - v = elm.offsetHeight; - elm.outerHTML = ''; - return this._fontSize = v * 0.75; - }); + 0; X.CSS = { diff --git a/0.6.x/js/02_dom/08_XNodeSelector.js b/0.6.x/js/02_dom/08_XNodeSelector.js index 1d1dbb7..2a746ff 100644 --- a/0.6.x/js/02_dom/08_XNodeSelector.js +++ b/0.6.x/js/02_dom/08_XNodeSelector.js @@ -56,7 +56,10 @@ var // TODO { a : 1, A : 2, _ : 3,,, } X_Node_Selector__ALPHABET = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-0123456789\\', X_Node_Selector__NUMBER = '+-0123456789'; - + +// XMLWrapper のために今だけ外部に公開 +X_NodeSelector_parse = X_Node_Selector__parse; + /* * セレクタ文字列の解析、但し一挙に行わず、ひと塊づつ * 結合子 + 単体セレクタ( タグ,*,#,.,[],: ) diff --git a/0.6.x/js/05_util/01_XNinjaIframe.js b/0.6.x/js/05_util/01_XNinjaIframe.js index 5624baa..93f62f1 100644 --- a/0.6.x/js/05_util/01_XNinjaIframe.js +++ b/0.6.x/js/05_util/01_XNinjaIframe.js @@ -54,7 +54,10 @@ X.Util.NinjaIframe = X.EventDispatcher.inherits( switch( e.type ){ case X.Event.AFTER_UPDATE : - this._iwin = raw.contentWindow || raw.contentDocument && raw.contentDocument.parentWindow || window.frames[ this._name ]; + this._iwin = raw.contentWindow || ( raw.contentDocument && raw.contentDocument.parentWindow ) || window.frames[ this._name ]; + // http://d.hatena.ne.jp/NeoCat/20080921/1221940658 + // こちらに名前をsetしないとtargetが動作しない + this._iwin.name = this._name; this.xnodeIframe.listen( X_UA.IE < 9 ? [ 'readystatechange', 'error' ] : [ 'load', 'error' ], this ); diff --git a/0.6.x/js/06_net/02_XNetJSONP.js b/0.6.x/js/06_net/02_XNetJSONP.js index 13bd9e5..806396c 100644 --- a/0.6.x/js/06_net/02_XNetJSONP.js +++ b/0.6.x/js/06_net/02_XNetJSONP.js @@ -37,7 +37,9 @@ X.Net.JSONP = { var X_NET_JSONP_ACCESS_KEY = Math.random(), - X_NET_JSONP_NinjaIframe; + X_NET_JSONP_NinjaIframe, + + X_Net_JSONP_onloadCount; function X_NET_JSONP_loadScriptInNinjaIframe( url ){ @@ -48,35 +50,56 @@ function X_NET_JSONP_loadScriptInNinjaIframe( url ){ X_NET_JSONP_NinjaIframe || ( X_NET_JSONP_NinjaIframe = new X.Util.NinjaIframe() ); // TODO ' 化 恐らくアンチウイルスソフトが反応しないための対策 - + // TODO postMessage の利用 + + // numonLoad + + if( X_UA.Opera ){ + html = [ + ( window[ 'JSON' ] ? '' : '' ), + '', + '', + '' + ]; + X_Net_JSONP_onloadCount = 2; + } else if( X_UA.IE8 ){ html = [ // http://blog.livedoor.jp/dankogai/archives/51503830.html // Ajax - IE8にもJSON入ってます。使えるとは限らないけど // Compatibility mode (別名Quirks mode) では、JSONオブジェクトは無効になります。iframeもだめです - /* 以下のコードは XP ie8 では動くけど、win8 IE11(8モード)で動かない 開発の便宜を取って,setTimeout を挟む - '', - '' */ '', '' + + /* 以下のコードは XP ie8 では動くけど、win8 IE11(8モード)で動かない 開発の便宜を取って,setTimeout を挟む + '', + '' */ ]; + X_Net_JSONP_onloadCount = 2; } else if( X_UA.IE9 ){ html = [ '', '' ]; + X_Net_JSONP_onloadCount = 2; } else if( window[ 'JSON' ] ){ html = [ @@ -86,30 +109,35 @@ function X_NET_JSONP_loadScriptInNinjaIframe( url ){ '', '' ]; + X_Net_JSONP_onloadCount = 1; } else if( X_UA.IE4 || X_UA.MacIE ){ html = [ '', '', '' ]; + X_Net_JSONP_onloadCount = 3; } else if( X_UA.IE < 8 ){ // ie5-7 html = [ '', '', '' ]; + X_Net_JSONP_onloadCount = 3; } else { html = [ '', '' ]; + X_Net_JSONP_onloadCount = 1; }; X_NET_JSONP_NinjaIframe @@ -130,14 +159,18 @@ function X_NET_JSONP_loadScriptInNinjaIframe( url ){ function X_NET_JSONP_iframeListener( e ){ switch( e.type ){ case X.Event.SUCCESS : - console.log( 'iframe onload' ); - + console.log( 'iframe onload, but' ); + if( ++X_NET_JSONPWrapper._onloadCount < X_Net_JSONP_onloadCount ) return; + // TODO callback が無ければ error + X_NET_JSONPWrapper.asyncDispatch( 1000, X.Event.ERROR ); break; case X.Event.ERROR : console.log( 'iframe onerror' ); - X_NET_JSONPWrapper.asyncDispatch( 0, X.Event.ERROR ); + X_NET_JSONPWrapper.asyncDispatch( X.Event.ERROR ); break; }; + X_NET_JSONP_NinjaIframe.unlisten(); + return X.Callback.UN_LISTEN; }; @@ -145,51 +178,24 @@ X_NET_JSONPWrapper = X_Class_override( new X.EventDispatcher(), { - _operaImage : null, // X.Net.Image(); _busy : false, _canceled : false, + _onloadCount : 0, load : function( url, data, timeout ){ //createURL - if( X_NET_JSONP_operaImageHandleEvent ){ - this._operaImage = X.Net.Image( url, false ) - .listenOnce( [ X.Event.SUCCESS, X.Event.ERROR, X.Event.TIMEOUT ], X_NET_JSONP_operaImageHandleEvent ); - } else { - X_NET_JSONP_loadScriptInNinjaIframe( url ); - }; + X_NET_JSONP_loadScriptInNinjaIframe( url ); this._busy = true; }, cancel : function(){ - if( this._operaImage ){ - this._operaImage - .unlisten( [ X.Event.SUCCESS, X.Event.ERROR, X.Event.TIMEOUT ], X_NET_JSONP_operaImageHandleEvent ) - .cancel(); - delete this._operaImage; - } else { - this._canceled = true; - }; + this._canceled = true; }, reset : function(){ this._busy = this._canceled = false; + this._onloadCount = 0; } } ); - -function X_NET_JSONP_operaImageHandleEvent( e ){ - switch( e.type ){ - case X.Event.SUCCESS : - case X.Event.ERROR : - X_NET_JSONP_loadScriptInNinjaIframe( e.src ); - break; - case X.Event.TIMEOUT : - X_NET_JSONPWrapper._operaImage - .unlisten( [ X.Event.SUCCESS, X.Event.ERROR, X.Event.TIMEOUT ], X_NET_JSONP_operaImageHandleEvent ) - .reset(); - X_NET_JSONPWrapper.asyncDispatch( 0, X.Event.ERROR ); - break; - }; -}; -if( !X_UA.Opera ) X_NET_JSONP_operaImageHandleEvent = null; \ No newline at end of file diff --git a/0.6.x/js/06_net/04_XNetImage.js b/0.6.x/js/06_net/04_XNetImage.js index 6a90a46..853ec82 100644 --- a/0.6.x/js/06_net/04_XNetImage.js +++ b/0.6.x/js/06_net/04_XNetImage.js @@ -43,24 +43,15 @@ X_NET_ImageWrapper = X_Class_override( this.abspath = X.URL.toAbsolutePath( data.url ); this.delay = data.delay || 100; this.timeout = data.timeout || 5000; - this.timerID = X.Timer.add( this.delay, 0, this, this._detect ); - - //X_Net_Image_hasImage ? ( this._rawObject.src = this.abspath ) : this.attr( 'src', this.abspath ); - /* - if( X_UA.Opera7 ){ - X_EventDispatcher_toggleAllEvents( this, false ); - this._rawObject = new Image(); - X_EventDispatcher_toggleAllEvents( this, true ); - }; */ - + //this.timerID = X.Timer.add( this.delay, 0, this, this._detect ); + this._rawObject.src = this.abspath; - //alert( this._rawObject.src + ' ' + this._rawObject.complete ); + if( X_UA.Opera7 && this._rawObject.complete ){ this.asyncDispatch( 'load' ); } else { this.timerID = X.Timer.add( this.delay, 0, this, this._detect ); }; - //alert( this._rawObject.src + ' ' + this._rawObject.complete ); }, handleEvent : function( e ){ @@ -119,6 +110,7 @@ X_NET_ImageWrapper = X_Class_override( cancel : function(){ // abort がある? this._rawObject && this._rawObject.abort && this._rawObject.abort(); + // this._rawObject.src = ''; this._busy = false; this.finish = true; this.asyncDispatch( X.Event.CANCELED ); diff --git a/0.6.x/js/07_audio/01_XHTML5Audio.js b/0.6.x/js/07_audio/01_XHTML5Audio.js index 536e229..3bce85d 100644 --- a/0.6.x/js/07_audio/01_XHTML5Audio.js +++ b/0.6.x/js/07_audio/01_XHTML5Audio.js @@ -53,21 +53,21 @@ if( window.HTMLAudioElement ){ var ok, mineType = 'audio/' + ext; switch( ext ){ case 'mp3' : - ok = X.UA.IE || X.UA.Chrome || X.UA.Safari; //( X.UA.OS === 'windows' && X.UA.Safari ); + ok = X_UA.IE || X_UA.Chrome || X_UA.Safari; //( X_UA.OS === 'windows' && X_UA.Safari ); mineType = 'audio/mpeg'; break; case 'ogg' : - ok = 15 <= X.UA.Gecko || X.UA.Chrome || X.UA.Opera; + ok = 15 <= X_UA.Gecko || X_UA.Chrome || X_UA.Opera; break; case 'm4a' : - ok = X.UA.IE || X.UA.WebKit; + ok = X_UA.IE || X_UA.WebKit; mineType = 'audio/mp4'; break; case 'webm' : - ok = 2 <= X.UA.Gecko || 10.6 <= X.UA.Opera; // firefox4+(Gecko2+) + ok = 2 <= X_UA.Gecko || 10.6 <= X_UA.Opera; // firefox4+(Gecko2+) break; case 'wav' : - ok = X.UA.Gecko || X.UA.Opera || X.UA.Safari; //( X.UA.OS === 'windows' && X.UA.Safari ); + ok = X_UA.Gecko || X_UA.Opera || X_UA.Safari; //( X_UA.OS === 'windows' && X_UA.Safari ); //mineType = 'audio/wav'; // audio/x-wav ? break; default : @@ -236,7 +236,7 @@ if( window.HTMLAudioElement ){ if( this._closed ) return; this._lastUserAction = 'play'; - if( X.UA.Chrome ){ // [CHROME][FIX] volume TODO どの version で 修正される? + if( X_UA.Chrome ){ // [CHROME][FIX] volume TODO どの version で 修正される? // [!] delay X.Timer.once( 0, this, this._fixForChrome, [ this._rawObject.volume ] ); this._rawObject.volume = 0; @@ -249,7 +249,7 @@ if( window.HTMLAudioElement ){ }, // [CHROME][FIX] volume - _fixForChrome : X.UA.Chrome && function( volume ){ + _fixForChrome : X_UA.Chrome && function( volume ){ !this._closed && ( this._rawObject.volume = volume ); }, diff --git a/0.6.x/js/07_audio/02_XSilverlightAudio.js b/0.6.x/js/07_audio/02_XSilverlightAudio.js index 3eb6538..484a900 100644 --- a/0.6.x/js/07_audio/02_XSilverlightAudio.js +++ b/0.6.x/js/07_audio/02_XSilverlightAudio.js @@ -129,6 +129,8 @@ if( X.Pulgin.SilverlightEnabled ){ * http://www.atmarkit.co.jp/fdotnet/dotnettips/902slobjcallfromjs/slobjcallfromjs.html * このページのサンプルは sl5+firefox32 環境で動いている。xaml を js から利用する形ではなく、.xap を sl4 以下で作るのがよさそう. */ + + // TODO embed this.proxy = proxy; this._onload = 'XAudioSilverlightOnLoad' + ( ++X_Audio_SLAudio_uid ); this._callback = window[ this._onload ] = X_Callback_create( this, this.onSLReady, [ option.autoplay ] ); @@ -162,7 +164,7 @@ if( X.Pulgin.SilverlightEnabled ){ window[ this._onload ] = null; delete this._onload; - this._callback.kill(); + X_Callback_correct( this._callback ); delete this._callback; //if( sender.findName('media') ) alert( 'exist' ); -- 2.11.0