X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=0.6.x%2Fjs%2Fdom%2F12_XDomEvent.js;h=d80f5e0b0bec7bd1a79f07c883e70d9d68786753;hb=fb2a4b2dace3975474be1daa56659a861bbcbfbe;hp=b364cf21bf13a81ace7aa300563c0833519ee602;hpb=8c3abfb7fe5b2ff8cf15fb4e35e4349895a92ec4;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 b364cf2..d80f5e0 100644 --- a/0.6.x/js/dom/12_XDomEvent.js +++ b/0.6.x/js/dom/12_XDomEvent.js @@ -1,405 +1,487 @@ -/** - * use X.Callback - * - * http://d.hatena.ne.jp/uupaa/20100430/1272561922 - * - */ - -if( window.addEventListener ){ - X.Dom.Event = function( e ){ - //this._event = e; - this.type = e.type; - this.target = e.target; // xnode - this.currentTarget = e.currentTarget; // xnode - this.relatedTarget = 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.altKey = e.altKey; - //this.ctrlKey = e.ctrlKey; - this.metaKey = e.metaKey; - //this.shiftKey = e.shiftKey; - //this.type = e.type; - //this.target = e.target; - } 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, element ){ - var btn; - - //this._event = e; - this.type = e.type; - this.target = e.srcElement; // xnode - this.currentTarget = element; // xnode - this.relatedTarget = 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; - this.pageX = e.clientX + document.body.scrollLeft; - this.pageY = e.clientY + document.body.scrollTop; - - if( X.UA.IE && 5 <= X.UA.IE ){ - this.offsetX = e.offsetX; - this.offsetY = e.offsetY; - }; - - 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.COMMIT_UPDATE = 6; -X.Dom.Event.ANIME_BEFORE_START = 7; -X.Dom.Event.ANIME_START = 8; -X.Dom.Event.ANIME = 9; -X.Dom.Event.ANIME_END = 10; -X.Dom.Event.ANIME_BEFORE_STOP = 11; // xnode.stop() のみ、指定時間による停止では呼ばれない -X.Dom.Event.ANIME_STOP = 12; -X.Dom.Event._LAST_EVENT = 12; // ここに書いてあるイベントの最後の値 X.Dom.Event.ANIME_STOP と同じ値 - - -X.Dom.Event._chashe = [ {}, {}, null, {} ]; // window, document, documentElement, body -X.Dom.Event._chashe2 = []; - -X.Dom.Node.prototype.listen = function( type, arg2, arg3, arg4 /* [ listener || ( context + function ) || function ][ arguments ] */ ){ - var elm; - - if( this._xnodeType === 0 || this._xnodeType === 3 ) return this; - - ( !this._listeners || !this._listeners[ type ] ) && this._addEvent( type ); - - if( typeof arg2 === 'function' ){ - X.EventDispatcher.prototype.listen.call( this, type, this, arg2, arg3 ); - } else { - X.EventDispatcher.prototype.listen.apply( this, arguments ); - }; - return this; -}; - -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, arg2, arg3, arg4 */ ){ - var list = this._listeners, - type = arguments[ 0 ]; - l = list && type && list[ type ] && list[ type ].length; - - X.EventDispatcher.prototype.unlisten.apply( this, arguments ); - - if( 1 < arguments.length && !this._dispatching && l && !list[ type ] ){ - this._removeEvent( type ); - }; - - return this; -}; - -X.Dom.Node.prototype._removeEvent = - document.removeEventListener ? - (function( type ){ - var elm = this._ie4getRawNode ? this._ie4getRawNode() : this._rawNode; - if( !elm ) return; - elm.removeEventListener( type, this, false ); - }) : - document.detachEvent ? - (function( type ){ - var elm = this._ie4getRawNode ? this._ie4getRawNode() : 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._ie4getRawNode ? this._ie4getRawNode() : this._rawNode; - 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 ) ); - - 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.elm ) ); - - 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( "