Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
(function( $ ) { | ||
var POINTER_TYPE_UNAVAILABLE = 1, | ||
This comment has been minimized.
Sorry, something went wrong. |
||
POINTER_TYPE_TOUCH = 2, | ||
POINTER_TYPE_PEN = 3, | ||
POINTER_TYPE_MOUSE = 4; | ||
|
||
function processEvent( event, pointerType ) { | ||
var prop, | ||
orig = event; | ||
|
||
event = $.Event( pointerType ); | ||
|
||
for ( prop in orig ) { | ||
This comment has been minimized.
Sorry, something went wrong.
scottgonzalez
Member
|
||
if ( !( prop in event ) ) { | ||
event[ prop ] = orig[ prop ]; | ||
} | ||
} | ||
|
||
event.pageX = event.pageX || orig.originalEvent.pageX; | ||
event.pageY = event.pageY || orig.originalEvent.pageY; | ||
|
||
// TODO - Actually determine if primary | ||
event.isPrimary = true; | ||
|
||
if ( orig.type.indexOf("mouse") != -1 ) { | ||
event.pointerId = 1; | ||
event.pointerType = POINTER_TYPE_MOUSE; | ||
// TODO: Don't assume left click | ||
event.button = 0; | ||
event.buttons = 1; | ||
} else if ( orig.type.indexOf("touch") != -1 ) { | ||
event.pointerId = orig.identifier || 2; | ||
This comment has been minimized.
Sorry, something went wrong.
scottgonzalez
Member
|
||
event.pointerType = POINTER_TYPE_TOUCH; | ||
event.button = 0; | ||
event.buttons = 1; | ||
} else if ( orig.type.indexOf("Pointer") != -1 ) { | ||
event.pointerId = orig.originalEvent.pointerId; | ||
event.pointerType = orig.originalEvent.pointerType || POINTER_TYPE_UNAVAILABLE; | ||
event.button = orig.originalEvent.button; | ||
event.buttons = orig.originalEvent.buttons; | ||
} | ||
|
||
return event; | ||
} | ||
|
||
$.event.special.pointerdown = { | ||
setup: function() { | ||
$( this ).bind( "mousedown touchstart MSPointerDown", jQuery.event.special.pointerdown.handler ); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
}, | ||
teardown: function() { | ||
$( this ).unbind( "mousedown touchstart MSPointerDown", jQuery.event.special.pointerdown.handler ); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
}, | ||
handler: function( event ) { | ||
event = processEvent( event, "pointerdown" ); | ||
$( event.target ).trigger( event ); | ||
} | ||
}; | ||
|
||
$.event.special.pointerup = { | ||
setup: function() { | ||
$( this ).bind( "mouseup touchend MSPointerUp", jQuery.event.special.pointerup.handler ); | ||
}, | ||
teardown: function() { | ||
$( this ).unbind( "mouseup touchend MSPointerUp", jQuery.event.special.pointerup.handler ); | ||
}, | ||
handler: function( event ) { | ||
event = processEvent( event, "pointerup" ); | ||
$( event.target ).trigger( event ); | ||
} | ||
}; | ||
|
||
$.event.special.pointermove = { | ||
setup: function() { | ||
$( this ).bind( "mousemove touchmove MSPointerMove", jQuery.event.special.pointermove.handler ); | ||
}, | ||
teardown: function() { | ||
$( this ).unbind( "mousemove touchmove MSPointerMove", jQuery.event.special.pointermove.handler ); | ||
}, | ||
handler: function( event ) { | ||
event = processEvent( event, "pointermove" ); | ||
$( event.target ).trigger( event ); | ||
} | ||
}; | ||
})( jQuery ); |
2 comments
on commit c3b8048
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other event types: pointercancel
, pointerover
, pointerout
, poitnerenter
, pointerleave
. We need pointercancel
for the interactions, the others are required for the full shim. pointerenter
and pointerleave
should get custom delegation handling built on top of pointerover
and pointerout
just like we do for mouse events in core.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to handle multiple changed touches for touch events.
pointerType
is a string.