X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=0.6.x%2Fjs%2Fdom%2F12_XDomEvent.js;h=145054e7793700c0c1f7ffd1edf4b22abd3c3d99;hb=a93316a3916f7aca87b1cf6e4488382b749eca76;hp=d945617db2717d0c7e7441f871bf69cebd9920de;hpb=d0f13b6086143af1a134cf24282e817b5a86ca42;p=pettanr%2FclientJs.git diff --git a/0.6.x/js/dom/12_XDomEvent.js b/0.6.x/js/dom/12_XDomEvent.js index d945617..145054e 100644 --- a/0.6.x/js/dom/12_XDomEvent.js +++ b/0.6.x/js/dom/12_XDomEvent.js @@ -5,16 +5,20 @@ * */ -if( window.addEventListener ){ +if( X.Dom.EVENT_W3C ){ X.Dom.Event = function( e, xnode ){ //this._event = e; - this.type = e.type; + this.type = X.Dom.Event.RenameTo[ e.type ] || e.type; //http://www.quirksmode.org/js/events_properties.html - this.target = Node._getXNode( e.target.nodeType === 3 ? e.target.parentNode : e.target );// defeat Safari bug // xnode + if( e.target ){ + this.target = Node._getXNode( e.target.nodeType === 3 ? e.target.parentNode : e.target );// defeat Safari bug // xnode + }; + if( e.relatedTarget ){ + this.relatedTarget = Node._getXNode( e.relatedTarget.nodeType === 3 ? e.relatedTarget.parentNode : e.relatedTarget ); // xnode + }; this.currentTarget = xnode; // xnode - this.relatedTarget = Node._getXNode( e.relatedTarget ); // xnode this.eventPhase = e.eventPhase; this.clientX = e.clientX; @@ -35,6 +39,10 @@ if( window.addEventListener ){ this.which = e.which || ( e.button + 1 ); // 左:1, 中:2, 右:3 // https://developer.mozilla.org/ja/docs/DOM/DOM_event_reference/mousewheel + + // TODO + // https://w3g.jp/blog/tools/wheelevent_crossbrowser + // ホイール系イベント2014年版クロスブラウザ if( e.wheelDeltaY !== undefined ){ this.wheelDeltaX = e.wheelDeltaX / 12; this.wheelDeltaY = e.wheelDeltaY / 12; @@ -135,40 +143,59 @@ if( window.addEventListener ){ }; }; -X.Dom.Event.DOM_PRE_INIT = 0; -X.Dom.Event.DOM_INIT = 1; -X.Dom.Event.XDOM_READY = 2; -X.Dom.Event.VIEW_ACTIVATE = 3; -X.Dom.Event.VIEW_DEACTIVATE = 4; -X.Dom.Event.VIEW_RESIZED = 5; -X.Dom.Event.BASE_FONT_RESIZED = 6; +X.Dom.Event.DOM_PRE_INIT = ++X.Event._LAST_EVENT; +X.Dom.Event.DOM_BUILDER_COMPLETE= ++X.Event._LAST_EVENT; +X.Dom.Event.DOM_INIT = ++X.Event._LAST_EVENT; +X.Dom.Event.XDOM_READY = ++X.Event._LAST_EVENT; +X.Dom.Event.VIEW_ACTIVATE = ++X.Event._LAST_EVENT; +X.Dom.Event.VIEW_DEACTIVATE = ++X.Event._LAST_EVENT; +X.Dom.Event.VIEW_RESIZED = ++X.Event._LAST_EVENT; +X.Dom.Event.BASE_FONT_RESIZED = ++X.Event._LAST_EVENT; +// same_page_jump // on_screen_keyboard_show // on_screen_keyboard_hide -X.Dom.Event.BEFORE_UPDATE = 7; -X.Dom.Event.AFTER_UPDATE = 8; +// X.Dom.Event.BEFORE_UPDATE = ++X.Event._LAST_EVENT; // このイベントで要素のサイズを取得すると無限ループに! +X.Dom.Event.AFTER_UPDATE = ++X.Event._LAST_EVENT; // hash_change -X.Dom.Event.BEFORE_UNLOAD = 9; -X.Dom.Event.UNLOAD = 10; -X.Dom.Event.LOAD_BEFORE_STOP = 11; -X.Dom.Event.LOAD_ASSET_STOP = 12; -X.Dom.Event.LOAD_ASSET_COMPLETE = 13; -X.Dom.Event.LOAD_ASSET_ERROR = 14; - -X.Dom.Event.ANIME_BEFORE_START = 15; -X.Dom.Event.ANIME_START = 16; -X.Dom.Event.ANIME = 17; -X.Dom.Event.ANIME_END = 18; -X.Dom.Event.ANIME_BEFORE_STOP = 19; // xnode.stop() のみ、指定時間による停止では呼ばれない -X.Dom.Event.ANIME_STOP = 20; -X.Dom.Event._LAST_EVENT = 20; // ここに書いてあるイベントの最後の値 X.Dom.Event.ANIME_STOP と同じ値 +X.Dom.Event.BEFORE_UNLOAD = ++X.Event._LAST_EVENT; +X.Dom.Event.UNLOAD = ++X.Event._LAST_EVENT; +X.Dom.Event.LOAD_BEFORE_STOP = ++X.Event._LAST_EVENT; +X.Dom.Event.LOAD_ASSET_STOP = ++X.Event._LAST_EVENT; +X.Dom.Event.LOAD_ASSET_COMPLETE = ++X.Event._LAST_EVENT; +X.Dom.Event.LOAD_ASSET_ERROR = ++X.Event._LAST_EVENT; + +X.Dom.Event.ANIME_BEFORE_START = ++X.Event._LAST_EVENT; +X.Dom.Event.ANIME_START = ++X.Event._LAST_EVENT; +X.Dom.Event.ANIME = ++X.Event._LAST_EVENT; +X.Dom.Event.ANIME_END = ++X.Event._LAST_EVENT; +X.Dom.Event.ANIME_BEFORE_STOP = ++X.Event._LAST_EVENT; // xnode.stop() のみ、指定時間による停止では呼ばれない +X.Dom.Event.ANIME_STOP = ++X.Event._LAST_EVENT; +X.Dom.Event._LAST_EVENT = X.Event._LAST_EVENT; // ここに書いてあるイベントの最後の値 X.Dom.Event.ANIME_STOP と同じ値 + +X.Dom.Event.Rename = {}; +X.Dom.Event.RenameTo = {}; +// https://github.com/georgeadamson/jQuery.prefixfree-events/blob/master/jQuery.prefixfree-events.js + +if( window.onwebkitanimationend !== undefined && window.onanimationend === undefined ){ + X.Dom.Event.Rename[ 'animationend' ] = 'webkitAnimationEnd'; + X.Dom.Event.RenameTo[ 'webkitAnimationEnd' ] = 'animationend'; + X.Dom.Event.Rename[ 'animationstart' ] = 'webkitAnimationStart'; + X.Dom.Event.RenameTo[ 'webkitAnimationStart' ] = 'animationstart'; + X.Dom.Event.Rename[ 'animationiteration' ] = 'webkitAnimationIteration'; + X.Dom.Event.RenameTo[ 'webkitAnimationIteration' ] = 'animationiteration'; +}; +if( window.onwebkittransitionend !== undefined && window.ontransitionend === undefined ){ + X.Dom.Event.Rename[ 'transitionend' ] = 'webkitTransitionEnd'; + X.Dom.Event.RenameTo[ 'webkitTransitionEnd' ] = 'transitionend'; +}; X.Dom.Node.prototype.listen = function( type, arg1, arg2, arg3 /* [ listener || ( context + function ) || function ][ arguments ] */ ){ var elm; if( this._xnodeType === 0 || this._xnodeType === 3 || !arg1 ) return this; - ( !this._listeners || !this._listeners[ type ] ) && this._addEvent( type ); + ( !this._listeners || !this._listeners[ type ] ) && X.Type.isString( type ) && this._addEvent( type ); return typeof arg1 === 'function' ? X.EventDispatcher.prototype.listen.call( this, type, this, arg1, arg2 ) : @@ -176,18 +203,43 @@ X.Dom.Node.prototype.listen = function( type, arg1, arg2, arg3 /* [ listener || }; X.Dom.Node.prototype._addEvent = - document.removeEventListener ? + // 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.Safari && X.UA.Safari < 3 ? (function( type ){ - this._rawNode && this._rawNode.addEventListener( type, this, false ); + var raw = this._rawNode; + if( !raw ) return; + this._handleEvent = this._handleEvent || X.Callback.create( this ); + if( this._xnodeType === 4 ){ // Image + raw[ 'on' + type ] = this._handleEvent; + } else { + raw.addEventListener( type, this._handleEvent, false ); + }; }) : - document.detachEvent ? + X.Dom.EVENT_W3C && X.UA.Opera7 ? + (function( type ){ + var raw = this._rawNode; + if( !raw ) return; + this._handleEvent = this._handleEvent || X.Callback.create( this ); + if( raw === window ){ + raw[ 'on' + type ] = this._handleEvent; + } else { + raw.addEventListener( type, this._handleEvent, false ); + }; + }) : + 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 ){ if( !this._rawNode ) return; this._handleEvent = this._handleEvent || X.Callback.create( this ); this._rawNode.attachEvent( 'on' + type, this._handleEvent ); }) : (function( type ){ - var elm = this._ie4getRawNode(); + var elm = this._rawNode || ( this._ie4getRawNode && this._ie4getRawNode() ); if( !elm ) return; this._handleEvent = elm[ 'on' + type ] = this._handleEvent || X.Callback.create( this ); }); @@ -199,19 +251,49 @@ X.Dom.Node.prototype.unlisten = function( type /* , arg1, arg2, arg3 */ ){ X.EventDispatcher.prototype.unlisten.apply( this, arguments ); - l && !list[ type ] && this._removeEvent( type ); + l && !list[ type ] && X.Type.isString( type ) && this._removeEvent( type ); return this; }; X.Dom.Node.prototype._removeEvent = - document.removeEventListener ? + X.Dom.EVENT_W3C && X.UA.Safari && X.UA.Safari < 3 ? + (function( type ){ + var raw = this._rawNode; + if( !raw ) return; + + if( this._xnodeType === 4 ){ // Image + raw[ 'on' + type ] = ''; + } else { + raw.removeEventListener( type, this._handleEvent, false ); + }; + if( !this._listeners ){ + X.Callback._correct( this._handleEvent ); + delete this._handleEvent; + }; + }) : + X.Dom.EVENT_W3C && X.UA.Opera7 ? + (function( type ){ + var raw = this._rawNode; + if( !raw ) return; + + if( raw === window ){ + raw[ 'on' + type ] = null; + } else { + raw.removeEventListener( type, this._handleEvent, false ); + }; + if( !this._listeners ){ + X.Callback._correct( this._handleEvent ); + delete this._handleEvent; + }; + }) : + X.Dom.EVENT_W3C ? (function( type ){ var elm = this._rawNode; if( !elm ) return; - elm.removeEventListener( type, this, false ); + elm.removeEventListener( X.Dom.Event.Rename[ type ] || type, this, false ); }) : - document.detachEvent ? + X.Dom.EVENT_IE ? (function( type ){ var elm = this._rawNode; if( !elm ) return; @@ -222,7 +304,7 @@ X.Dom.Node.prototype._removeEvent = }; }) : (function( type ){ - var elm = this._rawNode || this._ie4getRawNode(); + var elm = this._rawNode || ( this._ie4getRawNode && this._ie4getRawNode() ); if( !elm ) return; elm[ 'on' + type ] = X.emptyFunction; elm[ 'on' + type ] = ''; @@ -232,18 +314,25 @@ X.Dom.Node.prototype._removeEvent = }; }); +// 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 = - document.removeEventListener ? + X.Dom.EVENT_W3C ? (function( e ){ var ret = X.EventDispatcher.prototype.dispatch.call( this, new X.Dom.Event( e, this ) ); - + if( ret & X.Callback.STOP_PROPAGATION ){ e.stopPropagation(); }; if( ret & X.Callback.PREVENT_DEFAULT ){ this._tag === 'A' && this._rawNode.blur(); e.preventDefault(); + if( X.UA.Safari && X.UA.Safari < 3 ){ + if( e.type === 'click' || e.type === 'dbclick' ){ + X.Dom._safariPreventDefault = true; + }; + }; return false; }; }) : @@ -280,25 +369,37 @@ X.Dom.Node.prototype._restoreEvent = function(){ }; }; - - /* ----------------------------------------------- * Document Ready * Dean Edwards/Matthias Miller/John Resig */ + +// SafariでJavaScriptのデバッグをする方法 +// safari1.3 可 +// http://shimax.cocolog-nifty.com/search/2006/09/safarijavascrip_c54d.html + /* for ie9+/Mozilla/Opera9 */ -if( document.addEventListener ){ - X.Dom.Node._document.listenOnce( 'DOMContentLoaded', X.Dom._init ); +if( X.Dom.EVENT_W3C ){ + Node._document.listenOnce( 'DOMContentLoaded', X.Dom._init ); } else -if( 5 <= X.UA.IE && X.inHead ){ +if( 6 <= X.UA.IE && X.inHead ){ // if this script in Head document.write( "