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=bddd8009dce39a540d86185c98cceca3c708719b;hpb=d0b73629913a4a570785b212abffccfdf7bd3116;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 bddd800..d80f5e0 100644 --- a/0.6.x/js/dom/12_XDomEvent.js +++ b/0.6.x/js/dom/12_XDomEvent.js @@ -7,6 +7,7 @@ if( X.Dom.EVENT_W3C ){ X.Dom.Event = function( e, xnode ){ + var touch0; //this._event = e; this.type = X.Dom.Event.RenameTo[ e.type ] || e.type; @@ -41,6 +42,7 @@ if( X.Dom.EVENT_W3C ){ // https://developer.mozilla.org/ja/docs/DOM/DOM_event_reference/mousewheel // TODO + // axis // https://w3g.jp/blog/tools/wheelevent_crossbrowser // ホイール系イベント2014年版クロスブラウザ if( e.wheelDeltaY !== undefined ){ @@ -56,13 +58,23 @@ if( X.Dom.EVENT_W3C ){ this.wheelDeltaX = this.wheelDeltaY = 0; }; - if( e.constructor === window.TouchEvent ){ + if( /* e.constructor === window.TouchEvent || */ e.touches /* for iOS3.13 */ ){ // TouchEvent this.touches = e.touches; this.changedTouches = e.changedTouches; this.targetTouches = e.targetTouches; this.metaKey = e.metaKey; this.force = e.force || e.webkitForce || 0; + // + if( this.touches.length ){ + touch0 = this.touches[ 0 ]; + this.clientX = touch0.clientX; + this.clientY = touch0.clientY; + this.pageX = touch0.pageX; + this.pageY = touch0.pageY; + this.offsetX = touch0.offsetX || touch0.layerX; + this.offsetY = touch0.offsetY || touch0.layerY; + }; } else if( e.constructor === window.PointerEvent ){ // PointerEvent; @@ -80,6 +92,9 @@ if( X.Dom.EVENT_W3C ){ this.tiltY = e.tiltY; }; }; + if( !window.PointerEvent && window.MSPointerEvent ){ + window.PointerEvent = window.MSPointerEvent; + }; } else { X.Dom.Event = function( e, xnode, element ){ var btn; @@ -150,6 +165,7 @@ 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.VIEW_TURNED = ++X.Event._LAST_EVENT; X.Dom.Event.BASE_FONT_RESIZED = ++X.Event._LAST_EVENT; // same_page_jump // on_screen_keyboard_show @@ -176,21 +192,29 @@ X.Dom.Event.Rename = {}; X.Dom.Event.RenameTo = {}; // https://github.com/georgeadamson/jQuery.prefixfree-events/blob/master/jQuery.prefixfree-events.js +// DOMMoseScroll +if( X.UA.Gecko && window.MouseScrollEvent ){ + if( 2 <= X.UA.Gecko || ( 1.9 < X.UA.Gecko && 1 <= X.UA.GeckoPatch ) ){ // Gecko 1.9.1+ (firefox3.5+) + console.log( 'mousewheel <= MozMousePixelScroll' ); + X.Dom.Event.Rename[ 'mousewheel' ] = 'MozMousePixelScroll'; + } else + if( 0.9 < X.UA.Gecko && 7 <= X.UA.GeckoPatch ){ // Gecko 0.9.7+ (NN6.2+?) + console.log( 'mousewheel <= DOMMouseScroll' ); + X.Dom.Event.Rename[ 'mousewheel' ] = 'DOMMouseScroll'; + }; +}; + 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'; + console.log( 'animationend <= webkitAnimationEnd' ); + X.Dom.Event.Rename[ 'animationend' ] = 'webkitAnimationEnd'; + X.Dom.Event.Rename[ 'animationstart' ] = 'webkitAnimationStart'; + X.Dom.Event.Rename[ 'animationiteration' ] = 'webkitAnimationIteration'; } else if( window.onoanimationend !== undefined && window.onanimationend === undefined ){ - X.Dom.Event.Rename[ 'animationend' ] = 'oAnimationEnd'; - X.Dom.Event.RenameTo[ 'oAnimationEnd' ] = 'animationend'; - X.Dom.Event.Rename[ 'animationstart' ] = 'oAnimationStart'; - X.Dom.Event.RenameTo[ 'oAnimationStart' ] = 'animationstart'; - X.Dom.Event.Rename[ 'animationiteration' ] = 'oAnimationIteration'; - X.Dom.Event.RenameTo[ 'oAnimationIteration' ] = 'animationiteration'; + console.log( 'animationend <= oAnimationEnd' ); + X.Dom.Event.Rename[ 'animationend' ] = 'oAnimationEnd'; + X.Dom.Event.Rename[ 'animationstart' ] = 'oAnimationStart'; + X.Dom.Event.Rename[ 'animationiteration' ] = 'oAnimationIteration'; } else /* if( window.onmozanimationend !== undefined && window.onanimationend === undefined ){ @@ -202,83 +226,68 @@ if( window.onmozanimationend !== undefined && window.onanimationend === undefine X.Dom.Event.RenameTo[ 'mozAnimationIteration' ] = 'animationiteration'; } else*/ if( document.documentElement && document.documentElement.style.msAnimation !== undefined && document.documentElement.style.animation === undefined ){ //document.documentElement.style.msAnimation - X.Dom.Event.Rename[ 'animationend' ] = 'MSAnimationEnd'; - X.Dom.Event.RenameTo[ 'MSAnimationEnd' ] = 'animationend'; - X.Dom.Event.Rename[ 'animationstart' ] = 'MSAnimationStart'; - X.Dom.Event.RenameTo[ 'MSAnimationStart' ] = 'animationstart'; - X.Dom.Event.Rename[ 'animationiteration' ] = 'MSAnimationIteration'; - X.Dom.Event.RenameTo[ 'MSAnimationIteration' ] = 'animationiteration'; + console.log( 'animationend <= MSAnimationEnd' ); + X.Dom.Event.Rename[ 'animationend' ] = 'MSAnimationEnd'; + X.Dom.Event.Rename[ 'animationstart' ] = 'MSAnimationStart'; + X.Dom.Event.Rename[ 'animationiteration' ] = 'MSAnimationIteration'; }; // https://developer.mozilla.org/en-US/docs/Web/Events/transitionend // chrome1+, firefox4+, IE10+, Opera10.5+, Safari3.2+, Android2.1+ if( window.onwebkittransitionend !== undefined && window.ontransitionend === undefined ){ - X.Dom.Event.Rename[ 'transitionend' ] = 'webkitTransitionEnd'; - X.Dom.Event.RenameTo[ 'webkitTransitionEnd' ] = 'transitionend'; + console.log( 'transitionend <= webkitTransitionEnd' ); + X.Dom.Event.Rename[ 'transitionend' ] = 'webkitTransitionEnd'; } else if( window.onotransitionend !== undefined && window.ontransitionend === undefined ){ if( X.UA.Opera < 12 ){ - X.Dom.Event.Rename[ 'transitionend' ] = 'oTransitionEnd'; - X.Dom.Event.RenameTo[ 'oTransitionEnd' ] = 'transitionend'; + console.log( 'transitionend <= oTransitionEnd|ver.' + X.UA.Opera ); + X.Dom.Event.Rename[ 'transitionend' ] = 'oTransitionEnd'; } else { - X.Dom.Event.Rename[ 'transitionend' ] = 'otransitionEnd'; - X.Dom.Event.RenameTo[ 'otransitionEnd' ] = 'transitionend'; + console.log( 'transitionend <= otransitionEnd|ver.' + X.UA.Opera ); + X.Dom.Event.Rename[ 'transitionend' ] = 'otransitionEnd'; }; } else if( window.onmoztransitionend !== undefined && window.ontransitionend === undefined ){ - X.Dom.Event.Rename[ 'transitionend' ] = 'mozTransitionEnd'; - X.Dom.Event.RenameTo[ 'mozTransitionEnd' ] = 'transitionend'; + console.log( 'transitionend <= mozTransitionEnd' ); + X.Dom.Event.Rename[ 'transitionend' ] = 'mozTransitionEnd'; }; if( navigator.msPointerEnabled && !navigator.pointerEnabled ){ - X.Dom.Event.Rename[ 'pointerdown' ] = 'MSPointerDown'; - X.Dom.Event.RenameTo[ 'MSPointerDown' ] = 'pointerdown'; - X.Dom.Event.Rename[ 'pointerup' ] = 'MSPointerUp'; - X.Dom.Event.RenameTo[ 'MSPointerUp' ] = 'pointerup'; - X.Dom.Event.Rename[ 'pointermove' ] = 'MSPointerMove'; - X.Dom.Event.RenameTo[ 'MSPointerMove' ] = 'pointermove'; - X.Dom.Event.Rename[ 'pointercancel' ] = 'MSPointerCancel'; - X.Dom.Event.RenameTo[ 'MSPointerCancel' ] = 'pointercancel'; + console.log( 'pointerdown <= MSPointerDown' ); + X.Dom.Event.Rename[ 'pointerdown' ] = 'MSPointerDown'; + X.Dom.Event.Rename[ 'pointerup' ] = 'MSPointerUp'; + X.Dom.Event.Rename[ 'pointermove' ] = 'MSPointerMove'; + X.Dom.Event.Rename[ 'pointercancel' ] = 'MSPointerCancel'; }; +(function( rename, renameTo ){ + for( var k in rename ){ + renameTo[ rename[ k ] ] = k; + }; +})( X.Dom.Event.Rename, X.Dom.Event.RenameTo ); - -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; +X.Dom.Node.prototype.listen = function( type /* , arg1, arg2, arg3[ listener || ( context + function ) || function ][ arguments ] */ ){ + if( this._xnodeType === 0 || this._xnodeType === 3 ) return this; ( !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 ) : - X.EventDispatcher.prototype.listen.apply( this, arguments ); + 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.Safari && X.UA.Safari < 3 ? + X.Dom.EVENT_W3C && ( X.UA.WebKit < 525.13 || X.UA.Opera7 ) ? // Safari3- (function( type ){ 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 { + if( raw.addEventListener ){ raw.addEventListener( type, this._handleEvent, false ); - }; - }) : - 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 ); + // Safari は Image, Opera7 は window + raw[ 'on' + type ] = this._handleEvent; }; }) : X.Dom.EVENT_W3C ? @@ -287,14 +296,19 @@ X.Dom.Node.prototype._addEvent = }) : X.Dom.EVENT_IE ? (function( type ){ - if( !this._rawNode ) return; + var raw = this._rawNode; + if( !raw ) return; this._handleEvent = this._handleEvent || X.Callback.create( this ); - this._rawNode.attachEvent( 'on' + type, this._handleEvent ); + if( raw.attachEvent ){ + raw.attachEvent( 'on' + type, this._handleEvent ); + } else { + raw[ 'on' + type ] = this._handleEvent; + }; }) : (function( type ){ - var elm = this._rawNode || ( this._ie4getRawNode && this._ie4getRawNode() ); - if( !elm ) return; - this._handleEvent = elm[ 'on' + type ] = this._handleEvent || X.Callback.create( this ); + var raw = this._rawNode || ( this._ie4getRawNode && this._ie4getRawNode() ); + if( !raw ) return; + raw[ 'on' + type ] = this._handleEvent = this._handleEvent || X.Callback.create( this ); }); @@ -310,30 +324,15 @@ X.Dom.Node.prototype.unlisten = function( type /* , arg1, arg2, arg3 */ ){ }; X.Dom.Node.prototype._removeEvent = - X.Dom.EVENT_W3C && X.UA.Safari && X.UA.Safari < 3 ? + X.Dom.EVENT_W3C && ( X.UA.WebKit < 525.13 || X.UA.Opera7 ) ? // Safari3- (function( type ){ var raw = this._rawNode; if( !raw ) return; - if( this._xnodeType === 4 ){ // Image - raw[ 'on' + type ] = ''; - } else { + if( raw.addEventListener ){ // Image 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 ); + raw[ 'on' + type ] = null; }; if( !this._listeners ){ X.Callback._correct( this._handleEvent ); @@ -342,25 +341,30 @@ X.Dom.Node.prototype._removeEvent = }) : X.Dom.EVENT_W3C ? (function( type ){ - var elm = this._rawNode; - if( !elm ) return; - elm.removeEventListener( X.Dom.Event.Rename[ type ] || type, this, false ); + var raw = this._rawNode; + if( !raw ) return; + raw.removeEventListener( X.Dom.Event.Rename[ type ] || type, this, false ); }) : X.Dom.EVENT_IE ? (function( type ){ - var elm = this._rawNode; - if( !elm ) return; - elm.detachEvent( 'on' + type, this._handleEvent ); + var raw = this._rawNode; + if( !raw ) return; + 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 elm = this._rawNode || ( this._ie4getRawNode && this._ie4getRawNode() ); - if( !elm ) return; - elm[ 'on' + type ] = X.emptyFunction; - elm[ 'on' + type ] = ''; + var raw = this._rawNode || ( this._ie4getRawNode && this._ie4getRawNode() ); + if( !raw ) return; + raw[ 'on' + type ] = X.emptyFunction; + raw[ 'on' + type ] = ''; if( !this._listeners ){ X.Callback._correct( this._handleEvent ); delete this._handleEvent; @@ -369,9 +373,20 @@ 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 = - X.Dom.EVENT_W3C ? + X.UA.IE < 9 ? // ie45678 EVENT_IE & EVENT_DOM0 for ie4 + (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 ){ + this._tag === 'A' && this._rawNode.blur(); + return event.returnValue = false; + }; + }) : + //X.Dom.EVENT_W3C & EVENT_DOM0 for NetFront (function( e ){ var ret = X.EventDispatcher.prototype.dispatch.call( this, new X.Dom.Event( e, this ) ); @@ -381,24 +396,13 @@ X.Dom.Node.prototype.handleEvent = if( ret & X.Callback.PREVENT_DEFAULT ){ this._tag === 'A' && this._rawNode.blur(); e.preventDefault(); - if( X.UA.Safari && X.UA.Safari < 3 ){ + if( X.UA.WebKit < 525.13 ){ // Safari3- if( e.type === 'click' || e.type === 'dbclick' ){ X.Dom._safariPreventDefault = true; }; }; 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 ){ - this._tag === 'A' && this._rawNode.blur(); - return event.returnValue = false; - }; }); @@ -408,7 +412,8 @@ X.Dom.Node.prototype._migrateEvent = function(){ type; if( !hash ) return; for( type in hash ){ - this._removeEvent( type ); + // 数字イベントの除外 + /*'' + parseFloat( type ) !== type && */this._removeEvent( type ); }; }; @@ -418,7 +423,8 @@ X.Dom.Node.prototype._restoreEvent = function(){ type; if( !hash ) return; for( type in hash ){ - this._addEvent( type ); + // 数字イベントの除外 + /*'' + parseFloat( type ) !== type && */ this._addEvent( type ); }; }; @@ -466,7 +472,7 @@ X.Dom.listenOnce( X.Dom.Event.XDOM_READY, function(e){ console.log( 'X.Dom XDomReady ' + X.Dom.readyState ); } ); -if( X.UA.Safari && X.UA.Safari < 3 ){ +if( X.UA.WebKit < 525.13 ){ // Safari3- document.documentElement.onclick = document.documentElement.ondbclick = function( e ){ if( X.Dom._safariPreventDefault ){