X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=0.6.x%2Fjs%2F02_dom%2F03_XDomEvent.js;h=7c94b060a6138254cf344b2254d6e94bb347fe4e;hb=009b1cd0cebdd15591a9abfb964fb57b41ccb5f9;hp=183090e4d5d93c5d258ddf4841b6a9cb746aa300;hpb=541618cd9485cb041f46177d6869cc6d618ed1da;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 183090e..7c94b06 100644 --- a/0.6.x/js/02_dom/03_XDomEvent.js +++ b/0.6.x/js/02_dom/03_XDomEvent.js @@ -1,4 +1,4 @@ -/** +/* * use X.Callback * * http://d.hatena.ne.jp/uupaa/20100430/1272561922 @@ -11,190 +11,232 @@ */ // http://msdn.microsoft.com/ja-jp/library/ie/dn255104%28v=vs.85%29.aspx -var X_Dom_Event_devicePixelRatio = window.devicePixelRatio || ( window.screen.deviceXDPI / window.screen.logicalXDPI ), - X_Dom_Event_convertMSPointerType = window.MSPointerEvent && { - 2 : 'touch', - 3 : 'pen', - 4 : 'mouse' - }; +var X_Dom_Event_devicePixelRatio = window.devicePixelRatio || ( window.screen.deviceXDPI / window.screen.logicalXDPI ) || 1, -if( !X.UA.IE || 9 <= X.UA.IE ){ - X.Dom.Event = function( e, xnode ){ - var _type = e.type, - type, - changedTouches, targetTouches, targetIDs, changedTargets, isEnd, - altKey, ctrlKey, metaKey, shiftKey, target, related, - i, n, time, touch, ev; + X_Dom_Event_convertMSPointerType = ( !window.PointerEvent && window.MSPointerEvent ) && [ 0, 0, 'touch', 'pen', 'mouse' ], // WP8.1 は PointerEvent と MSPointerEvent 両方ある + /*{ + '2' : 'touch', + '3' : 'pen', + '4' : 'mouse' + }; */ + X_Dom_Event_CANCEL_MOUSE = {}, + X_DomEvent; + +if( X_Dom_Event_devicePixelRatio !== 1 ){ + X_UA_classNameForHTML += ' dpr' + X_Dom_Event_devicePixelRatio; + + X_UA[ 'dpr' ] = X_Dom_Event_devicePixelRatio; +}; + +if( !X_UA[ 'IE' ] || 9 <= X_UA[ 'IE' ] ){ + X_DomEvent = function( e, xnode ){ + var originalType = e.type, + type, pointerEventType, + touches, events, + altKey, ctrlKey, metaKey, shiftKey, target, related, force, + elm, i, n, time, touch, ev; //this._event = e; - this.type = type = X.Dom.Event.RenameTo[ _type ] || _type; + this[ 'type' ] = type = X_Event_RenameTo[ originalType ] || originalType; + 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; + case 'dragstart' : + case 'dragenter' : + case 'dragover' : + case 'dragleave' : + case 'drop' : + case 'dragend' : + this[ 'dataTransfer' ] = e.dataTransfer; + break; + }; + + //console.log( 'original : ' + originalType + ' > ' + type ); // http://msdn.microsoft.com/ja-jp/library/ie/dn304886%28v=vs.85%29.aspx // ポインター イベントの更新 if( e.pointerType ){ // PointerEvent; if( X_Dom_Event_convertMSPointerType ){ - this.pointerType = X_Dom_Event_convertMSPointerType[ e.pointerType ]; - this.pressure = e.pressure || ( e.button !== -1 ? 0.5 : 0 ); + this[ 'pointerType' ] = X_Dom_Event_convertMSPointerType[ e.pointerType ]; + this[ 'pressure' ] = e.pressure || ( e.button !== -1 ? 0.5 : 0 ); // ポインターの接触形状の スクリーン ピクセル単位の幅と高さ なので変換。(多分、、、) - this.width = e.width / X_Dom_Event_devicePixelRatio; - this.height = e.height / X_Dom_Event_devicePixelRatio; + this[ 'width' ] = e.width / X_Dom_Event_devicePixelRatio; + this[ 'height' ] = e.height / X_Dom_Event_devicePixelRatio; } else { - this.pointerType = e.pointerType; - this.pressure = e.pressure; + this[ 'pointerType' ] = e.pointerType; + this[ 'pressure' ] = e.pressure; // ポインターの接触形状の CSS ピクセル単位の幅と高さ。 - this.width = e.width; - this.height = e.height; + this[ 'width' ] = e.width; + this[ 'height' ] = e.height; }; - switch( this.pointerType ){ + switch( this[ 'pointerType' ] ){ case 'pen' : //Y-Z 平面と、ペンの軸が含まれる平面の間の角度を返します。Y 軸の範囲は -90 ~ +90 です。X の傾きの正の方向は右方向です。 - this.tiltX = e.tiltX; - this.tiltY = e.tiltY; - if( _type === 'MSPointerHover' ){ - this.type = 'pointermove'; // ie10 には pointerhover と pointermoveがあり、ie11 で一本化。ie11 では buttons を見て hover 状態を判定 + this[ 'tiltX' ] = e.tiltX; + this[ 'tiltY' ] = e.tiltY; + if( originalType === 'MSPointerHover' ){ + this[ 'type' ] = 'pointermove'; // ie10 には pointerhover と pointermoveがあり、ie11 で一本化。ie11 では buttons を見て hover 状態を判定 }; case 'touch' : - this.radiusX = e.radiusX; - this.radiusY = e.radiusY; - this.rotationAngle = e.rotationAngle; + this[ 'radiusX' ] = e.radiusX; + this[ 'radiusY' ] = e.radiusY; + this[ 'rotationAngle' ] = e.rotationAngle; case 'mouse' : }; - this.button = e.button; - this.buttons = e.buttons; + this[ 'button' ] = e.button; + this[ 'buttons' ] = e.buttons; - this.pointerId = e.pointerId; - this.target = Node._getXNode( e.target ); - this.relatedTarget = Node._getXNode( e.relatedTarget ); // xnode - this.isPrimary = e.isPrimary; - this.hwTimestamp = e.hwTimestamp; - this.timestamp = e.timestamp; + this[ 'pointerId' ] = e.pointerId; + this[ 'target' ] = X_Node_getXNode( e.target ); + this[ 'relatedTarget' ] = X_Node_getXNode( e.relatedTarget ); // xnode + this[ 'isPrimary' ] = e.isPrimary; + this[ 'hwTimestamp' ] = e.hwTimestamp; + this[ 'timestamp' ] = e.timestamp; - this.altKey = e.altKey; - this.ctrlKey = e.ctrlKey; - this.metaKey = e.metaKey; - this.shiftKey = e.shiftKey; - //this.screenX = touch.screenX; - //this.screenY = touch.screenY; - this.clientX = e.clientX; - this.clientY = e.clientY; - this.pageX = e.pageX; - this.pageY = e.pageY; - this.offsetX = e.offsetX; - this.offsetY = e.offsetY; + this[ 'altKey' ] = e.altKey; + this[ 'ctrlKey' ] = e.ctrlKey; + this[ 'metaKey' ] = e.metaKey; + this[ 'shiftKey' ] = e.shiftKey; + //this[ 'screenX' ] = touch.screenX; + //this[ 'screenY' ] = touch.screenY; + this[ 'clientX' ] = e.clientX; + this[ 'clientY' ] = e.clientY; + this[ 'pageX' ] = e.pageX; + this[ 'pageY' ] = e.pageY; + this[ 'offsetX' ] = e.offsetX; + this[ 'offsetY' ] = e.offsetY; } else - if( X.Dom.Event.toPointer[ _type ] ){ + 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 ){ + if( touches = e.changedTouches ){ + //console.log( originalType + ' => ' + pointerEventType ); if( touches.length === 0 ){ alert( 'e.changedTouches.length === 0' ); }; - xnode._cancelMouse = type; + X_Dom_Event_CANCEL_MOUSE[ xnode[ '_uid' ] ] = pointerEventType; events = []; altKey = e.altKey; ctrlKey = e.ctrlKey; metaKey = e.metaKey; shiftKey = e.shiftKey; - time = X.getTime(); + 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 : type, - pointerType : 'touch', - target : Node._getXNode( target.nodeType === 3 ? target.parentNode : target ),// defeat Safari bug // xnodetouch.target, - currentTarget : xnode, - relatedTarget : Node._getXNode( related.nodeType === 3 ? related.parentNode : related ), // xnode - isPrimary : true, - hwTimestamp : time, - timestamp : time, - buttons : e.button, - buttons : e.buttons || e.button, - altKey : altKey, - ctrlKey : ctrlKey, - metaKey : metaKey, - shiftKey : shiftKey, - pointerId : touch.identifier + 2, + 'type' : pointerEventType, + 'pointerType' : 'touch', + 'target' : X_Node_getXNode( target.nodeType === 3 ? target.parentNode : target ),// defeat Safari bug // xnodetouch.target, + 'currentTarget' : xnode, + 'relatedTarget' : related && X_Node_getXNode( related.nodeType === 3 ? related.parentNode : related ), // xnode iOS3 には relatedTarget がない + 'isPrimary' : true, + 'hwTimestamp' : time, + 'timestamp' : time, + 'button' : /*e.button ||*/ ( force ? 0 : -1 ), + 'buttons' : /*e.buttons || e.button ||*/ ( force ? 1 : 0 ), + 'altKey' : altKey, + 'ctrlKey' : ctrlKey, + 'metaKey' : metaKey, + 'shiftKey' : shiftKey, + 'pointerId' : touch.identifier + 2, // iOS4 は 変換が必要! //screenX : touch.screenX, //screenY : touch.screenY, - clientX : touch.clientX, - clientY : touch.clientY, - pageX : touch.pageX, - pageY : touch.pageY, - offsetX : touch.offsetX, // 要素上の座標を取得 - offsetY : touch.offsetY, - radiusX : touch.radiusX || 0, - radiusY : touch.radiusY || 0, - rotationAngle : touch.rotationAngle || 0, - pressure : touch.force || touch.webkitForce || ( isEnd ? 0 : 0.5 ), - width : touch.width || 0, - height : touch.height || 0 + 'clientX' : touch.clientX || ( touch.pageX - X_ViewPort_scrollX ), // iOS4以下は clientX が undefined, コードでは入れ子のスクロールに対応できない + 'clientY' : touch.clientY || ( touch.pageY - X_ViewPort_scrollY ), + 'pageX' : touch.pageX, + 'pageY' : touch.pageY, + 'offsetX' : touch.offsetX, // 要素上の座標を取得 + 'offsetY' : touch.offsetY, + 'radiusX' : touch.radiusX || 0, + 'radiusY' : touch.radiusY || 0, + 'rotationAngle' : touch.rotationAngle || 0, + 'pressure' : touch.force || touch.webkitForce || force, + 'width' : touch.width || 0, + 'height' : touch.height || 0 }; + //console.log( 'e.pointerId = ' + touch.identifier ); }; return events.length === 1 ? events[ 0 ] : events; } else { - if( xnode._cancelMouse === type ){ - delete xnode._cancelMouse; + if( X_Dom_Event_CANCEL_MOUSE[ xnode[ '_uid' ] ] === pointerEventType ){ + delete X_Dom_Event_CANCEL_MOUSE[ xnode[ '_uid' ] ]; return []; }; // MouseEvent; - this.type = type; - this.pointerType = 'mouse'; + this[ 'type' ] = pointerEventType; + this[ 'pointerType' ] = 'mouse'; - // http://www.programming-magic.com/20090127231544/ - // TODO Opera で button==2の場合、コンテキストメニューイベントを発火 「ツール」->「設定」->「詳細設定」->「コンテンツ」->「Javascriptオプション」で「右クリックを制御するスクリプトを許可する」 - this.button = e.button !== undefined ? e.button : - e.which !== undefined ? e.which - 1 : -1; - this.buttons = e.buttons !== undefined ? e.buttons : this.button === 0 ? 1 : this.button === 1 ? 2 : this.button === 2 ? 4 : 0; - this.pressure = ( this.button !== -1 ? 0.5 : 0 ); + this[ 'button' ] = e.button !== undefined ? e.button : e.which !== undefined ? e.which - 1 : -1; + this[ 'buttons' ] = e.buttons !== undefined ? e.buttons : this[ 'button' ] === 0 ? 1 : this[ 'button' ] === 1 ? 2 : this[ 'button' ] === 2 ? 4 : 0; + this[ 'pressure' ] = ( this[ 'button' ] !== -1 ? 0.5 : 0 ); elm = e.target; - this.target = Node._getXNode( elm.nodeType === 3 ? elm.parentNode : elm );// defeat Safari bug // xnodetouch.target; - this.isPrimary = true; - this.hwTimestamp = this.timestamp = X.getTime(); - this.altKey = e.altKey; - this.ctrlKey = e.ctrlKey; - this.metaKey = e.metaKey; - this.shiftKey = e.shiftKey; - this.pointerId = 1; - //this.screenX = touch.screenX; - //this.screenY = touch.screenY; + this[ 'target' ] = X_Node_getXNode( elm.nodeType === 3 ? elm.parentNode : elm );// defeat Safari bug // xnodetouch.target; + this[ 'isPrimary' ] = true; + this[ 'hwTimestamp' ] = this[ 'timestamp' ] = X_Timer_now(); + this[ 'altKey' ] = e.altKey; + this[ 'ctrlKey' ] = e.ctrlKey; + this[ 'metaKey' ] = e.metaKey; + this[ 'shiftKey' ] = e.shiftKey; + this[ 'pointerId' ] = 1; + //this[ 'screenX' ] = touch.screenX; + //this[ 'screenY' ] = touch.screenY; // TODO http://uupaa-js.googlecode.com/svn-history/r8/trunk/doc/reference/symbols/src/trunk_uu.module.ui.js.html // Safari2ではclientX,YはpageX,Yと同じ値を返す - this.clientX = e.clientX; - this.clientY = e.clientY; - this.pageX = e.pageX; - this.pageY = e.pageY; - this.offsetX = e.offsetX || e.layerX; // 要素上の座標を取得 - this.offsetY = e.offsetY || e.layerY; + this[ 'clientX' ] = e.clientX; + this[ 'clientY' ] = e.clientY; + this[ 'pageX' ] = e.pageX; + this[ 'pageY' ] = e.pageY; + this[ 'offsetX' ] = e.offsetX || e.layerX; // 要素上の座標を取得 + this[ 'offsetY' ] = e.offsetY || e.layerY; + + // http://www.programming-magic.com/20090127231544/ + // Opera で button==2の場合、コンテキストメニューイベントを発火 「ツール」->「設定」->「詳細設定」->「コンテンツ」->「Javascriptオプション」で「右クリックを制御するスクリプトを許可する」 + if( originalType === 'mousedown' && this[ 'button' ] === 2 && X_UA[ 'Opera' ] ){ + events = [ X_Object_copy( this ), X_Object_copy( this ) ]; + events[ 1 ].type = 'contextmenu'; + return events; + }; }; } else { // Other - this.keyCode = e.keyCode || e.which; - this.altKey = e.altKey; - this.ctrlKey = e.ctrlKey; - this.shiftKey = e.shiftKey; - this.metaKey = e.metaKey; + this[ 'keyCode' ] = X_Type_isFinite( e.keyCode ) ? e.keyCode : X_Type_isFinite( e.charCode ) ? e.charCode : e.which; + this[ 'charCode' ] = X_Type_isFinite( e.charCode ) ? e.charCode : e.which; + this[ 'altKey' ] = e.altKey || !!( e.modifiers & 1 ); + this[ 'ctrlKey' ] = e.ctrlKey || !!( e.modifiers & 2 ); + this[ 'shiftKey' ] = e.shiftKey || !!( e.modifiers & 4 ); + this[ 'metaKey' ] = e.metaKey || !!( e.modifiers & 8 );; - this.button = e.button !== undefined ? e.button : + this[ 'button' ] = e.button !== undefined ? e.button : e.which !== undefined ? e.which - 1 : -1; - this.buttons = e.buttons !== undefined ? e.buttons : this.button === 0 ? 1 : this.button === 1 ? 2 : this.button === 2 ? 4 : 0; + this[ 'buttons' ] = e.buttons !== undefined ? e.buttons : this[ 'button' ] === 0 ? 1 : this[ 'button' ] === 1 ? 2 : this[ 'button' ] === 2 ? 4 : 0; //http://www.quirksmode.org/js/events_properties.html if( elm = e.target ){ - this.target = Node._getXNode( elm.nodeType === 3 ? elm.parentNode : elm );// defeat Safari bug // xnode + this[ 'target' ] = X_Node_getXNode( elm.nodeType === 3 ? elm.parentNode : elm );// defeat Safari bug // xnode }; if( elm = e.relatedTarget ){ - this.relatedTarget = Node._getXNode( elm.nodeType === 3 ? elm.parentNode : elm ); // xnode + this[ 'relatedTarget' ] = X_Node_getXNode( elm.nodeType === 3 ? elm.parentNode : elm ); // xnode }; if( type === 'wheel' ){ @@ -203,186 +245,146 @@ if( !X.UA.IE || 9 <= X.UA.IE ){ // https://w3g.jp/blog/tools/wheelevent_crossbrowser // ホイール系イベント2014年版クロスブラウザ if( e.deltaY !== undefined ){ - this.deltaX = e.deltaX; - this.deltaY = e.deltaY; - this.deltaZ = e.deltaZ; + this[ 'deltaX' ] = e.deltaX; + this[ 'deltaY' ] = e.deltaY; + this[ 'deltaZ' ] = e.deltaZ || 0; } else if( e.wheelDeltaY !== undefined ){ - this.deltaX = e.wheelDeltaX / 120; - this.deltaY = e.wheelDeltaY / 120; - this.deltaZ = e.wheelDeltaZ / 120 || 0; + this[ 'deltaX' ] = e.wheelDeltaX / 120; + this[ 'deltaY' ] = e.wheelDeltaY / 120; + this[ 'deltaZ' ] = e.wheelDeltaZ / 120 || 0; } else if( e.wheelDelta !== undefined ){ - this.deltaX = this.deltaZ = 0; - this.deltaY = e.wheelDelta / -120; + this[ 'deltaX' ] = this[ 'deltaZ' ] = 0; + this[ 'deltaY' ] = e.wheelDelta / -120; } else if( e.detail !== undefined ){ - this.deltaX = this.deltaZ = 0; - this.deltaY = _type === 'MozMousePixelScroll' ? e.detail / 45 : e.detail / 3; // 3 + this[ 'deltaX' ] = this[ 'deltaZ' ] = 0; + this[ 'deltaY' ] = originalType === 'MozMousePixelScroll' ? e.detail / 45 : e.detail / 3; // 3 } else { - this.deltaX = this.deltaY = this.deltaZ = 0; + this[ 'deltaX' ] = this[ 'deltaY' ] = this[ 'deltaZ' ] = 0; }; - }; + }; }; - this.currentTarget = xnode; // xnode - this.eventPhase = e.eventPhase; - this.detail = e.detail; - + this[ 'currentTarget' ] = xnode; // xnode + this[ 'eventPhase' ] = e.eventPhase; + this[ 'detail' ] = e.detail; }; } else { - X.Dom.Event = function( e, xnode, element ){ - var btn; + X_DomEvent = function( e, xnode, element ){ + var originalType = e.type, btn, type; - this.type = X.Dom.Event.RenameTo[ e.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.toElement ); // xnode - this.eventPhase = e.srcElement === element ? 2: 3; + this[ 'type' ] = X_Event_RenameTo[ originalType ] || originalType; + this[ 'target' ] = X_Node_getXNode( e.srcElement ); // xnode + if( this[ 'target' ] && !this[ 'target' ][ '_tag' ] ) this[ 'target' ] = this[ 'target' ].parent; // ie4 の fake Textnode がヒットしていないか? + this[ 'currentTarget' ] = xnode; // xnode + this[ 'relatedTarget' ] = X_Node_getXNode( e.formElement || e.toElement ); // xnode + this[ 'relatedTarget' ] && console.dir( 'relatide...' ); + this[ 'eventPhase' ] = e.srcElement === element ? 2: 3; - this.keyCode = e.keyCode; - this.altKey = e.altKey; - this.ctrlKey = e.ctrlKey; - this.shiftKey = e.shiftKey; + this[ 'keyCode' ] = e.keyCode; + this[ 'charCode' ] = e.keyCode; + this[ 'altKey' ] = e.altKey; + 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( this.type ){ + switch( originalType ){ case 'click' : case 'dblclick' : - this.button = 0; + this[ 'button' ] = 0; break; case 'contextmenu' : - this.button = 2; + this[ 'button' ] = 2; break; default : // mouseup, mousedown btn = e.button; - this.button = + this[ 'button' ] = btn & 1 ? 0 : btn & 4 ? 2 : btn & 2 ? 1 : -1; // 左:1(click:0), 中:4, 右:2 }; - this.buttons = e.button; + this[ 'buttons' ] = e.button; + + this[ 'deltaX' ] = 0; + this[ 'deltaY' ] = e.wheelDelta / -120; - if( type = X.Dom.Event.toPointer[ e.type ] ){ - this.type = type; - this.clientX = e.clientX; - this.clientY = e.clientY; - //this.screenX = e.screenX; - //this.screenY = e.screenY; + if( type = X_Event_toPointer[ originalType ] ){ + this[ 'type' ] = type; + this[ 'pointerType' ] = 'mouse'; + 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; + //if( X_ViewPort_rootElement ){ // uuu... + this[ 'pageX' ] = e.clientX + X_ViewPort_rootElement.scrollLeft; + this[ 'pageY' ] = e.clientY + X_ViewPort_rootElement.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( 5 <= X.UA.IE ){ - this.offsetX = e.offsetX; // イベントターゲット左上からの座標 - this.offsetY = e.offsetY; + if( 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[ 'offsetX' ] = e.x - e.srcElement.offsetLeft; // e.x はイベント発生要素の親要素を基準にした座標。 + // this[ 'offsetY' ] = e.y - e.srcElement.offsetTop; //}; - - this.deltaX = 0; - this.deltaY = e.wheelDelta / -120; - - this.pointerId = 1; - this.radiusX = 0; - this.radiusY = 0; - this.rotationAngle = 0; - this.width = 0; - this.height = 0; - this.tiltX = 0; - this.tiltY = 0; + this[ 'pressure' ] = ( this[ 'button' ] !== -1 ? 0.5 : 0 ); + this[ 'isPrimary' ] = true; + this[ 'hwTimestamp' ] = this[ 'timestamp' ] = X_Timer_now(); + this[ 'pointerId' ] = 1; + this[ 'radiusX' ] = 0; + this[ 'radiusY' ] = 0; + this[ 'rotationAngle' ] = 0; + this[ 'width' ] = 0; + this[ 'height' ] = 0; + this[ 'tiltX' ] = 0; + this[ 'tiltY' ] = 0; }; }; }; -X.Dom.Event.DOM_PRE_INIT = ++X.Event._LAST_EVENT; -X.Dom.Event.DOM_BUILDER_COMPLETE= ++X.Event._LAST_EVENT; -X.Dom.Event.DOM_INIT = ++X.Event._LAST_EVENT; -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 -// on_screen_keyboard_hide -// X.Dom.Event.BEFORE_UPDATE = ++X.Event._LAST_EVENT; // このイベントで要素のサイズを取得すると無限ループに! -X.Dom.Event.AFTER_UPDATE = ++X.Event._LAST_EVENT; -// hash_change -X.Dom.Event.BEFORE_UNLOAD = ++X.Event._LAST_EVENT; -X.Dom.Event.UNLOAD = ++X.Event._LAST_EVENT; - -X.Dom.Event.ANIME_BEFORE_START = ++X.Event._LAST_EVENT; -X.Dom.Event.ANIME_START = ++X.Event._LAST_EVENT; -X.Dom.Event.ANIME = ++X.Event._LAST_EVENT; -X.Dom.Event.ANIME_END = ++X.Event._LAST_EVENT; -X.Dom.Event.ANIME_BEFORE_STOP = ++X.Event._LAST_EVENT; // xnode.stop() のみ、指定時間による停止では呼ばれない -X.Dom.Event.ANIME_STOP = ++X.Event._LAST_EVENT; -X.Dom.Event._LAST_EVENT = X.Event._LAST_EVENT; // ここに書いてあるイベントの最後の値 X.Dom.Event.ANIME_STOP と同じ値 - // TODO load -> readystatechange this.readyState === "loaded" || this.readyState === "complete" -X.Dom.Event._LOAD_FIX_TAGS = { - IFRAME : true, - SCRIPT : true//, - //LINK : true -}; - -X.Dom.Event.Rename = {}; -X.Dom.Event.RenameTo = {}; -X.Dom.Event.toPointer = !X.Dom.EVENT_POINTER && ( X.Dom.EVENT_TOUCH ? - { - touchdown : 'pointerdown', - mousedown : 'pointerdown', - touchup : 'pointerup', - mouseup : 'pointerup', - touchmove : 'pointermove', - mousemove : 'pointermove', - touchcancel : 'pointercancel', - contextmenu : 'contextmenu', - dbclick : 'dbclick', - click : 'click', - tap : 'click' - } : - { - mousedown : 'pointerdown', - mouseup : 'pointerup', - mousemove : 'pointermove', - contextmenu : 'contextmenu', - dbclick : 'dbclick', - click : 'click' - }); - // https://github.com/georgeadamson/jQuery.prefixfree-events/blob/master/jQuery.prefixfree-events.js // https://developer.mozilla.org/en-US/docs/Web/Events/wheel // if( document.onwheel === undefined ){ // 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+) + 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( 'wheel <= MozMousePixelScroll' ); - X.Dom.Event.Rename[ 'wheel' ] = 'MozMousePixelScroll'; + X_Event_Rename[ 'wheel' ] = 'MozMousePixelScroll'; } else - if( 1 <= X.UA.Gecko || ( 0.9 <= X.UA.Gecko && 7 <= X.UA.GeckoPatch ) ){ // Gecko 0.9.7+ (NN6.2+?) + if( 1 <= X_UA[ 'Gecko' ] || ( 0.9 <= X_UA[ 'Gecko' ] && 7 <= X_UA[ 'GeckoPatch' ] ) ){ // Gecko 0.9.7+ (NN6.2+?) console.log( 'wheel <= DOMMouseScroll' ); - X.Dom.Event.Rename[ 'wheel' ] = 'DOMMouseScroll'; + X_Event_Rename[ 'wheel' ] = 'DOMMouseScroll'; }; } else { - X.Dom.Event.Rename[ 'wheel' ] = 'mousewheel'; + X_Event_Rename[ 'wheel' ] = 'mousewheel'; }; //if( document.onmousewheel !== undefined ){ // Opera で判定失敗する - // X.Dom.Event.Rename[ 'wheel' ] = 'mousewheel'; + // X_Event_Rename[ 'wheel' ] = 'mousewheel'; //}; }; @@ -390,135 +392,84 @@ if( document.onwheel === undefined ){ 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'; + X_Event_Rename[ 'animationend' ] = 'webkitAnimationEnd'; + X_Event_Rename[ 'animationstart' ] = 'webkitAnimationStart'; + X_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'; + X_Event_Rename[ 'animationend' ] = 'oAnimationEnd'; + X_Event_Rename[ 'animationstart' ] = 'oAnimationStart'; + X_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'; + X_Event_Rename[ 'animationend' ] = 'mozAnimationEnd'; + X_Event_RenameTo[ 'mozAnimationEnd' ] = 'animationend'; + X_Event_Rename[ 'animationstart' ] = 'mozAnimationStart'; + X_Event_RenameTo[ 'mozAnimationStart' ] = 'animationstart'; + X_Event_Rename[ 'animationiteration' ] = 'mozAnimationIteration'; + X_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'; + X_Event_Rename[ 'animationend' ] = 'MSAnimationEnd'; + X_Event_Rename[ 'animationstart' ] = 'MSAnimationStart'; + X_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 ){ console.log( 'transitionend <= webkitTransitionEnd' ); - X.Dom.Event.Rename[ 'transitionend' ] = 'webkitTransitionEnd'; + X_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'; + if( X_UA[ 'Opera' ] < 12 ){ + console.log( 'transitionend <= oTransitionEnd|ver.' + X_UA[ 'Opera' ] ); + X_Event_Rename[ 'transitionend' ] = 'oTransitionEnd'; } else { - console.log( 'transitionend <= otransitionEnd|ver.' + X.UA.Opera ); - X.Dom.Event.Rename[ 'transitionend' ] = 'otransitionEnd'; + console.log( 'transitionend <= otransitionEnd|ver.' + X_UA[ 'Opera' ] ); + X_Event_Rename[ 'transitionend' ] = 'otransitionEnd'; }; } else if( window.onmoztransitionend !== undefined && window.ontransitionend === undefined ){ console.log( 'transitionend <= mozTransitionEnd' ); - X.Dom.Event.Rename[ 'transitionend' ] = 'mozTransitionEnd'; + X_Event_Rename[ 'transitionend' ] = 'mozTransitionEnd'; }; if( !navigator.pointerEnabled ){ if( navigator.msPointerEnabled ){ console.log( 'pointerdown <= MSPointerDown' ); - X.Dom.Event.Rename[ 'pointerdown' ] = 'MSPointerDown'; - X.Dom.Event.Rename[ 'pointerup' ] = 'MSPointerUp'; - X.Dom.Event.Rename[ 'pointermove' ] = [ 'MSPointerMove', 'MSPointerHover' ];// ie10 と ie11 でペンのhoverevent の値が異なる - X.Dom.Event.Rename[ 'pointercancel' ] = 'MSPointerCancel'; + X_Event_Rename[ 'pointerdown' ] = 'MSPointerDown'; + X_Event_Rename[ 'pointerup' ] = 'MSPointerUp'; + X_Event_Rename[ 'pointermove' ] = [ 'MSPointerMove', 'MSPointerHover' ];// ie10 と ie11 でペンのhoverevent の値が異なる + X_Event_Rename[ 'pointercancel' ] = 'MSPointerCancel'; + X_Event_Rename[ 'pointerout' ] = 'MSPointerOut'; + X_Event_Rename[ 'pointerleave' ] = 'MSPointerLeave'; // http://msdn.microsoft.com/ja-jp/library/ie/dn304886%28v=vs.85%29.aspx } else - if( X.Dom.EVENT_TOUCH ){ - X.Dom.Event.Rename[ 'pointerdown' ] = [ 'touchdown', 'mousedown' ]; - X.Dom.Event.Rename[ 'pointerup' ] = [ 'touchup', 'mouseup' ]; - X.Dom.Event.Rename[ 'pointermove' ] = [ 'touchmove', 'mousemove' ]; - X.Dom.Event.Rename[ 'pointercancel' ] = 'touchcancel'; - X.Dom.Event.Rename[ 'click' ] = [ 'click', 'tap' ]; + if( X_UA_HID.TOUCH ){ + // touch のみ(iOS でも脱獄したら?)、 touch と mouse(Android), mouse のみ + 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[ 'pointerout' ] = + X_Event_Rename[ 'pointerleave' ] = 'touchleave'; + // X_Event_Rename[ 'click' ] = [ 'touchstart', 'touchmove', 'touchend' ]; // ループになってしまう!直した!直ってない! } else { - X.Dom.Event.Rename[ 'pointerdown' ] = 'mousedown'; - X.Dom.Event.Rename[ 'pointerup' ] = 'mouseup'; - X.Dom.Event.Rename[ 'pointermove' ] = 'mousemove'; - X.Dom.Event.Rename[ 'pointercancel' ] = 'mouseleave';//?? - // Opera - // X.Dom.Event.Rename[ 'contextmenu' ] = 'mousedown'; button==2 の場合 - }; -}; - - -(function( rename, renameTo ){ - var k, name, i; - for( k in rename ){ - name = rename[ k ]; - if( X.Type.isArray( name ) ){ - for( i = name.length; i; ){ - renameTo[ name[ --i ] ] = k; - }; - } else { - renameTo[ name ] = k; - }; - }; -})( X.Dom.Event.Rename, X.Dom.Event.RenameTo ); - - -/* ----------------------------------------------- - * Document Ready - * Dean Edwards/Matthias Miller/John Resig - */ - -// SafariでJavaScriptのデバッグをする方法 -// safari1.3 可 -// http://shimax.cocolog-nifty.com/search/2006/09/safarijavascrip_c54d.html - -/* for ie9+/Mozilla/Opera9 */ -if( X.Dom.EVENT_W3C ){ - Node._document.listenOnce( 'DOMContentLoaded', X.Dom._init ); -} else -if( 6 <= X.UA.IE && X.inHead ){ - // if this script in Head - document.write( "