X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=0.6.x%2Fjs%2F02_dom%2F03_XDomEvent.js;h=87087467dd4ddd922916e4e7610f7a87704e8b97;hb=dc5a75639232882249108b4f708916e9690e42b3;hp=540ed81212fef7d7d31196268f5f23be0ebae8fc;hpb=dd02887497fa95f13d112b7fc2e5e7aefd0ffb08;p=pettanr%2FclientJs.git diff --git a/0.6.x/js/02_dom/03_XDomEvent.js b/0.6.x/js/02_dom/03_XDomEvent.js index 540ed81..8708746 100644 --- a/0.6.x/js/02_dom/03_XDomEvent.js +++ b/0.6.x/js/02_dom/03_XDomEvent.js @@ -21,15 +21,28 @@ var X_Dom_Event_devicePixelRatio = window.devicePixelRatio || ( window.screen.de if( !X_UA.IE || 9 <= X_UA.IE ){ X.Dom.Event = function( e, xnode ){ var originalType = e.type, - type, pointerType, + type, pointerEventType, touches, events, - altKey, ctrlKey, metaKey, shiftKey, target, related, + altKey, ctrlKey, metaKey, shiftKey, target, related, force, elm, i, n, time, touch, ev; //this._event = e; this.type = type = X_Event_RenameTo[ originalType ] || originalType; - console.log( 'original : ' + originalType + ' > ' + type ); + switch( type ){ + case 'message' : + this.data = e.data; + this.origin = e.origin; + this.source = e.source; + break; + case 'progress' : + this.lengthComputable = e.lengthComputable; + this.loaded = e.loaded; + this.total = e.total; + break; + }; + + //console.log( 'original : ' + originalType + ' > ' + type ); // http://msdn.microsoft.com/ja-jp/library/ie/dn304886%28v=vs.85%29.aspx // ポインター イベントの更新 if( e.pointerType ){ @@ -86,15 +99,17 @@ if( !X_UA.IE || 9 <= X_UA.IE ){ this.offsetX = e.offsetX; this.offsetY = e.offsetY; } else - if( pointerType = X_Event_toPointer[ originalType ] ){ + if( pointerEventType = X_Event_toPointer[ originalType ] ){ // Touch or Mouse + //console.log( originalType + ' => ' + pointerEventType ); /* e.constructor === window.TouchEvent -> e.touches for iOS3.13 */ if( touches = e.changedTouches ){ + //console.log( originalType + ' => ' + pointerEventType ); if( touches.length === 0 ){ alert( 'e.changedTouches.length === 0' ); }; - xnode._cancelMouse = pointerType; + xnode._cancelMouse = pointerEventType; events = []; altKey = e.altKey; @@ -102,20 +117,21 @@ if( !X_UA.IE || 9 <= X_UA.IE ){ metaKey = e.metaKey; shiftKey = e.shiftKey; time = X_Timer_now(); + force = originalType === 'touchend' || originalType === 'touchcancel' ? 0 : 0.5; for( i = touches.length; i; ){ touch = touches[ --i ]; target = touch.target; related = touch.relatedTarget; events[ i ] = { - type : pointerType, + type : pointerEventType, pointerType : 'touch', target : X_Node_getXNode( target.nodeType === 3 ? target.parentNode : target ),// defeat Safari bug // xnodetouch.target, currentTarget : xnode, - relatedTarget : X_Node_getXNode( related.nodeType === 3 ? related.parentNode : related ), // xnode + relatedTarget : related && X_Node_getXNode( related.nodeType === 3 ? related.parentNode : related ), // xnode iOS3 には relatedTarget がない isPrimary : true, hwTimestamp : time, timestamp : time, - buttons : e.button, + button : e.button, buttons : e.buttons || e.button, altKey : altKey, ctrlKey : ctrlKey, @@ -133,7 +149,7 @@ if( !X_UA.IE || 9 <= X_UA.IE ){ radiusX : touch.radiusX || 0, radiusY : touch.radiusY || 0, rotationAngle : touch.rotationAngle || 0, - pressure : touch.force || touch.webkitForce || ( isEnd ? 0 : 0.5 ), + pressure : touch.force || touch.webkitForce || force, width : touch.width || 0, height : touch.height || 0 }; @@ -141,14 +157,14 @@ if( !X_UA.IE || 9 <= X_UA.IE ){ return events.length === 1 ? events[ 0 ] : events; } else { - if( xnode._cancelMouse === pointerType ){ + if( xnode._cancelMouse === pointerEventType ){ delete xnode._cancelMouse; console.log( '**** xnode._cancelMouse ' + xnode._cancelMouse ); return []; }; // MouseEvent; - this.type = type; + this.type = pointerEventType; this.pointerType = 'mouse'; this.button = e.button !== undefined ? e.button : @@ -213,7 +229,7 @@ if( !X_UA.IE || 9 <= X_UA.IE ){ if( e.deltaY !== undefined ){ this.deltaX = e.deltaX; this.deltaY = e.deltaY; - this.deltaZ = e.deltaZ; + this.deltaZ = e.deltaZ || 0; } else if( e.wheelDeltaY !== undefined ){ this.deltaX = e.wheelDeltaX / 120; @@ -254,6 +270,19 @@ if( !X_UA.IE || 9 <= X_UA.IE ){ this.ctrlKey = e.ctrlKey; this.shiftKey = e.shiftKey; + + switch( this.type ){ + case 'message' : + this.data = e.data; + this.origin = e.origin; + this.source = e.source; + break; + case 'progress' : + this.loaded = e.loaded; + this.total = e.total; + break; + }; + // http://www.programming-magic.com/20090127231544/ switch( originalType ){ case 'click' : @@ -313,14 +342,6 @@ if( !X_UA.IE || 9 <= X_UA.IE ){ }; }; -X.Dom.Event.ANIME_BEFORE_START = ++X_Event_last; -X.Dom.Event.ANIME_START = ++X_Event_last; -X.Dom.Event.ANIME = ++X_Event_last; -X.Dom.Event.ANIME_END = ++X_Event_last; -X.Dom.Event.ANIME_BEFORE_STOP = ++X_Event_last; // xnode.stop() のみ、指定時間による停止では呼ばれない -X.Dom.Event.ANIME_STOP = ++X_Event_last; - - // TODO load -> readystatechange this.readyState === "loaded" || this.readyState === "complete" /* X.Dom.Event._LOAD_FIX_TAGS = { @@ -411,11 +432,11 @@ if( !navigator.pointerEnabled ){ } else if( X_UA_HID.TOUCH ){ // touch のみ(iOS でも脱獄したら?)、 touch と mouse(Android), mouse のみ - X_Event_Rename[ 'pointerdown' ] = [ 'touchdown', 'mousedown' ]; - X_Event_Rename[ 'pointerup' ] = [ 'touchup', 'mouseup' ]; - X_Event_Rename[ 'pointermove' ] = [ 'touchmove', 'mousemove' ]; + X_Event_Rename[ 'pointerdown' ] = [ 'touchstart', 'mousedown' ]; + X_Event_Rename[ 'pointerup' ] = [ 'touchend', 'mouseup' ]; + X_Event_Rename[ 'pointermove' ] = [ 'touchmove', 'mousemove' ]; X_Event_Rename[ 'pointercancel' ] = 'touchcancel'; - // X_Event_Rename[ 'click' ] = [ 'touchdown', 'touchmove', 'touchup' ]; // ループになってしまう!直した!直ってない! + // X_Event_Rename[ 'click' ] = [ 'touchstart', 'touchmove', 'touchend' ]; // ループになってしまう!直した!直ってない! } else { X_Event_Rename[ 'pointerdown' ] = 'mousedown'; X_Event_Rename[ 'pointerup' ] = 'mouseup';