X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=0.6.x%2Fjs%2Fui%2F05_XUI_Gesture.js;h=58f843270ad9c61957e401d0b4823c3b41edafdc;hb=46d3fdf2559c59963e53ff6136c3fd58cd8f7a6d;hp=a9a127668189c65d7baf287be36cadeeda74ed10;hpb=e2daa9cc6441d4766b21f45400e8c2032d00438a;p=pettanr%2FclientJs.git diff --git a/0.6.x/js/ui/05_XUI_Gesture.js b/0.6.x/js/ui/05_XUI_Gesture.js index a9a1276..58f8432 100644 --- a/0.6.x/js/ui/05_XUI_Gesture.js +++ b/0.6.x/js/ui/05_XUI_Gesture.js @@ -36,7 +36,7 @@ gestures = Detection.gestures, numTouches = 0,// count the total touches on the screen pointerType, i, l, touches, ret, active, gesture, startEv, - deltaTime, deltaX, deltaY, velocity; + hammer, deltaTime, deltaX, deltaY, velocity; if( !type ) return; @@ -44,13 +44,13 @@ type |= POINTER; switch( e.pointerType ){ case 'touch' : - case e.MSPOINTER_TYPE_TOUCH : + case 2 : //e.MSPOINTER_TYPE_TOUCH : type |= TOUCH; break; case 'pen' : - case e.MSPOINTER_TYPE_PEN : + case 3 : //e.MSPOINTER_TYPE_PEN : type |= PEN; break; case 'mouse' : - case e.MSPOINTER_TYPE_MOUSE : + case 4 : //e.MSPOINTER_TYPE_MOUSE : type |= MOUSE; break; default : return; @@ -109,7 +109,6 @@ target : e.target }]; }; - // if we are in a end event, but when we remove one touch and // we still have enough, set eventType to move if( 0 < numTouches && type & END ){ // eventType === Hammer.EVENT_END ){ @@ -255,7 +254,8 @@ // Register all gestures inside Gestures for( name in Gestures ){ - Gestures.hasOwnProperty( name ) && Detection.register( Gestures[ name ] ); + //Gestures.hasOwnProperty( name ) && + Detection.register( Gestures[ name ] ); }; if( navigator.pointerEnabled || navigator.msPointerEnabled ){ @@ -321,10 +321,7 @@ /* * "Android version < 2.2" return ev.touches.length === 1 when touchend, others return ev.touches.length === 0 */ - Hammer.DO_TOUCHES_FIX = Hammer.HAS_TOUCHEVENTS && ( function( ua, i ){ - if( ( i = ua.indexOf('android') ) === -1 ) return false; - return ( parseFloat( ua.substr( i + 8 ) ) || 0 ) < 2.2; - })( navigator.userAgent.toLowerCase() ); + Hammer.DO_TOUCHES_FIX = Hammer.HAS_TOUCHEVENTS && X.UA.Android < 2.2; // detect touchevents Hammer.HAS_POINTEREVENTS = navigator.pointerEnabled || navigator.msPointerEnabled; @@ -595,7 +592,9 @@ */ register : function( gesture ){ // add an enable gesture options if there is no given - var options = gesture.defaults || {}; + var options = gesture.defaults || {}, + list = Detection.gestures, + _index, i = 0, l = list.length, index; if( options[ gesture.name ] === undefined ) options[ gesture.name ] = true; // extend Hammer default options with the Hammer.gesture options @@ -605,14 +604,34 @@ gesture.index = gesture.index || 1000; // add Hammer.gesture to the list - Detection.gestures.push( gesture ); + //Detection.gestures.push( gesture ); // sort the list by index - Detection.gestures.sort( function( a, b ){ - return - a.index < b.index ? -1 : - a.index > b.index ? 1 : 0; - }); + //Detection.gestures.sort( function( a, b ){ + // return + // a.index < b.index ? -1 : + // a.index > b.index ? 1 : 0; + //}); + if( l === 0 ){ + list[ 0 ] = gesture; + return; + }; + _index = gesture.index; + for( i = 0; i < l; ++i ){ + index = list[ i ].index; + if( i === 0 && _index < index ){ + list.unshift( gesture ); + return; + } else + if( i === l - 1 ){ + list[ l ] = gesture; + return; + } else + if( index <= _index && _index < list[ i + 1 ].index ){ + list.splice( i, 0, gesture ); + return; + }; + }; } }; @@ -731,8 +750,8 @@ * @events hold holdend */ Gestures.Hold = { - name : 'hold', - index : 10, + name : 'hold', + index : 10, startID : X.UI.Event.HOLD, endID : X.UI.Event.HOLD_END, defaults : { @@ -808,7 +827,7 @@ // do a single tap if( hammer.options.tap_always ){ Detection.current.name = 'tap'; - return hammer.trigger( X.UI.Event.TAP, e ); + return hammer.trigger( X.UI.Event.TAP, e ); }; }; } @@ -820,14 +839,14 @@ * @events swipe, swipeleft, swiperight, swipeup, swipedown */ Gestures.Swipe = { - name : 'swipe', - index : 40, + name : 'swipe', + index : 40, startID : X.UI.Event.SWIP, endID : X.UI.Event.SWIP_DOWN, defaults : { // set 0 for unlimited, but this can conflict with transform swipe_max_touches : 1, - swipe_velocity : 0.7 + swipe_velocity : 0.7 }, handler : function swipeGesture(e, hammer) { if( e.eventType === END ){ @@ -862,8 +881,8 @@ * @events drag, dragstart, dragend, drapleft, dragright, dragup, dragdown */ Gestures.Drag = { - name : 'drag', - index : 50, + name : 'drag', + index : 50, startID : X.UI.Event.DRAG, endID : X.UI.Event.DRAG_DOWN, defaults : { @@ -964,8 +983,8 @@ * @events transform, transformstart, transformend, pinch, pinchin, pinchout, rotate */ Gestures.Transform = { - name : 'transform', - index : 45, + name : 'transform', + index : 45, startID : X.UI.Event.TRANSFORM, endID : X.UI.Event.ROTATE, defaults : { @@ -1044,8 +1063,8 @@ * @events touch */ Gestures.Touch = { - name : 'touch', - index : -Infinity, + name : 'touch', + index : -Infinity, defaults : { // call preventDefault at touchstart, and makes the element blocking by // disabling the scrolling of the page, but it improves gestures like @@ -1075,8 +1094,8 @@ * @events release */ Gestures.Release = { - name : 'release', - index : Infinity, + name : 'release', + index : Infinity, handler : function releaseGesture( e, hammer ){ e.eventType === END && hammer.trigger( this.name, e ); }