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=71ee2c1abb3e17e07464b8215877de936b30bd9a;hpb=1d0f175bdfd85ad04995e69a9eb878d8980d9940;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 71ee2c1..145054e 100644 --- a/0.6.x/js/dom/12_XDomEvent.js +++ b/0.6.x/js/dom/12_XDomEvent.js @@ -1,666 +1,428 @@ -/** - * use X.Callback - * - * http://d.hatena.ne.jp/uupaa/20100430/1272561922 - * - */ - -if( window.addEventListener ){ - X.Dom.Event = function( e, xnode ){ - //this._event = e; - this.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 - - this.currentTarget = xnode; // xnode - this.relatedTarget = Node._getXNode( e.relatedTarget ); // xnode - this.eventPhase = e.eventPhase; - - this.clientX = e.clientX; - this.clientY = e.clientY; - //this.screenX = e.screenX; - //this.screenY = e.screenY; - this.pageX = e.pageX; - this.pageY = e.pageY; - this.offsetX = e.offsetX || e.layerX; - this.offsetY = e.offsetY || e.layerY; - - this.keyCode = e.keyCode; - this.altKey = e.altKey; - this.ctrlKey = e.ctrlKey; - this.shiftKey = e.shiftKey; - - // http://www.programming-magic.com/20090127231544/ - this.which = e.which || ( e.button + 1 ); // 左:1, 中:2, 右:3 - - // https://developer.mozilla.org/ja/docs/DOM/DOM_event_reference/mousewheel - if( e.wheelDeltaY !== undefined ){ - this.wheelDeltaX = e.wheelDeltaX / 12; - this.wheelDeltaY = e.wheelDeltaY / 12; - } else - if( e.wheelDelta !== undefined ){ - this.wheelDeltaX = this.wheelDeltaY = e.wheelDelta / 12; - } else - if( e.detail !== undefined ){ - this.wheelDeltaX = this.wheelDeltaY = - e.detail * 3; - } else { - this.wheelDeltaX = this.wheelDeltaY = 0; - }; - - if( e.constructor === window.TouchEvent ){ - // TouchEvent - this.touches = e.touches; - this.changedTouches = e.changedTouches; - this.targetTouches = e.targetTouches; - this.metaKey = e.metaKey; - this.force = e.force || e.webkitForce || 0; - } else - if( e.constructor === window.PointerEvent ){ - // PointerEvent; - this.currentPoint = e.currentPoint; - this.width = e.width; - this.height = e.height; - this.timeStamp = e.timeStamp; - this.hwTimestamp = e.hwTimestamp; - this.intermediatePoints = e.intermediatePoints; - this.isPrimary = e.isPrimary; - this.pointerId = e.pointerId; - this.pointerType = e.pointerType; - this.pressure = e.pressure; - this.tiltX = e.tiltX; - this.tiltY = e.tiltY; - }; - }; -} else { - X.Dom.Event = function( e, xnode, element ){ - var btn; - - //this._event = e; - this.type = e.type; - this.target = Node._getXNode( e.srcElement ); // xnode - if( this.target && this.target._xnodeType === 3 ) this.target = this.target.parent; // ie4 の fake Textnode がヒットしていないか? - this.currentTarget = xnode; // xnode - this.relatedTarget = Node._getXNode( e.formElement ? e.formElement : e.toElement ); // xnode - this.eventPhase = e.srcElement === element ? 2: 3; - - this.clientX = e.clientX; - this.clientY = e.clientY; - //this.screenX = e.screenX; - //this.screenY = e.screenY; - - if( X.Dom._root ){ // uuu... - - this.pageX = e.clientX + X.Dom._root.scrollLeft; - this.pageY = e.clientY + X.Dom._root.scrollTop; - - // DOMAssistant 2.8.1 - //event.pageX = DOMAssistant.def(e.pageX)? e.pageX : (event.clientX + (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0)); - //event.pageY = DOMAssistant.def(e.pageY)? e.pageY : (event.clientY + (de.scrollTop || b.scrollTop) - (de.clientTop || 0)); - }; - - - - if( X.UA.IE && 5 <= X.UA.IE ){ - this.offsetX = e.offsetX; // イベントターゲット左上からの座標 - this.offsetY = e.offsetY; - }// else - //if( e.srcElement ){ - // this.offsetX = e.x - e.srcElement.offsetLeft; // e.x はイベント発生要素の親要素を基準にした座標。 - // this.offsetY = e.y - e.srcElement.offsetTop; - //}; - - this.keyCode = e.keyCode; - this.altKey = e.altKey; - this.ctrlKey = e.ctrlKey; - this.shiftKey = e.shiftKey; - - // http://www.programming-magic.com/20090127231544/ - switch( this.type ){ - case 'click' : - case 'dblclick' : - this.which = 1; - break; - case 'contextmenu' : - this.which = 3; - break; - default : - btn = e.button; - this.which = - btn & 1 ? 1 : - btn & 4 ? 2 : - btn & 2 ? 3 : 0; // 左:1(click:0), 中:4, 右:2 - }; - this.wheelDeltaX = this.wheelDeltaY = e.wheelDelta / 12; - }; -}; - -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; -// on_screen_keyboard_show -// on_screen_keyboard_hide -X.Dom.Event.BEFORE_UPDATE = 7; -X.Dom.Event.COMMIT_UPDATE = 8; -// 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.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 ); - - return typeof arg1 === 'function' ? - X.EventDispatcher.prototype.listen.call( this, type, this, arg1, arg2 ) : - X.EventDispatcher.prototype.listen.apply( this, arguments ); -}; - -X.Dom.Node.prototype._addEvent = - document.removeEventListener ? - (function( type ){ - this._rawNode && this._rawNode.addEventListener( type, this, false ); - }) : - document.detachEvent ? - (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(); - if( !elm ) return; - this._handleEvent = elm[ 'on' + type ] = this._handleEvent || X.Callback.create( this ); - }); - - -X.Dom.Node.prototype.unlisten = function( type /* , arg1, arg2, arg3 */ ){ - var list = this._listeners, - l = !this._dispatching && list && type !== undefined && list[ type ] && list[ type ].length; - - X.EventDispatcher.prototype.unlisten.apply( this, arguments ); - - l && !list[ type ] && this._removeEvent( type ); - - return this; -}; - -X.Dom.Node.prototype._removeEvent = - document.removeEventListener ? - (function( type ){ - var elm = this._rawNode; - if( !elm ) return; - elm.removeEventListener( type, this, false ); - }) : - document.detachEvent ? - (function( type ){ - var elm = this._rawNode; - if( !elm ) return; - elm.detachEvent( 'on' + type, this._handleEvent ); - if( !this._listeners ){ - X.Callback._correct( this._handleEvent ); - delete this._handleEvent; - }; - }) : - (function( type ){ - var elm = this._rawNode || this._ie4getRawNode(); - if( !elm ) return; - elm[ 'on' + type ] = X.emptyFunction; - elm[ 'on' + type ] = ''; - if( !this._listeners ){ - X.Callback._correct( this._handleEvent ); - delete this._handleEvent; - }; - }); - - -X.Dom.Node.prototype.handleEvent = - document.removeEventListener ? - (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 ){ - e.preventDefault(); - return false; - }; - }) : - (function(){ - var ret = X.EventDispatcher.prototype.dispatch.call( this, new X.Dom.Event( event, this, this._rawNode ) ); - - if( ret & X.Callback.STOP_PROPAGATION ){ - event.cancelBubble = true; - }; - if( ret & X.Callback.PREVENT_DEFAULT ){ - return event.returnValue = false; - }; - }); - - -// イベントの退避、dom が画面から抜かれる場合に実施しておく -X.Dom.Node.prototype._migrateEvent = function(){ - var hash = this._listeners, - type; - if( !hash ) return; - for( type in hash ){ - this._removeEvent( type ); - }; -}; - -// 退避したイベントの復帰 -X.Dom.Node.prototype._restoreEvent = function(){ - var hash = this._listeners, - type; - if( !hash ) return; - for( type in hash ){ - this._addEvent( type ); - }; -}; - - - -/* ----------------------------------------------- - * Document Ready - * Dean Edwards/Matthias Miller/John Resig - */ -/* for ie9+/Mozilla/Opera9 */ -if( document.addEventListener ){ - X.Dom.Node._document.listenOnce( 'DOMContentLoaded', X.Dom._init ); -} else -if( 5 <= X.UA.IE && X.inHead ){ - // if this script in Head - document.write( "