-\r
-X.Dom.Node.prototype.listen = function( type, arg1, arg2, arg3 /* [ listener || ( context + function ) || function ][ arguments ] */ ){\r
- if( this._xnodeType === 0 || this._xnodeType === 3 ) return this;\r
- \r
- if( X.Type.isArray( type ) ){\r
- return X.EventDispatcher.prototype.listen.apply( this, arguments );\r
- };\r
- \r
- ( !this._listeners || !this._listeners[ type ] ) && X.Type.isString( type ) && this._addEvent( type );\r
- \r
- return X.EventDispatcher.prototype.listen.apply( this, arguments );\r
-};\r
-\r
-X.Dom.Node.prototype._addEvent =\r
- // Days on the Moon DOM Events とブラウザの実装 \r
- // http://nanto.asablo.jp/blog/2007/03/23/1339502\r
- // Safari 2 では関数オブジェクトしか EventListener として使えませんが、Safari のナイトリービルドでは handleEvent メソッドを持つオブジェクトも EventListener として使えるようです。\r
- X.Dom.EVENT_W3C && ( X.UA.WebKit < 525.13 || X.UA.Opera7 || X.UA.NetFront < 4 ) ? // Safari3-\r
- (function( type ){\r
- var raw = this._rawNode;\r
- if( !raw ) return;\r
- this._handleEvent = this._handleEvent || X.Callback.create( this );\r
- type = X.Dom.Event.Rename[ type ] || type;\r
- if( raw.addEventListener ){\r
- raw.addEventListener( type, this._handleEvent, false );\r
- } else {\r
- // Safari は Image, Opera7 は window\r
- raw[ 'on' + type ] = this._handleEvent;\r
- };\r
- }) :\r
- X.Dom.EVENT_W3C ?\r
- (function( type ){\r
- this._rawNode && this._rawNode.addEventListener( X.Dom.Event.Rename[ type ] || type, this, false );\r
- }) :\r
- X.Dom.EVENT_IE ?\r
- (function( type ){\r
- var raw = this._rawNode;\r
- if( !raw ) return;\r
- type = X.Dom.Event.Rename[ type ] || type;\r
- //if( type === 'load' && this._tag && X.Dom.Event._LOAD_FIX_TAGS[ this._tag ] ){\r
- // type = 'readystatechange';\r
- //};\r
- this._handleEvent = this._handleEvent || X.Callback.create( this );\r
- if( raw.attachEvent ){\r
- raw.attachEvent( 'on' + type, this._handleEvent );\r
- } else {\r
- raw[ 'on' + type ] = this._handleEvent;\r
- };\r
- }) :\r
- (function( type ){\r
- var raw = this._rawNode || ( this._ie4getRawNode && this._ie4getRawNode() );\r
- if( !raw ) return;\r
- raw[ 'on' + ( X.Dom.Event.Rename[ type ] || type ) ] = this._handleEvent = this._handleEvent || X.Callback.create( this );\r
- });\r
-\r
-\r
-X.Dom.Node.prototype.unlisten = function( type, arg1, arg2, arg3 ){\r
- var list = this._listeners, l;\r
- \r
- if( X.Type.isArray( type ) ){\r
- return list ? X.EventDispatcher.prototype.unlisten.apply( this, arguments ) : this;\r
- };\r
-\r
- l = !this._dispatching && list && type !== undefined && list[ type ] && list[ type ].length;\r
- \r
- X.EventDispatcher.prototype.unlisten.apply( this, arguments );\r
- \r
- l && !list[ type ] && X.Type.isString( type ) && this._removeEvent( type );\r
- \r
- return this;\r
-};\r
-\r
-X.Dom.Node.prototype._removeEvent =\r
- X.Dom.EVENT_W3C && ( X.UA.WebKit < 525.13 || X.UA.Opera7 || X.UA.NetFront < 4 ) ? // Safari3-\r
- (function( type ){\r
- var raw = this._rawNode;\r
- if( !raw ) return;\r
- type = X.Dom.Event.Rename[ type ] || type;\r
- \r
- if( raw.addEventListener ){ // Image\r
- raw.removeEventListener( type, this._handleEvent, false );\r
- } else {\r
- raw[ 'on' + type ] = null;\r
- };\r
- if( !this._listeners ){\r
- X.Callback._correct( this._handleEvent );\r
- delete this._handleEvent;\r
- };\r
- }) :\r
- X.Dom.EVENT_W3C ?\r
- (function( type ){\r
- var raw = this._rawNode;\r
- if( !raw ) return;\r
- raw.removeEventListener( X.Dom.Event.Rename[ type ] || type, this, false );\r
- }) :\r
- X.Dom.EVENT_IE ?\r
- (function( type ){\r
- var raw = this._rawNode;\r
- if( !raw ) return;\r
- type = X.Dom.Event.Rename[ type ] || type;\r
- //if( type === 'load' && this._tag && X.Dom.Event._LOAD_FIX_TAGS[ this._tag ] ){\r
- // type = 'readystatechange';\r
- //};\r
- if( raw.attachEvent ){\r
- raw.detachEvent( 'on' + type, this._handleEvent );\r
- } else {\r
- raw[ 'on' + type ] = X.emptyFunction;\r
- raw[ 'on' + type ] = '';\r
- };\r
- if( !this._listeners ){\r
- X.Callback._correct( this._handleEvent );\r
- delete this._handleEvent;\r
- };\r
- }) :\r
- (function( type ){\r
- var raw = this._rawNode || ( this._ie4getRawNode && this._ie4getRawNode() );\r
- if( !raw ) return;\r
- type = X.Dom.Event.Rename[ type ] || type;\r
- raw[ 'on' + type ] = X.emptyFunction;\r
- raw[ 'on' + type ] = '';\r
- if( !this._listeners ){\r
- X.Callback._correct( this._handleEvent );\r
- delete this._handleEvent;\r
- };\r
- });\r
-\r
-// Is this in regard to the Safari 1.x preventDefault bug on click/dblclick?\r
-// https://groups.google.com/forum/#!msg/comp.lang.javascript/uYEuCHjHxnw/yKoHtZJPa1QJ\r
-X.Dom.Node.prototype.handleEvent =\r
- X.UA.IE4 || X.UA.IE5678 ? // ie45678 EVENT_IE & EVENT_DOM0 for ie4\r
- (function(){\r
- var ret;\r
- \r
- if( event.type === 'readystatechange' && this._tag && X.Dom.Event._LOAD_FIX_TAGS[ this._tag ] ){\r
- //type = 'readystatechange';\r
- };\r
- \r
- ret = X.EventDispatcher.prototype.dispatch.call( this, new X.Dom.Event( event, this, this._rawNode ) );\r
-\r
- if( ret & X.Callback.STOP_PROPAGATION ){\r
- event.cancelBubble = true;\r
- };\r
- if( ret & X.Callback.PREVENT_DEFAULT ){\r
- this._tag === 'A' && this._rawNode.blur();\r
- return event.returnValue = false;\r
- };\r
- }) :\r
- //X.Dom.EVENT_W3C & EVENT_DOM0\r
- (function( e ){\r
- var ret = X.EventDispatcher.prototype.dispatch.call( this, new X.Dom.Event( e, this ) );\r
- \r
- if( ret & X.Callback.STOP_PROPAGATION ){\r
- e.stopPropagation();\r
- };\r
- if( ret & X.Callback.PREVENT_DEFAULT ){\r
- this._tag === 'A' && this._rawNode.blur();\r
- e.preventDefault();\r
- if( X.UA.WebKit < 525.13 ){ // Safari3-\r
- if( e.type === 'click' || e.type === 'dbclick' ){\r
- X.Dom._safariPreventDefault = true;\r
- };\r
- };\r
- return false;\r
- };\r
- });\r
-\r
-\r
-// イベントの退避、dom が画面から抜かれる場合に実施しておく\r
-X.Dom.Node.prototype._migrateEvent = function(){\r
- var hash = this._listeners,\r
- type;\r
- if( !hash ) return;\r
- for( type in hash ){\r
- // 数字イベントの除外\r
- /*'' + parseFloat( type ) !== type && */this._removeEvent( type );\r
- };\r
-};\r
-\r
-// 退避したイベントの復帰\r
-X.Dom.Node.prototype._restoreEvent = function(){\r
- var hash = this._listeners,\r
- type;\r
- if( !hash ) return;\r
- for( type in hash ){\r
- // 数字イベントの除外\r
- /*'' + parseFloat( type ) !== type && */ this._addEvent( type );\r
- };\r
-};\r
-\r