mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
Interaction: MSPointer: Prevent mouse event promotion. Properly retrieve x/y coordinates. Handle cancel events.
This commit is contained in:
parent
a13894672a
commit
f09288d18f
46
ui/jquery.ui.interaction.js
vendored
46
ui/jquery.ui.interaction.js
vendored
@ -18,6 +18,11 @@ $.widget( "ui.interaction", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
_interactionStart: function( event, position, hook ) {
|
_interactionStart: function( event, position, hook ) {
|
||||||
|
// only one interaction can happen at a time
|
||||||
|
if ( interaction.started ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ( false !== this._start( event, position ) ) {
|
if ( false !== this._start( event, position ) ) {
|
||||||
interaction.started = true;
|
interaction.started = true;
|
||||||
interaction.hooks[ hook ].handle( this );
|
interaction.hooks[ hook ].handle( this );
|
||||||
@ -155,17 +160,24 @@ var touchHook = interaction.hooks.touch = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: test mouse, pen
|
// TODO: test mouse
|
||||||
var pointerHook = interaction.hooks.msPointer = {
|
var pointerHook = interaction.hooks.msPointer = {
|
||||||
setup: function( widget, start ) {
|
setup: function( widget, start ) {
|
||||||
widget._bind({
|
widget._bind({
|
||||||
"MSPointerDown": function( event ) {
|
"MSPointerDown": function( _event ) {
|
||||||
|
var event = _event.originalEvent;
|
||||||
|
|
||||||
if ( pointerHook.id ) {
|
if ( pointerHook.id ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pointerHook.id = event.originalEvent.pointerId;
|
// track which pointer is performing the interaction
|
||||||
event.originalEvent.preventManipulation();
|
pointerHook.id = event.pointerId;
|
||||||
|
// prevent panning/zooming
|
||||||
|
event.preventManipulation();
|
||||||
|
// prevent promoting pointer events to mouse events
|
||||||
|
event.preventMouseEvent();
|
||||||
|
|
||||||
start( event, {
|
start( event, {
|
||||||
left: event.pageX,
|
left: event.pageX,
|
||||||
top: event.pageY
|
top: event.pageY
|
||||||
@ -175,11 +187,13 @@ var pointerHook = interaction.hooks.msPointer = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
handle: function( widget ) {
|
handle: function( widget ) {
|
||||||
function pointermove( event ) {
|
function move( _event ) {
|
||||||
// always prevent manipulation to avoid zooming/scrolling
|
var event = _event.originalEvent;
|
||||||
event.originalEvent.preventManipulation();
|
|
||||||
|
|
||||||
if ( event.originalEvent.pointerId !== pointerHook.id ) {
|
// always prevent manipulation to avoid panning/zooming
|
||||||
|
event.preventManipulation();
|
||||||
|
|
||||||
|
if ( event.pointerId !== pointerHook.id ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,8 +203,10 @@ var pointerHook = interaction.hooks.msPointer = {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function pointerup( event ) {
|
function stop( _event ) {
|
||||||
if ( event.originalEvent.pointerId !== pointerHook.id ) {
|
var event = _event.originalEvent;
|
||||||
|
|
||||||
|
if ( event.pointerId !== pointerHook.id ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,13 +216,15 @@ var pointerHook = interaction.hooks.msPointer = {
|
|||||||
});
|
});
|
||||||
pointerHook.id = null;
|
pointerHook.id = null;
|
||||||
widget.document
|
widget.document
|
||||||
.unbind( "MSPointerMove", pointermove )
|
.unbind( "MSPointerMove", move )
|
||||||
.unbind( "MSPointerUp", pointerup );
|
.unbind( "MSPointerUp", stop )
|
||||||
|
.unbind( "MSPointerCancel", stop );
|
||||||
}
|
}
|
||||||
|
|
||||||
widget._bind( widget.document, {
|
widget._bind( widget.document, {
|
||||||
"MSPointerMove": pointermove,
|
"MSPointerMove": move,
|
||||||
"MSPointerUp": pointerup
|
"MSPointerUp": stop,
|
||||||
|
"MSPointerCancel": stop
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user