From a13894672a5be36cec217d800c73871d1dbf012d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Scott=20Gonz=C3=A1lez?= Date: Sun, 8 Jan 2012 22:17:19 -0500 Subject: [PATCH] Interaction: Initiail MSPointer implementation. --- ui/jquery.ui.interaction.js | 58 +++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/ui/jquery.ui.interaction.js b/ui/jquery.ui.interaction.js index b0d289846..b31e0e265 100644 --- a/ui/jquery.ui.interaction.js +++ b/ui/jquery.ui.interaction.js @@ -118,6 +118,8 @@ var touchHook = interaction.hooks.touch = { handle: function( widget ) { function touchmove( event ) { + // TODO: test non-Apple WebKits to see if they allow + // zooming/scrolling if we don't preventDefault() var touch = getTouch( event ); if ( !touch ) { return; @@ -153,4 +155,60 @@ var touchHook = interaction.hooks.touch = { } }; +// TODO: test mouse, pen +var pointerHook = interaction.hooks.msPointer = { + setup: function( widget, start ) { + widget._bind({ + "MSPointerDown": function( event ) { + if ( pointerHook.id ) { + return; + } + + pointerHook.id = event.originalEvent.pointerId; + event.originalEvent.preventManipulation(); + start( event, { + left: event.pageX, + top: event.pageY + }); + } + }); + }, + + handle: function( widget ) { + function pointermove( event ) { + // always prevent manipulation to avoid zooming/scrolling + event.originalEvent.preventManipulation(); + + if ( event.originalEvent.pointerId !== pointerHook.id ) { + return; + } + + widget._interactionMove( event, { + left: event.pageX, + top: event.pageY + }); + } + + function pointerup( event ) { + if ( event.originalEvent.pointerId !== pointerHook.id ) { + return; + } + + widget._interactionStop( event, { + left: event.pageX, + top: event.pageY + }); + pointerHook.id = null; + widget.document + .unbind( "MSPointerMove", pointermove ) + .unbind( "MSPointerUp", pointerup ); + } + + widget._bind( widget.document, { + "MSPointerMove": pointermove, + "MSPointerUp": pointerup + }); + } +}; + })( jQuery );