From 08e72a61fa7363b2fb04f5bc863df082c3067e47 Mon Sep 17 00:00:00 2001 From: itozyun Date: Thu, 4 Sep 2014 07:12:26 +0900 Subject: [PATCH] Version 0.6.73, move ._rawNode from X.Dom.Event to X.EventDispatcher. --- 0.6.x/js/00_core/01_XUa.js | 4 +- 0.6.x/js/00_core/02_XType.js | 2 +- 0.6.x/js/00_core/04_XClass.js | 26 ++- 0.6.x/js/00_core/06_XEventDispatcher.js | 401 ++++++++++++++++++++++++-------- 0.6.x/js/00_core/07_XNotification.js | 2 +- 0.6.x/js/01_dom/10_XDom.js | 14 +- 0.6.x/js/01_dom/11_XDomNode.js | 2 +- 0.6.x/js/01_dom/12_XDomEvent.js | 152 ++---------- 0.6.x/js/01_dom/15_XDomStyle.js | 20 +- 0.6.x/js/10_ui/06_AbstractUINode.js | 6 +- 0.6.x/js/10_ui/15_ScrollBox.js | 3 +- 11 files changed, 376 insertions(+), 256 deletions(-) diff --git a/0.6.x/js/00_core/01_XUa.js b/0.6.x/js/00_core/01_XUa.js index 04bf643..a9e659b 100644 --- a/0.6.x/js/00_core/01_XUa.js +++ b/0.6.x/js/00_core/01_XUa.js @@ -184,9 +184,11 @@ X.UA = (function( n, undefined ){ console.log( '>> Webkit : ' + acme.WebKit + ' Safari : ' + acme.Safari ); }; + // TODO 3DS, DSi, WiiU + // Mozilla/5.0 (Android; Linux armv7l; rv:9.0) Gecko/20111216 Firefox/9.0 Fennec/9.0 if( ( i = dua.toLowerCase().indexOf( 'android' ) ) !== -1 ){ - acme.Android = parseFloat( dua.substr( i + 8 ) ) || 1.5; + acme.Android = parseFloat( dua.substr( i + 8 ) ) || 0; console.log( '>> Android : ' + acme.Android ); } else if( dua.indexOf( 'iPhone;' ) !== -1 || dua.indexOf( 'iPad;' ) !== -1 || dua.indexOf( 'iPod;' ) !== -1 ){ diff --git a/0.6.x/js/00_core/02_XType.js b/0.6.x/js/00_core/02_XType.js index c8e1980..1861709 100644 --- a/0.6.x/js/00_core/02_XType.js +++ b/0.6.x/js/00_core/02_XType.js @@ -35,7 +35,7 @@ X.Type = { }, isNumber : function( v ){ - return typeof v === 'number'; v !== v || v + 0 === v; + return typeof v === 'number'; // v !== v || v + 0 === v; }, isFinite : function( v ){ diff --git a/0.6.x/js/00_core/04_XClass.js b/0.6.x/js/00_core/04_XClass.js index f4497b0..2de9d36 100644 --- a/0.6.x/js/00_core/04_XClass.js +++ b/0.6.x/js/00_core/04_XClass.js @@ -17,8 +17,9 @@ X.Class = ( function(){ CONSTRUCTOR = 'Constructor', killPrivateFlag = false, traits = null, + useObjectCreate = false, // !!Object.create, http://jsperf.com/prototype-vs-object-create-perf use__proto__ = !!X.emptyFunction.prototype.__proto__; - + _DEF_LIST = DEF_LIST; /* サブクラスを作るメソッド * var subClass = superClass.inherits( ... ) * http://d.hatena.ne.jp/m-hiyama/20051018/1129605002 @@ -47,7 +48,8 @@ X.Class = ( function(){ if( X.Type.isNumber( classSetting ) ){ args.shift(); } else { - classSetting = superDef.setting; + // クラス設定がない場合、親からコピーして、Abstract flag は落とす?? + classSetting = superDef.setting;// &= ~X.Class.ABSTRACT; }; if( superDef.isPrivate ) classSetting = classSetting | X.Class.PRIVATE_DATA; opt_super = !!( classSetting & X.Class.SUPER_ACCESS ); @@ -63,6 +65,9 @@ X.Class = ( function(){ params.push( args[ 0 ] ); /* props サブクラスでは未定義でも可 */ // 継承クラスの作成 + if( useObjectCreate ){ + traits = Object.create( Super.prototype ); + } else if( use__proto__ ){ traits = Super.prototype; } else { @@ -84,7 +89,10 @@ X.Class = ( function(){ return klass; }; - /* X.Class.create で作られたクラスのインスタンスが共通で備えるメソッド */ + /* X.Class.create で作られたクラスのインスタンスが共通で備えるメソッド + * + * + */ var CommonProps = { kill : function(){ var instance = this, @@ -155,7 +163,11 @@ X.Class = ( function(){ return; }; klass.__new = null; - instance = def.pool && def.pool.length > 0 ? def.pool.pop() : new klass(); + instance = def.pool && def.pool.length > 0 ? + def.pool.pop() : + useObjectCreate ? + Object.create( klass.prototype ) : + new klass(); klass.__new = C; if( def.isPrivate === true ){ userDef = X.Class._getClassDef( dataUser ); @@ -175,7 +187,7 @@ X.Class = ( function(){ def[ CONSTRUCTOR ].apply( instance, args ) : def.SuperConstructor && def.SuperConstructor.apply( instance, args ); - if( X.Type.isObject( obj ) ){ + if( X.Type.isObject( obj ) && obj !== instance ){ instance.kill(); return obj; }; @@ -257,6 +269,10 @@ X.Class = ( function(){ klass.superClassOf = X.Class._superClassOf; klass.subClassOf = X.Class._subClassOf; + if( useObjectCreate ){ + klass.prototype = X.Class._override( X.Class._override( traits || klass.prototype, props, true ), CommonProps, false ); + klass.prototype.constructor = klass; + } else if( use__proto__ ){ X.Class._override( klass.prototype, props, true ); if( traits ){ diff --git a/0.6.x/js/00_core/06_XEventDispatcher.js b/0.6.x/js/00_core/06_XEventDispatcher.js index 067e217..b1134d7 100644 --- a/0.6.x/js/00_core/06_XEventDispatcher.js +++ b/0.6.x/js/00_core/06_XEventDispatcher.js @@ -1,4 +1,10 @@ /** + * X.EventDispatcher + * + * 1. as3 の EventDispatcher ライクなクラス。そのまま使ったり、継承したり。コールバック中にイベントを追加したら?削除したら?にも対処している。 + * 2. _rawObject メンバがいる場合、addEventListener, attachEvent, on 等で生のブラウザオブジェクトにリスナを登録する。 + * window, document, HTMLElement, Image, XHR などが _rawObject + * * use X.Callback * * https://developer.mozilla.org/ja/docs/Web/API/EventTarget.addEventListener @@ -19,118 +25,118 @@ X.Event = { BEFORE_CANCEL : 5, CANCELED : 6, TIMEOUT : 7, + // INSTANCE_KILLED + // KILL_INSTANCE_CANCELED _LAST_EVENT : 7 }; +// --- define / local variables ---------------------------- +var x_eventdispatcher_once = false, + x_eventdispatcher_needsIndex = false, + x_eventdispatcher_temp = {}; + +if( X.UA.MacIE ){ + x_eventdispatcher_temp.DOM_W3C = true; + x_eventdispatcher_temp.EVENT_DOM0 = true; +} else +if( X.UA.IE4 ){ // ie4 & iemobi4 + x_eventdispatcher_temp.DOM_IE4 = true; + x_eventdispatcher_temp.EVENT_DOM0 = true; +} else +if( document.getElementById ){ + x_eventdispatcher_temp.DOM_W3C = true; + if( document.addEventListener ){ + x_eventdispatcher_temp.EVENT_W3C = true; + } else + if( document.attachEvent ){ + x_eventdispatcher_temp.EVENT_IE = true; + } else { + x_eventdispatcher_temp.EVENT_DOM0 = true; + }; +} else +if( document.all ){ + x_eventdispatcher_temp.DOM_IE4 = true; + x_eventdispatcher_temp.EVENT_DOM0 = true; +} else +if( document.layers ){ + +} else { + +}; +/** + * イベントターゲットをラップする場合(widnow, document, Image, XHR 等)、通常は new 時に渡します。参照:コンストラクタ実体 {@link X.EventDispatcher.Constructor} + * アプリケーション独自のイベントをやり取りしたいだけ、という場合、イベントターゲットは不要です。 + * @constructor + * @classdesc EventTarget オブジェクトをラップしたり、アプリケーションで独自に定義したイベントを発信するためのクラスです。 + * listen, unlisten, dispatch という addEventListener, removeEventListener, dispatchEvent に対応する関数を持ちます。さらに listening という as3 の hasEventListener に相当する関数を持ちます。 + * as3 の EventDispatcher に相当する機能に加え、イベントターゲットオブジェクト(widnow, document, HTMLElement, XHR 等)が設定されていた場合に、それらへ実際のイベント登録・解除も行います。 + * このイベントの登録・解除はクロスブラウザ対策が施されていて、IE5~8の独自イベントの差異を吸収し、DOM0 に対しても複数のイベントリスナを登録します。 + * さらに、コールバックに対して、this コンテキストや、追加の引数を指定できます。 this コンテキストを指定しなかった場合、EventDispatcher インスタンスがコールバック関数の this になります。 + * @param {object=} opt_argument + */ X.EventDispatcher = X.Class.create( 'EventDispatcher', { + + /** + * @namespace + * @memberof X.EventDispatcher + */ + + /** + * イベントリスナをイベント名(string)や数値(1~,フレームワーク内で定義)をキーとするArrayで記憶します。 + * Arrayには、{k:種類,x:コンテキスト(thisObject),f:関数,s:サプリメントする引数の配列} というハッシュ、または関数が蓄えられています。 + * @private + * @type {Object.<(number|string), Array.<(callbackDef|function)>>} + */ _listeners : null, - _dispatching : 0, // dispatch 中の unlisten で使用 - _unlistens : null, // dispatch 中の unlisten で使用 - _needsIndex : false, // listening で index を返す - _reserves : null, + + /** + * _rawObject には HTMLElement, window, document, XHR といったイベントターゲットオブジェクトを設定します。 + * _rawObject が設定されていると on(), off() 時に addEventListener(DOM Level2) や detachEvent(ie5~8), on~(DOM0) 等を操作します。 + * _rawObject は最初の on() 前に設定しておかないと addEventListener 等が意図したように行われません。 + * X.Dom.Node では非同期に HTMLElement を生成していて、要素生成以前に on, off を呼び出すことができます。これは適宜に migrateEvent, restoreEvent を呼んで解決しているためです。 + * @private + * @type {Object} + */ + _rawNode : null, + _handleEvent : null, + + _dispatching : 0, // dispatch 中の unlisten で使用 + _unlistens : null, // dispatch 中の unlisten で使用 + _reserves : null, // dispatch中に unlisten されたイベントリスナ _killReserved : false, - listen : function( type, arg1, arg2, arg3 ){ - var list = this._listeners, - i, r, f; - if( this._dispatching ){ - if( !this._reserves ) this._reserves = []; - this._reserves[ this._reserves.length ] = [ type, arg1, arg2, arg3, X.EventDispatcher._once ]; - return this; - }; - - if( X.Type.isArray( type ) ){ - for( i = type.length; i; ){ - this.listen( type[ --i ], arg1, arg2, arg3 ); - }; - return this; + /** + * X.EventDispatcher のコンストラクタの実体。 + * @private + * @this {X.EventDispatcher} + */ + Constructor : function( rawObject ){ + if( rawObject ){ + this._rawNode = rawObject; }; - - if( this.listening( type, arg1, arg2, arg3 ) ) return this; - - if( !list ) list = this._listeners = {}; - if( !( list = list[ type ] ) ) list = this._listeners[ type ] = []; - - f = X.Callback._classifyCallbackArgs( arg1, arg2, arg3, this ); - list[ list.length ] = f; - f.once = X.EventDispatcher._once; - - return this; }, + + /** + * + * @this {X.EventDispatcher} + */ + on : x_eventdispatcher_on, + listen : x_eventdispatcher_on, + listenOnce : function( type, arg1, arg2, arg3 ){ - X.EventDispatcher._once = true; + x_eventdispatcher_once = true; this.listen( type, arg1, arg2, arg3 ); - X.EventDispatcher._once = false; - return this; - }, - unlisten : function( type, arg1, arg2, arg3 ){ - var list = this._listeners, - _list, reserves, unlistens, i, f; - if( !list ) return this; - - if( X.Type.isArray( type ) ){ - for( i = type.length; i; ){ - this.unlisten( type[ --i ], arg1, arg2, arg3 ); - }; - return this; - }; - - if( type === undefined ){ - // 全て削除 - for( type in list ){ - _list = list[ type ]; - for( i = _list.length; i; ){ - this.unlisten( type, _list[ --i ] ); // override されていることがあるので、必ず unlisten を使用 - }; - // this.unlisten( type ); これは無茶! - }; - return this; - } else - if( arg1 === undefined ){ - // 同一タイプを全て削除 - if( _list = list[ type ] ){ - for( i = _list.length; i; ){ - this.unlisten( type, _list[ --i ] ); // override されていることがあるので、必ず unlisten を使用 - }; - }; - return this; - } else - if( reserves = this._reserves ){ - for( i = reserves.length; i; ){ - f = reserves[ --i ]; - if( f[ 0 ] === type && f[ 1 ] === arg1 && f[ 2 ] === arg2 && f[ 3 ] === arg3 ){ - reserves.splice( i, 1 ); - if( !reserves.legth ) delete this._reserves; - return this; - }; - }; - }; - - this._needsIndex = true; - i = this.listening( type, arg1, arg2, arg3 ); - delete this._needsIndex; - if( i === false ) return this; - - f = ( _list = list[ type ] )[ i ]; - if( unlistens = this._unlistens ){ - ( unlistens = unlistens[ type ] ) ? - ( unlistens[ unlistens.length ] = f ) : - ( this._unlistens[ type ] = [ f ] ); - } else { - delete f.once; - f.kill === X.Callback._kill && f.kill(); - _list.splice( i, 1 ); - if( !_list.length ){ - delete this._listeners[ type ]; - if( X.isEmptyObject( this._listeners ) ) delete this._listeners; - }; - }; + x_eventdispatcher_once = false; return this; }, + + off : x_eventdispatcher_off, + unlisten : x_eventdispatcher_off, + listening : function( type, arg1, arg2, arg3 ){ var list = this._listeners, unlistens, i, f, hash; if( type === undefined ) return !!list; @@ -151,7 +157,7 @@ X.EventDispatcher = }; for( i = list.length; i; ){ f = list[ --i ]; - if( f === hash || ( f.x === hash.x && f.f === hash.f && f.s === hash.s ) ) return this._needsIndex ? i : true; + if( f === hash || ( f.x === hash.x && f.f === hash.f && f.s === hash.s ) ) return x_eventdispatcher_needsIndex ? i : true; }; return false; }, @@ -233,9 +239,9 @@ X.EventDispatcher = if( list = this._reserves ){ for( i = 0, l = list.length; i < l; ++i ){ f = list[ i ]; - X.EventDispatcher._once = f[ 4 ]; + x_eventdispatcher_once = f[ 4 ]; this.listen( f[ 0 ], f[ 1 ], f[ 2 ], f[ 3 ] ); - X.EventDispatcher._once = false; + x_eventdispatcher_once = false; f.length = 0; }; list.length = 0; @@ -260,9 +266,202 @@ X.EventDispatcher = } ); -X.EventDispatcher.prototype.on = X.EventDispatcher.prototype.listen; -X.EventDispatcher.prototype.off = X.EventDispatcher.prototype.unlisten; -X.EventDispatcher._once = false; +// --- implements ------------------------------------------ +function x_eventdispatcher_on( type, arg1, arg2, arg3 ){ + var list = this._listeners, + i, r, f; + + if( this._dispatching ){ + if( !this._reserves ) this._reserves = []; + this._reserves[ this._reserves.length ] = [ type, arg1, arg2, arg3, x_eventdispatcher_once ]; + return this; + }; + + if( X.Type.isArray( type ) ){ + for( i = type.length; i; ){ + this.listen( type[ --i ], arg1, arg2, arg3 ); + }; + return this; + }; + + ( !list || !list[ type ] ) && X.Type.isString( type ) && x_eventdispatcher_actualAddEvent( this, type ); + + if( this.listening( type, arg1, arg2, arg3 ) ) return this; + + if( !list ) list = this._listeners = {}; + if( !( list = list[ type ] ) ) list = this._listeners[ type ] = []; + + f = X.Callback._classifyCallbackArgs( arg1, arg2, arg3, this ); + list[ list.length ] = f; + f.once = x_eventdispatcher_once; + + return this; +}; + +function x_eventdispatcher_off( type, arg1, arg2, arg3 ){ + var list = this._listeners, + _list, reserves, unlistens, i, f; + if( !list ) return this; + + if( X.Type.isArray( type ) ){ + for( i = type.length; i; ){ + this.unlisten( type[ --i ], arg1, arg2, arg3 ); + }; + return this; + }; + + if( type === undefined ){ + // 全て削除 + for( type in list ){ + _list = list[ type ]; + for( i = _list.length; i; ){ + this.unlisten( type, _list[ --i ] ); // override されていることがあるので、必ず unlisten を使用 + }; + // this.unlisten( type ); これは無茶! + }; + return this; + } else + if( arg1 === undefined ){ + // 同一タイプを全て削除 + if( _list = list[ type ] ){ + for( i = _list.length; i; ){ + this.unlisten( type, _list[ --i ] ); // override されていることがあるので、必ず unlisten を使用 + }; + }; + return this; + } else + if( reserves = this._reserves ){ + for( i = reserves.length; i; ){ + f = reserves[ --i ]; + if( f[ 0 ] === type && f[ 1 ] === arg1 && f[ 2 ] === arg2 && f[ 3 ] === arg3 ){ + reserves.splice( i, 1 ); + if( !reserves.legth ) delete this._reserves; + return this; + }; + }; + }; + + x_eventdispatcher_needsIndex = true; + i = this.listening( type, arg1, arg2, arg3 ); + x_eventdispatcher_needsIndex = false; + if( i === false ) return this; + + f = ( _list = list[ type ] )[ i ]; + if( unlistens = this._unlistens ){ + ( unlistens = unlistens[ type ] ) ? + ( unlistens[ unlistens.length ] = f ) : + ( this._unlistens[ type ] = [ f ] ); + } else { + delete f.once; + f.kill === X.Callback._kill && f.kill(); + _list.splice( i, 1 ); + if( !_list.length ){ + delete this._listeners[ type ]; + X.Type.isString( type ) && x_eventdispatcher_actualRemoveEvent( this, type ); + if( X.isEmptyObject( this._listeners ) ) delete this._listeners; + }; + }; + return this; +}; + + +x_eventdispatcher_actualAddEvent = + // Days on the Moon DOM Events とブラウザの実装 + // http://nanto.asablo.jp/blog/2007/03/23/1339502 + // Safari 2 では関数オブジェクトしか EventListener として使えませんが、Safari のナイトリービルドでは handleEvent メソッドを持つオブジェクトも EventListener として使えるようです。 + x_eventdispatcher_temp.EVENT_W3C && ( X.UA.WebKit < 525.13 || X.UA.Opera7 || X.UA.NetFront < 4 ) ? // Safari3- + (function( that, type ){ + var raw = that._rawNode; + if( !raw ) return; + that._handleEvent = that._handleEvent || X.Callback.create( that ); + type = X.Dom.Event.Rename[ type ] || type; + if( raw.addEventListener ){ + raw.addEventListener( type, that._handleEvent, false ); + } else { + // Safari は Image, Opera7 は window + raw[ 'on' + type ] = that._handleEvent; + }; + }) : + x_eventdispatcher_temp.EVENT_W3C ? + (function( that, type ){ + that._rawNode && that._rawNode.addEventListener( X.Dom.Event.Rename[ type ] || type, that, false ); + }) : + x_eventdispatcher_temp.EVENT_IE ? + (function( that, type ){ + var raw = that._rawNode; + if( !raw ) return; + type = X.Dom.Event.Rename[ type ] || type; + //if( type === 'load' && that._tag && X.Dom.Event._LOAD_FIX_TAGS[ that._tag ] ){ + // type = 'readystatechange'; + //}; + that._handleEvent = that._handleEvent || X.Callback.create( that ); + if( raw.attachEvent ){ + raw.attachEvent( 'on' + type, that._handleEvent ); + } else { + raw[ 'on' + type ] = that._handleEvent; + }; + }) : + (function( that, type ){ + var raw = that._rawNode || ( that._ie4getRawNode && that._ie4getRawNode() ); + if( !raw ) return; + raw[ 'on' + ( X.Dom.Event.Rename[ type ] || type ) ] = that._handleEvent = that._handleEvent || X.Callback.create( that ); + }); + + +x_eventdispatcher_actualRemoveEvent = + x_eventdispatcher_temp.EVENT_W3C && ( X.UA.WebKit < 525.13 || X.UA.Opera7 || X.UA.NetFront < 4 ) ? // Safari3- + (function( that, type ){ + var raw = that._rawNode; + if( !raw ) return; + type = X.Dom.Event.Rename[ type ] || type; + + if( raw.addEventListener ){ // Image + raw.removeEventListener( type, that._handleEvent, false ); + } else { + raw[ 'on' + type ] = null; + }; + if( !that._listeners ){ + X.Callback._correct( that._handleEvent ); + delete that._handleEvent; + }; + }) : + x_eventdispatcher_temp.EVENT_W3C ? + (function( that, type ){ + var raw = that._rawNode; + if( !raw ) return; + raw.removeEventListener( X.Dom.Event.Rename[ type ] || type, that, false ); + }) : + x_eventdispatcher_temp.EVENT_IE ? + (function( that, type ){ + var raw = that._rawNode; + if( !raw ) return; + type = X.Dom.Event.Rename[ type ] || type; + //if( type === 'load' && that._tag && X.Dom.Event._LOAD_FIX_TAGS[ that._tag ] ){ + // type = 'readystatechange'; + //}; + if( raw.attachEvent ){ + raw.detachEvent( 'on' + type, that._handleEvent ); + } else { + raw[ 'on' + type ] = X.emptyFunction; + raw[ 'on' + type ] = ''; + }; + if( !that._listeners ){ + X.Callback._correct( that._handleEvent ); + delete that._handleEvent; + }; + }) : + (function( that, type ){ + var raw = that._rawNode || ( that._ie4getRawNode && that._ie4getRawNode() ); + if( !raw ) return; + type = X.Dom.Event.Rename[ type ] || type; + raw[ 'on' + type ] = X.emptyFunction; + raw[ 'on' + type ] = ''; + if( !that._listeners ){ + X.Callback._correct( that._handleEvent ); + delete that._handleEvent; + }; + }); + console.log( 'X.Core.EventDispatcher' ); diff --git a/0.6.x/js/00_core/07_XNotification.js b/0.6.x/js/00_core/07_XNotification.js index 3653850..e566f95 100644 --- a/0.6.x/js/00_core/07_XNotification.js +++ b/0.6.x/js/00_core/07_XNotification.js @@ -32,7 +32,7 @@ X.Notification = { level === 0 ? console.debug( msg ) : level === 1 ? console.info( msg ) : level === 2 ? console.warn( msg ) : - level === 3 ? console.critical( msg ) : console.warn( msg ); + level === 3 ? console.warn( msg ) : console.warn( msg ); } else { 1 < level && alert( msg ); }; diff --git a/0.6.x/js/01_dom/10_XDom.js b/0.6.x/js/01_dom/10_XDom.js index 51443ea..9ab72de 100644 --- a/0.6.x/js/01_dom/10_XDom.js +++ b/0.6.x/js/01_dom/10_XDom.js @@ -19,6 +19,18 @@ X.Dom = X.Class._override( * https://w3g.jp/blog/studies/ios7_1_minimal-ui_warning * iOS7.0からあったiPad Safariの高さ100%コンテンツでlandscape(横向き)時に起きる不具合 * + * http://tenderfeel.xsrv.jp/javascript/1182/ + * アドレスバーの高さの算出 + * + * http://sssslide.com/www.slideshare.net/hiroakiwakamatsu/javascript-14514208 + * 1. 傾き時の画面サイズ取得ー 対処方法の例 + * (1)ー• タイマーを使って、画面サイズ取得の タイミングを少しだけ遅延させる + * window.onorientationchange = function() { setTimeout(function() { alert("W: " + window.innerWidth + ", H: " + window.innerHeight); }, 200); } + * 横に傾けた時、正常に横向け時の 幅と高さが取得できている ただし、端末によってはうまく取得できな い場合がある(Galaxy S IIIとか・・・) 7 + * + * http://sssslide.com/www.slideshare.net/hiroakiwakamatsu/ss-12718639 + * + * * getBoundingClientRect で fontsize の調査 */ _resize : @@ -205,7 +217,7 @@ X.Dom = X.Class._override( */ X.Dom.asyncDispatch( 0, { type : type, w : X.Dom.w, h : X.Dom.h } ); }; - return X.EventDispatcher.prototype.listen.apply( X.Dom, arguments ); + return x_eventdispatcher_on.apply( X.Dom, arguments ); }, getPointerPosition : function(){ diff --git a/0.6.x/js/01_dom/11_XDomNode.js b/0.6.x/js/01_dom/11_XDomNode.js index ec7a949..e40d14f 100644 --- a/0.6.x/js/01_dom/11_XDomNode.js +++ b/0.6.x/js/01_dom/11_XDomNode.js @@ -6,7 +6,7 @@ X.Dom.Dirty = { CLASSNAME : 8, // _getCharSize, width, height, x, y ATTR : 16, // _getCharSize, width, height, x, y CSS : 32, // _getCharSize, width, height, x, y - IE_FILTER : X.UA.IE && X.UA.IE < 9 && !X.UA.MacIE ? 64 : 0, + IE_FILTER : X.UA.IE < 9 && !X.UA.MacIE ? 64 : 0, UNKNOWN_TAG_FIX : 128, IE4_TEXTNODE_FIX : 256 }; diff --git a/0.6.x/js/01_dom/12_XDomEvent.js b/0.6.x/js/01_dom/12_XDomEvent.js index d0f93ac..591c479 100644 --- a/0.6.x/js/01_dom/12_XDomEvent.js +++ b/0.6.x/js/01_dom/12_XDomEvent.js @@ -46,9 +46,9 @@ if( !X.UA.IE || 9 <= X.UA.IE ){ // axis // https://w3g.jp/blog/tools/wheelevent_crossbrowser // ホイール系イベント2014年版クロスブラウザ - if( e.deltaY ){ - this.deltaX = e.deltaX; - this.deltaY = e.deltaY; + if( e.deltaY !== undefined ){ + this.deltaX = e.deltaX / 100; + this.deltaY = e.deltaY / 100; } else if( e.wheelDeltaY !== undefined ){ this.deltaX = e.wheelDeltaX / 120; @@ -56,11 +56,11 @@ if( !X.UA.IE || 9 <= X.UA.IE ){ } else if( e.wheelDelta !== undefined ){ this.deltaX = 0; - this.deltaY = -e.wheelDelta / 120; + this.deltaY = e.wheelDelta / -120; } else if( e.detail !== undefined ){ this.deltaX = 0; - this.deltaY = e.type === 'MozMousePixelScroll' ? e.detail / 15 : e.detail; // 3 + this.deltaY = e.type === 'MozMousePixelScroll' ? e.detail / 45 : e.detail / 3; // 3 } else { this.deltaX = this.deltaY = 0; }; @@ -163,7 +163,7 @@ if( !X.UA.IE || 9 <= X.UA.IE ){ }; this.button = this.which - 1; this.deltaX = 0; - this.deltaY = e.wheelDelta / -12; + this.deltaY = e.wheelDelta / -120; if( this.type === 'wheel' ) console.log( e.wheelDelta ); }; @@ -218,12 +218,16 @@ if( document.onwheel === undefined ){ console.log( 'wheel <= DOMMouseScroll' ); X.Dom.Event.Rename[ 'wheel' ] = 'DOMMouseScroll'; }; - } else - if( document.onmousewheel !== undefined ){ + } else { + X.Dom.Event.Rename[ 'wheel' ] = 'mousewheel'; + }; + if( document.onmousewheel !== undefined ){ // Opera で判定失敗 X.Dom.Event.Rename[ 'wheel' ] = 'mousewheel'; - }; + }; }; + + if( window.onwebkitanimationend !== undefined && window.onanimationend === undefined ){ console.log( 'animationend <= webkitAnimationEnd' ); X.Dom.Event.Rename[ 'animationend' ] = 'webkitAnimationEnd'; @@ -288,131 +292,7 @@ if( navigator.msPointerEnabled && !navigator.pointerEnabled ){ -X.Dom.Node.prototype.listen = function( type, arg1, arg2, arg3 /* [ listener || ( context + function ) || function ][ arguments ] */ ){ - if( this._xnodeType === 0 || this._xnodeType === 3 ) return this; - - if( X.Type.isArray( type ) ){ - return X.EventDispatcher.prototype.listen.apply( this, arguments ); - }; - - ( !this._listeners || !this._listeners[ type ] ) && X.Type.isString( type ) && this._addEvent( type ); - - return X.EventDispatcher.prototype.listen.apply( this, arguments ); -}; - -X.Dom.Node.prototype._addEvent = - // Days on the Moon DOM Events とブラウザの実装 - // http://nanto.asablo.jp/blog/2007/03/23/1339502 - // Safari 2 では関数オブジェクトしか EventListener として使えませんが、Safari のナイトリービルドでは handleEvent メソッドを持つオブジェクトも EventListener として使えるようです。 - X.Dom.EVENT_W3C && ( X.UA.WebKit < 525.13 || X.UA.Opera7 || X.UA.NetFront < 4 ) ? // Safari3- - (function( type ){ - var raw = this._rawNode; - if( !raw ) return; - this._handleEvent = this._handleEvent || X.Callback.create( this ); - type = X.Dom.Event.Rename[ type ] || type; - if( raw.addEventListener ){ - raw.addEventListener( type, this._handleEvent, false ); - } else { - // Safari は Image, Opera7 は window - raw[ 'on' + type ] = this._handleEvent; - }; - }) : - X.Dom.EVENT_W3C ? - (function( type ){ - this._rawNode && this._rawNode.addEventListener( X.Dom.Event.Rename[ type ] || type, this, false ); - }) : - X.Dom.EVENT_IE ? - (function( type ){ - var raw = this._rawNode; - if( !raw ) return; - type = X.Dom.Event.Rename[ type ] || type; - //if( type === 'load' && this._tag && X.Dom.Event._LOAD_FIX_TAGS[ this._tag ] ){ - // type = 'readystatechange'; - //}; - this._handleEvent = this._handleEvent || X.Callback.create( this ); - if( raw.attachEvent ){ - raw.attachEvent( 'on' + type, this._handleEvent ); - } else { - raw[ 'on' + type ] = this._handleEvent; - }; - }) : - (function( type ){ - var raw = this._rawNode || ( this._ie4getRawNode && this._ie4getRawNode() ); - if( !raw ) return; - raw[ 'on' + ( X.Dom.Event.Rename[ type ] || type ) ] = this._handleEvent = this._handleEvent || X.Callback.create( this ); - }); - - -X.Dom.Node.prototype.unlisten = function( type, arg1, arg2, arg3 ){ - var list = this._listeners, l; - - if( X.Type.isArray( type ) ){ - return list ? X.EventDispatcher.prototype.unlisten.apply( this, arguments ) : this; - }; - - l = !this._dispatching && list && type !== undefined && list[ type ] && list[ type ].length; - - X.EventDispatcher.prototype.unlisten.apply( this, arguments ); - - l && !list[ type ] && X.Type.isString( type ) && this._removeEvent( type ); - - return this; -}; - -X.Dom.Node.prototype._removeEvent = - X.Dom.EVENT_W3C && ( X.UA.WebKit < 525.13 || X.UA.Opera7 || X.UA.NetFront < 4 ) ? // Safari3- - (function( type ){ - var raw = this._rawNode; - if( !raw ) return; - type = X.Dom.Event.Rename[ type ] || type; - - if( raw.addEventListener ){ // Image - raw.removeEventListener( type, this._handleEvent, false ); - } else { - raw[ 'on' + type ] = null; - }; - if( !this._listeners ){ - X.Callback._correct( this._handleEvent ); - delete this._handleEvent; - }; - }) : - X.Dom.EVENT_W3C ? - (function( type ){ - var raw = this._rawNode; - if( !raw ) return; - raw.removeEventListener( X.Dom.Event.Rename[ type ] || type, this, false ); - }) : - X.Dom.EVENT_IE ? - (function( type ){ - var raw = this._rawNode; - if( !raw ) return; - type = X.Dom.Event.Rename[ type ] || type; - //if( type === 'load' && this._tag && X.Dom.Event._LOAD_FIX_TAGS[ this._tag ] ){ - // type = 'readystatechange'; - //}; - if( raw.attachEvent ){ - raw.detachEvent( 'on' + type, this._handleEvent ); - } else { - raw[ 'on' + type ] = X.emptyFunction; - raw[ 'on' + type ] = ''; - }; - if( !this._listeners ){ - X.Callback._correct( this._handleEvent ); - delete this._handleEvent; - }; - }) : - (function( type ){ - var raw = this._rawNode || ( this._ie4getRawNode && this._ie4getRawNode() ); - if( !raw ) return; - type = X.Dom.Event.Rename[ type ] || type; - raw[ 'on' + type ] = X.emptyFunction; - raw[ 'on' + type ] = ''; - if( !this._listeners ){ - X.Callback._correct( this._handleEvent ); - delete this._handleEvent; - }; - }); - +// TODO handleEvent を拡張可能にするために、クロージャに移動する // Is this in regard to the Safari 1.x preventDefault bug on click/dblclick? // https://groups.google.com/forum/#!msg/comp.lang.javascript/uYEuCHjHxnw/yKoHtZJPa1QJ X.Dom.Node.prototype.handleEvent = @@ -461,7 +341,7 @@ X.Dom.Node.prototype._migrateEvent = function(){ if( !hash ) return; for( type in hash ){ // 数字イベントの除外 - /*'' + parseFloat( type ) !== type && */this._removeEvent( type ); + /*'' + parseFloat( type ) !== type && */x_eventdispatcher_actualRemoveEvent( this, type ); }; }; @@ -472,7 +352,7 @@ X.Dom.Node.prototype._restoreEvent = function(){ if( !hash ) return; for( type in hash ){ // 数字イベントの除外 - /*'' + parseFloat( type ) !== type && */ this._addEvent( type ); + /*'' + parseFloat( type ) !== type && */ x_eventdispatcher_actualAddEvent( this, type ); }; }; diff --git a/0.6.x/js/01_dom/15_XDomStyle.js b/0.6.x/js/01_dom/15_XDomStyle.js index 198598f..968557b 100644 --- a/0.6.x/js/01_dom/15_XDomStyle.js +++ b/0.6.x/js/01_dom/15_XDomStyle.js @@ -119,9 +119,10 @@ _GRNERAL FIX_PROP = me.SPECIAL_FIX_PROP, SPECIAL_FIX = me.SPECIAL_FIX, n = -1, - p, name, sp; + p, v, name, sp; if( !obj ) return ''; // Opera7.5 未満? for( p in obj ){ + // TODO Object が拡張されていると error... name = uncamelize( VENDER_PREFIX[ p ] || p ); if( FIX_PROP[ name ] ){ sp = true; @@ -1183,16 +1184,17 @@ X.Dom.Node.prototype._getCharSize = X.Dom.listenOnce( X.Dom.Event.DOM_PRE_INIT, function(){ - var testStyle = X.Dom._root.style; + var testStyle = X.Dom._root.style, + temp = testStyle.cssText; X.Dom.Style.VENDER_PREFIX = (function(){ var ret = {}, - vendors = 'webkit,Webkit,Moz,moz,ms,Ms,O,o,khtml,Khtml'.split( ',' ), + vendors = 'webkit,Webkit,Moz,moz,Ms,ms,O,o,khtml,Khtml'.split( ',' ), searches = ( 'opacity,boxSizing,' + 'transform,transformOrigin,perspective,' + 'transisiton,transitionDelay,transitionProperty,transitionDuration,transitionTimingFunction,' + - 'userSelect,touchAction,touchCallout,contentZooming,userDrag,tapHighlightColor' ).split( ',' ), + 'userSelect,touchSelect,touchAction,touchCallout,contentZooming,userDrag,tapHighlightColor' ).split( ',' ), vendor, i, search, prop, j, v; for( i = searches.length; i; ){ @@ -1203,6 +1205,8 @@ X.Dom.listenOnce( X.Dom.Event.DOM_PRE_INIT, function(){ for( j = vendors.length; j; ){ v = vendors[ --j ]; if( testStyle[ v + prop ] !== undefined ){ + if( v === 'ms' ) v = 'Ms';// for ie9 + if( v === 'o' ) v = 'O';//for opera12 ret[ search ] = v + prop; break; }; @@ -1214,6 +1218,14 @@ X.Dom.listenOnce( X.Dom.Event.DOM_PRE_INIT, function(){ return ret; })(); + testStyle.cssText = 'background:rgba(0,0,0,0.5)'; + + X.Dom.Style.Support = { + rgba : !!testStyle.background + }; + + testStyle.cssText = temp; + X.Dom.Style.SPECIAL_FIX_PROP = // ~IE8 X.UA.IE < 9 && !X.UA.MacIE ? diff --git a/0.6.x/js/10_ui/06_AbstractUINode.js b/0.6.x/js/10_ui/06_AbstractUINode.js index 7ccbeb6..1c29ab9 100644 --- a/0.6.x/js/10_ui/06_AbstractUINode.js +++ b/0.6.x/js/10_ui/06_AbstractUINode.js @@ -780,12 +780,12 @@ X.UI._AbstractUINode = X.EventDispatcher.inherits( }; f = X.Callback._classifyCallbackArgs( arg1, arg2, arg3 ); if( !f.k ){ - return X.EventDispatcher.prototype.listen.apply( this, [ type, this.User, f ] ); + return x_eventdispatcher_on.apply( this, [ type, this.User, f ] ); } else if( f.k === X.Callback._FUNC_ONLY ){ - return X.EventDispatcher.prototype.listen.apply( this, [ type, this.User, f.f, f.s ] ); + return x_eventdispatcher_on.apply( this, [ type, this.User, f.f, f.s ] ); }; - return X.EventDispatcher.prototype.listen.apply( this, arguments ); + return x_eventdispatcher_on.apply( this, arguments ); }, unlisten : function( type, arg1, arg2, arg3 ){ var root, events, i, ev, counter, f; diff --git a/0.6.x/js/10_ui/15_ScrollBox.js b/0.6.x/js/10_ui/15_ScrollBox.js index 9febc45..f7dac75 100644 --- a/0.6.x/js/10_ui/15_ScrollBox.js +++ b/0.6.x/js/10_ui/15_ScrollBox.js @@ -757,8 +757,7 @@ X.Class._override( iScroll.prototype, { //this._unbind(CANCEL_EV, window); if (!this.options.hasTouch) { - //this._unbind('DOMMouseScroll'); - //this._unbind('mousewheel'); + //this._unbind('wheel'); } // if (this.options.useTransition) this._unbind(TRNEND_EV); -- 2.11.0