* Jorik Tangelder <j.tangelder@gmail.com>, MIT license\r
**/\r
\r
-( function( Math, window, document, undefined ){\r
\r
var ELEENT_LIST = [],\r
HAMMER_LIST = [],\r
POINTERS = [],\r
ABS = new Function( 'v', 'return v<0?-v:v' );\r
\r
- X.UI.Gesture = Hammer;\r
- \r
function Hammer( uinodeRoot, uinode, type ){\r
this.uinode = uinode;\r
this.enabled = true;\r
pointerType, i, l, touches, ret, active, gesture, startEv,\r
hammer, deltaTime, deltaX, deltaY, velocity, center;\r
\r
- //console.log( 'Hammer@handleEvent ' + X.UI.Event.IdToName[ e.type ] + ' ' + e.pointerType + ' ' + type );\r
+ //console.log( 'Hammer@handleEvent ' + XUI_Event.IdToName[ e.type ] + ' ' + e.pointerType + ' ' + type );\r
if( !type ) return;\r
\r
- //console.log( e.type + ' dw:' + X.UI.Event._POINTER_DOWN + ' up:' + X.UI.Event._POINTER_UP + ' mv:' + X.UI.Event._POINTER_MOVE );\r
+ //console.log( e.type + ' dw:' + XUI_Event._POINTER_DOWN + ' up:' + XUI_Event._POINTER_UP + ' mv:' + XUI_Event._POINTER_MOVE );\r
\r
if( e.pointerType ){\r
type |= POINTER;\r
// onmouseup, but when touchend has been fired we do nothing.\r
// this is for touchdevices which also fire a mouseup on touchend\r
if( type & MOUSE && touch_triggered ){\r
- return X_Callback_STOP_NOW | X_Callback_PREVENT_DEFAULT;\r
+ return X_CALLBACK_STOP_NOW | X_CALLBACK_PREVENT_DEFAULT;\r
} else\r
// mousebutton must be down or a touch event\r
if( type & TOUCH || //sourceEventType.match(/touch/) || // touch events are always on screen\r
enable_detect = true;\r
};\r
\r
- //console.log( 'Hammer@handleEvent ' + IdToGestureID[ e.type ] + ' ' + e.type + ' ' + X.UI.Event._POINTER_DOWN + ' ' + enable_detect );\r
+ //console.log( 'Hammer@handleEvent ' + IdToGestureID[ e.type ] + ' ' + e.type + ' ' + XUI_Event._POINTER_DOWN + ' ' + enable_detect );\r
\r
// we are in a touch event, set the touch triggered bool to true,\r
// this for the conflicts that may occur on ios and android\r
// and we are now handling a mouse event, we stop that to prevent conflicts\r
if( enable_detect ){\r
// update pointerevent\r
- if( Hammer.HAS_POINTEREVENTS ){ //eventType !== Hammer.EVENT_END ){\r
- POINTERS[ e.identifier = e.pointerId ] = type & END ? null : e;\r
- touches = [];\r
- // we can use forEach since pointerEvents only is in IE10\r
- for( i = 0, l = POINTERS.length; i < l; ++i ){\r
- POINTERS[ i ] && ( touches[ touches.length ] = POINTERS[ i ] );\r
- };\r
- numTouches = touches.length;\r
- \r
- ///console.log( 'numTouches ' + numTouches );\r
- } else\r
- // touch\r
- if ( type & TOUCH ){ //sourceEventType.match(/touch/)) {\r
- touches = Hammer.DO_TOUCHES_FIX && type & END ? [] : e.touches;\r
- numTouches = touches.length;\r
- } else\r
- // mouse\r
- if( !touch_triggered ){\r
- numTouches = ( type & END ) ? 0 : 1;\r
- touches = numTouches === 0 ? [] : [{\r
- identifier : 1,\r
- pageX : e.pageX,\r
- pageY : e.pageY,\r
- target : e.target\r
- }];\r
+\r
+ POINTERS[ e.pointerId ] = type & END ? null : e;\r
+ touches = [];\r
+ numTouches = -1;\r
+ // we can use forEach since pointerEvents only is in IE10\r
+ for( i in POINTERS ){\r
+ POINTERS[ i ] && ( touches[ ++numTouches ] = POINTERS[ i ] );\r
};\r
+ ++numTouches;\r
+ ///console.log( 'numTouches ' + numTouches );\r
+\r
// if we are in a end event, but when we remove one touch and\r
// we still have enough, set eventType to move\r
if( 0 < numTouches && type & END ){ // eventType === Hammer.EVENT_END ){\r
// only when the instance options have enabled this gesture\r
active[ gesture.name ] &&\r
// if a handler returns false, we stop with the detection\r
- ( ret |= ( gesture.handler( e, hammer ) || X_Callback_NONE ) );\r
+ ( ret |= ( gesture.handler( e, hammer ) || X_CALLBACK_NONE ) );\r
};\r
\r
// endevent, but not the last touch, so dont stop\r
Detection.register( Gestures[ name ] );\r
};\r
\r
- Hammer.EVENT_TYPES_START = [ X.UI.Event._POINTER_DOWN ];\r
- types = [ X.UI.Event._POINTER_MOVE, X.UI.Event._POINTER_UP, X.UI.Event._POINTER_CANCEL ];\r
+ Hammer.EVENT_TYPES_START = [ XUI_Event._POINTER_DOWN ];\r
+ types = [ XUI_Event._POINTER_MOVE, XUI_Event._POINTER_UP, XUI_Event._POINTER_CANCEL ];\r
\r
// Add touch events on the document\r
Utils.addEvents( uinodeRoot, types, Hammer.prototype.handleEvent );\r
EVENT_TYPE_MASK = START | MOVE | END,\r
POINTER_TYPE_MASK = POINTER | TOUCH | MOUSE | PEN,\r
IdToGestureID = {};\r
- IdToGestureID[ X.UI.Event._POINTER_DOWN ] = START;\r
- IdToGestureID[ X.UI.Event._POINTER_MOVE ] = MOVE;\r
- IdToGestureID[ X.UI.Event._POINTER_UP ] = END;\r
- IdToGestureID[ X.UI.Event._POINTER_CANCEL ] = END;\r
+ IdToGestureID[ XUI_Event._POINTER_DOWN ] = START;\r
+ IdToGestureID[ XUI_Event._POINTER_MOVE ] = MOVE;\r
+ IdToGestureID[ XUI_Event._POINTER_UP ] = END;\r
+ IdToGestureID[ XUI_Event._POINTER_CANCEL ] = END;\r
\r
- Utils = {\r
+ var Utils = {\r
\r
/**\r
* touch events with mouse fallback\r
}\r
};\r
\r
- /**\r
+ /*\r
* this holds the last move event,\r
* used to fix empty touchend issue\r
* see the onTouch event for an explanation\r
*/\r
var last_move_event = null;\r
\r
- /**\r
+ /*\r
* when the mouse is hold down, this is true\r
* @type {Boolean}\r
*/\r
var enable_detect = false;\r
\r
- /**\r
+ /*\r
* when touch events have been fired, this is true\r
* @type {Boolean}\r
*/\r
var touch_triggered = false;\r
\r
- Detection = {\r
+ var Detection = {\r
// contains all registred Gestures in the correct order\r
gestures : [],\r
\r
Gestures.Hold = {\r
name : 'hold',\r
index : 10,\r
- startID : X.UI.Event.HOLD,\r
- endID : X.UI.Event.HOLD_END,\r
+ startID : XUI_Event.HOLD,\r
+ endID : XUI_Event.HOLD_END,\r
defaults : {\r
hold_timeout : 500,\r
hold_threshold : 1\r
this.timerID && X_Timer_remove( this.timerID );\r
if( Gestures.Hold.holding === true ){\r
Gestures.Hold.holding = false;\r
- return hammer.trigger( X.UI.Event.HOLD_END, e );\r
+ return hammer.trigger( XUI_Event.HOLD_END, e );\r
};\r
break;\r
};\r
},\r
_onTimer : function( e, hammer ){\r
if( Detection.current.name === 'hold' ){\r
- hammer.trigger( X.UI.Event.HOLD, e );\r
+ hammer.trigger( XUI_Event.HOLD, e );\r
Gestures.Hold.holding = true;\r
};\r
}\r
Gestures.Tap = {\r
name : 'tap',\r
index : 100,\r
- startID : X.UI.Event.TAP,\r
- endID : X.UI.Event.DOUBLE_TAP,\r
+ startID : XUI_Event.TAP,\r
+ endID : XUI_Event.DOUBLE_TAP,\r
defaults : {\r
tap_max_touchtime : 250,\r
tap_max_distance : 10,\r
\r
// check if double tap\r
if( prev && prev.name === 'tap' && ( e.timeStamp - prev.lastEvent.timeStamp ) < hammer.options.doubletap_interval && e.distance < hammer.options.doubletap_distance ){\r
- return hammer.trigger( X.UI.Event.DOUBLE_TAP, e );\r
+ return hammer.trigger( XUI_Event.DOUBLE_TAP, e );\r
} else\r
// do a single tap\r
if( hammer.options.tap_always && Detection.current.name !== 'tap' ){ // EventFire中にalert すると mouseleave で再び呼ばれるのを防ぐ\r
Detection.current.name = 'tap';\r
- return hammer.trigger( X.UI.Event.TAP, e );\r
+ return hammer.trigger( XUI_Event.TAP, e );\r
};\r
};\r
}\r
Gestures.Swipe = {\r
name : 'swipe',\r
index : 40,\r
- startID : X.UI.Event.SWIP,\r
- endID : X.UI.Event.SWIP_DOWN,\r
+ startID : XUI_Event.SWIP,\r
+ endID : XUI_Event.SWIP_DOWN,\r
defaults : {\r
// set 0 for unlimited, but this can conflict with transform\r
swipe_max_touches : 1,\r
// or we can be already in dragging\r
if( hammer.options.swipe_velocity < e.velocityX || hammer.options.swipe_velocity < e.velocityY ){\r
// trigger swipe events\r
- hammer.trigger( X.UI.Event.SWIP, e );\r
+ hammer.trigger( XUI_Event.SWIP, e );\r
hammer.trigger(\r
e.direction === Hammer.DIRECTION_UP ?\r
- X.UI.Event.SWIP_UP :\r
+ XUI_Event.SWIP_UP :\r
e.direction === Hammer.DIRECTION_DOWN ?\r
- X.UI.Event.SWIP_DOWN :\r
+ XUI_Event.SWIP_DOWN :\r
e.direction === Hammer.DIRECTION_LEFT ?\r
- X.UI.Event.SWIP_LEFT :\r
- X.UI.Event.SWIP_RIGHT,\r
+ XUI_Event.SWIP_LEFT :\r
+ XUI_Event.SWIP_RIGHT,\r
e\r
);\r
};\r
Gestures.Drag = {\r
name : 'drag',\r
index : 50,\r
- startID : X.UI.Event.DRAG,\r
- endID : X.UI.Event.DRAG_DOWN,\r
+ startID : XUI_Event.DRAG,\r
+ endID : XUI_Event.DRAG_DOWN,\r
defaults : {\r
drag_min_distance : 10,\r
// set 0 for unlimited, but this can conflict with transform\r
// current gesture isnt drag, but dragged is true\r
// this means an other gesture is busy. now call dragend\r
if( Detection.current.name !== this.name && this.triggered ){\r
- hammer.trigger( X.UI.Event.DRAG_END, e );\r
+ hammer.trigger( XUI_Event.DRAG_END, e );\r
this.triggered = false;\r
return;\r
};\r
\r
// first time, trigger dragstart event\r
if( !this.triggered ){\r
- hammer.trigger( X.UI.Event.DRAG_START, e );\r
+ hammer.trigger( XUI_Event.DRAG_START, e );\r
this.triggered = true;\r
};\r
\r
// trigger normal event\r
- hammer.trigger( X.UI.Event.DRAG, e );\r
+ hammer.trigger( XUI_Event.DRAG, e );\r
\r
// direction event, like dragdown\r
hammer.trigger(\r
e.direction === Hammer.DIRECTION_UP ?\r
- X.UI.Event.DRAG_UP :\r
+ XUI_Event.DRAG_UP :\r
e.direction === Hammer.DIRECTION_DOWN ?\r
- X.UI.Event.DRAG_DOWN :\r
+ XUI_Event.DRAG_DOWN :\r
e.direction === Hammer.DIRECTION_LEFT ?\r
- X.UI.Event.DRAG_LEFT :\r
- X.UI.Event.DRAG_RIGHT,\r
+ XUI_Event.DRAG_LEFT :\r
+ XUI_Event.DRAG_RIGHT,\r
e\r
);\r
\r
\r
case END:\r
// trigger dragend\r
- this.triggered && hammer.trigger( X.UI.Event.DRAG_END, e );\r
+ this.triggered && hammer.trigger( XUI_Event.DRAG_END, e );\r
this.triggered = false;\r
break;\r
}\r
Gestures.Transform = {\r
name : 'transform',\r
index : 45,\r
- startID : X.UI.Event.TRANSFORM,\r
- endID : X.UI.Event.ROTATE,\r
+ startID : XUI_Event.TRANSFORM,\r
+ endID : XUI_Event.ROTATE,\r
defaults : {\r
// factor, no scale is 1, zoomin is to 0 and zoomout until higher then 1\r
transform_min_scale : 0.01,\r
// current gesture isnt drag, but dragged is true\r
// this means an other gesture is busy. now call dragend\r
if( Detection.current.name !== this.name && this.triggered ){\r
- hammer.trigger( X.UI.Event.TRANSFORM_END, e );\r
+ hammer.trigger( XUI_Event.TRANSFORM_END, e );\r
this.triggered = false;\r
return;\r
};\r
\r
// first time, trigger dragstart event\r
if( !this.triggered ){\r
- hammer.trigger( X.UI.Event.TRANSFORM_START, e );\r
+ hammer.trigger( XUI_Event.TRANSFORM_START, e );\r
this.triggered = true;\r
};\r
\r
- hammer.trigger( X.UI.Event.TRANSFORM, e );\r
+ hammer.trigger( XUI_Event.TRANSFORM, e );\r
// basic transform event\r
\r
// trigger rotate event\r
- hammer.options.transform_min_rotation < rotation_threshold && hammer.trigger( X.UI.Event.ROTATE, e );\r
+ hammer.options.transform_min_rotation < rotation_threshold && hammer.trigger( XUI_Event.ROTATE, e );\r
\r
// trigger pinch event\r
if( scale_threshold > hammer.options.transform_min_scale ){\r
- hammer.trigger( X.UI.Event.PINCH, e );\r
- hammer.trigger( e.scale < 1 ? X.UI.Event.PINCH_IN : X.UI.Event.PINCH_OUT, e );\r
+ hammer.trigger( XUI_Event.PINCH, e );\r
+ hammer.trigger( e.scale < 1 ? XUI_Event.PINCH_IN : XUI_Event.PINCH_OUT, e );\r
};\r
break;\r
\r
case END:\r
// trigger dragend\r
- this.triggered && hammer.trigger( X.UI.Event.TRANSFORM_END, e );\r
+ this.triggered && hammer.trigger( XUI_Event.TRANSFORM_END, e );\r
this.triggered = false;\r
break;\r
};\r
e.eventType === END && hammer.trigger( this.name, e );\r
}\r
};\r
- \r
-})( Math, window, document );
\ No newline at end of file