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=2fc5817a792185409dccbd170d30a18c252c14b7;hpb=b248d7e4d583904ebe7cf771325325b087627ab0;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 2fc5817..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; @@ -109,7 +124,7 @@ if( X.Dom.EVENT_W3C ){ - if( X.UA.IE && 5 <= X.UA.IE ){ + if( 5 <= X.UA.IE ){ this.offsetX = e.offsetX; // イベントターゲット左上からの座標 this.offsetY = e.offsetY; }// else @@ -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,45 +192,102 @@ 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'; +// 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 ){ + 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 ){ + 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 ){ + X.Dom.Event.Rename[ 'animationend' ] = 'mozAnimationEnd'; + X.Dom.Event.RenameTo[ 'mozAnimationEnd' ] = 'animationend'; + X.Dom.Event.Rename[ 'animationstart' ] = 'mozAnimationStart'; + X.Dom.Event.RenameTo[ 'mozAnimationStart' ] = 'animationstart'; + X.Dom.Event.Rename[ 'animationiteration' ] = 'mozAnimationIteration'; + X.Dom.Event.RenameTo[ 'mozAnimationIteration' ] = 'animationiteration'; +} else*/ +if( document.documentElement && document.documentElement.style.msAnimation !== undefined && document.documentElement.style.animation === undefined ){ //document.documentElement.style.msAnimation + 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 ){ + console.log( 'transitionend <= oTransitionEnd|ver.' + X.UA.Opera ); + X.Dom.Event.Rename[ 'transitionend' ] = 'oTransitionEnd'; + } else { + console.log( 'transitionend <= otransitionEnd|ver.' + X.UA.Opera ); + X.Dom.Event.Rename[ 'transitionend' ] = 'otransitionEnd'; + }; +} else +if( window.onmoztransitionend !== undefined && window.ontransitionend === undefined ){ + console.log( 'transitionend <= mozTransitionEnd' ); + X.Dom.Event.Rename[ 'transitionend' ] = 'mozTransitionEnd'; }; -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; + +if( navigator.msPointerEnabled && !navigator.pointerEnabled ){ + 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 ] */ ){ + 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 ); + } else { + // Safari は Image, Opera7 は window + raw[ 'on' + type ] = this._handleEvent; }; }) : X.Dom.EVENT_W3C ? @@ -223,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._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 ); }); @@ -246,15 +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 ); + } else { + raw[ 'on' + type ] = null; }; if( !this._listeners ){ X.Callback._correct( this._handleEvent ); @@ -263,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(); - 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; @@ -290,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 ) ); @@ -302,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; - }; }); @@ -329,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 ); }; }; @@ -339,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 ); }; }; @@ -353,16 +438,16 @@ X.Dom.Node.prototype._restoreEvent = function(){ // http://shimax.cocolog-nifty.com/search/2006/09/safarijavascrip_c54d.html /* for ie9+/Mozilla/Opera9 */ -if( X.Dom.DOM_W3C ){ +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( "