2013-05-01 08:46:16 +04:00
/ *
2013-05-14 08:00:24 +04:00
* OpenSeadragon - MouseTracker
2013-05-01 08:46:16 +04:00
*
* Copyright ( C ) 2009 CodePlex Foundation
2013-05-14 07:32:09 +04:00
* Copyright ( C ) 2010 - 2013 OpenSeadragon contributors
2013-05-01 08:46:16 +04:00
*
* Redistribution and use in source and binary forms , with or without
* modification , are permitted provided that the following conditions are
* met :
*
* - Redistributions of source code must retain the above copyright notice ,
* this list of conditions and the following disclaimer .
*
* - Redistributions in binary form must reproduce the above copyright
* notice , this list of conditions and the following disclaimer in the
* documentation and / or other materials provided with the distribution .
*
* - Neither the name of CodePlex Foundation nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission .
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES , INCLUDING , BUT NOT
* LIMITED TO , THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED . IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT , INDIRECT , INCIDENTAL ,
* SPECIAL , EXEMPLARY , OR CONSEQUENTIAL DAMAGES ( INCLUDING , BUT NOT LIMITED
* TO , PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES ; LOSS OF USE , DATA , OR
* PROFITS ; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY , WHETHER IN CONTRACT , STRICT LIABILITY , OR TORT ( INCLUDING
* NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE .
* /
2013-09-06 04:20:17 +04:00
( function ( $ ) {
2014-04-01 20:32:04 +04:00
// is any button currently being pressed while pointer events occur
2013-09-06 04:20:17 +04:00
var IS _BUTTON _DOWN = false ,
2013-09-06 21:43:39 +04:00
// is any tracker currently capturing?
2014-03-30 04:02:24 +04:00
//IS_CAPTURING = false,
2013-09-06 21:43:39 +04:00
// dictionary from hash to MouseTracker
2014-03-30 04:02:24 +04:00
//ACTIVE = {},
2013-09-06 21:43:39 +04:00
// list of trackers interested in capture
2014-03-30 04:02:24 +04:00
//CAPTURING = [],
2013-09-06 21:43:39 +04:00
// dictionary from hash to private properties
THIS = { } ;
2011-12-06 07:50:25 +04:00
2014-03-21 22:45:20 +04:00
2012-01-25 23:14:02 +04:00
/ * *
2013-11-16 10:19:53 +04:00
* @ class MouseTracker
2014-04-01 20:32:04 +04:00
* @ classdesc Provides simplified handling of common pointing device ( mouse , touch , pen ) and keyboard
2013-11-25 20:48:44 +04:00
* events on a specific element , like 'enter' , 'exit' , 'press' , 'release' ,
* 'scroll' , 'click' , and 'drag' .
*
2013-11-16 10:19:53 +04:00
* @ memberof OpenSeadragon
2013-09-06 21:43:39 +04:00
* @ param { Object } options
* Allows configurable properties to be entirely specified by passing
* an options object to the constructor . The constructor also supports
2013-11-25 20:48:44 +04:00
* the original positional arguments 'element' , 'clickTimeThreshold' ,
2013-09-06 21:43:39 +04:00
* and 'clickDistThreshold' in that order .
* @ param { Element | String } options . element
2014-04-01 20:32:04 +04:00
* A reference to an element or an element id for which the pointer / key
2013-09-06 21:43:39 +04:00
* events will be monitored .
* @ param { Number } options . clickTimeThreshold
2014-04-01 20:32:04 +04:00
* The number of milliseconds within which multiple pointer clicks
2013-09-06 21:43:39 +04:00
* will be treated as a single event .
* @ param { Number } options . clickDistThreshold
2014-04-01 20:32:04 +04:00
* The distance between pointer click within multiple pointer clicks
2013-09-06 21:43:39 +04:00
* will be treated as a single event .
2013-11-25 20:48:44 +04:00
* @ param { Number } [ options . stopDelay = 50 ]
2014-04-01 20:32:04 +04:00
* The number of milliseconds without pointer move before the stop
2013-10-23 00:54:04 +04:00
* event is fired .
2013-11-25 20:48:44 +04:00
* @ param { OpenSeadragon . EventHandler } [ options . enterHandler = null ]
2014-04-01 20:32:04 +04:00
* An optional handler for pointer enter .
2013-11-25 20:48:44 +04:00
* @ param { OpenSeadragon . EventHandler } [ options . exitHandler = null ]
2014-04-01 20:32:04 +04:00
* An optional handler for pointer exit .
2013-11-25 20:48:44 +04:00
* @ param { OpenSeadragon . EventHandler } [ options . pressHandler = null ]
2014-04-01 20:32:04 +04:00
* An optional handler for pointer press .
2013-11-25 20:48:44 +04:00
* @ param { OpenSeadragon . EventHandler } [ options . releaseHandler = null ]
2014-04-01 20:32:04 +04:00
* An optional handler for pointer release .
2013-11-25 20:48:44 +04:00
* @ param { OpenSeadragon . EventHandler } [ options . moveHandler = null ]
2014-04-01 20:32:04 +04:00
* An optional handler for pointer move .
2013-11-25 20:48:44 +04:00
* @ param { OpenSeadragon . EventHandler } [ options . scrollHandler = null ]
2014-04-01 20:32:04 +04:00
* An optional handler for mouse wheel scroll .
2013-11-25 20:48:44 +04:00
* @ param { OpenSeadragon . EventHandler } [ options . clickHandler = null ]
2014-04-01 20:32:04 +04:00
* An optional handler for pointer click .
2013-11-25 20:48:44 +04:00
* @ param { OpenSeadragon . EventHandler } [ options . dragHandler = null ]
2014-03-10 22:49:51 +04:00
* An optional handler for the drag gesture .
2014-03-30 04:02:24 +04:00
* @ param { OpenSeadragon . EventHandler } [ options . dragEndHandler = null ]
* An optional handler for after a drag gesture .
2014-03-10 22:49:51 +04:00
* @ param { OpenSeadragon . EventHandler } [ options . pinchHandler = null ]
* An optional handler for the pinch gesture .
2013-11-25 20:48:44 +04:00
* @ param { OpenSeadragon . EventHandler } [ options . keyHandler = null ]
2013-09-06 21:43:39 +04:00
* An optional handler for keypress .
2013-11-25 20:48:44 +04:00
* @ param { OpenSeadragon . EventHandler } [ options . focusHandler = null ]
2013-09-06 21:43:39 +04:00
* An optional handler for focus .
2013-11-25 20:48:44 +04:00
* @ param { OpenSeadragon . EventHandler } [ options . blurHandler = null ]
2013-09-06 21:43:39 +04:00
* An optional handler for blur .
2013-09-12 21:05:50 +04:00
* @ param { Object } [ options . userData = null ]
* Arbitrary object to be passed unchanged to any attached handler methods .
2013-09-06 21:43:39 +04:00
* /
2012-02-03 04:12:45 +04:00
$ . MouseTracker = function ( options ) {
2013-09-06 04:20:17 +04:00
var args = arguments ;
2012-02-03 04:12:45 +04:00
2013-09-06 04:20:17 +04:00
if ( ! $ . isPlainObject ( options ) ) {
2012-02-03 04:12:45 +04:00
options = {
2013-09-20 20:58:18 +04:00
element : args [ 0 ] ,
clickTimeThreshold : args [ 1 ] ,
clickDistThreshold : args [ 2 ]
2012-02-03 04:12:45 +04:00
} ;
}
2013-11-25 20:48:44 +04:00
this . hash = Math . random ( ) ; // An unique hash for this tracker.
/ * *
2014-04-01 20:32:04 +04:00
* The element for which pointer events are being monitored .
2013-11-25 20:48:44 +04:00
* @ member { Element } element
* @ memberof OpenSeadragon . MouseTracker #
* /
2012-02-03 04:12:45 +04:00
this . element = $ . getElement ( options . element ) ;
2013-11-25 20:48:44 +04:00
/ * *
2014-04-01 20:32:04 +04:00
* The number of milliseconds within which mutliple pointer clicks will be treated as a single event .
2013-11-25 20:48:44 +04:00
* @ member { Number } clickTimeThreshold
* @ memberof OpenSeadragon . MouseTracker #
* /
2012-02-03 04:12:45 +04:00
this . clickTimeThreshold = options . clickTimeThreshold ;
2013-11-25 20:48:44 +04:00
/ * *
2014-04-01 20:32:04 +04:00
* The distance between pointer click within multiple pointer clicks will be treated as a single event .
2013-11-25 20:48:44 +04:00
* @ member { Number } clickDistThreshold
* @ memberof OpenSeadragon . MouseTracker #
* /
2012-02-03 04:12:45 +04:00
this . clickDistThreshold = options . clickDistThreshold ;
2013-09-06 21:43:39 +04:00
this . userData = options . userData || null ;
2013-10-23 00:54:04 +04:00
this . stopDelay = options . stopDelay || 50 ;
2012-02-03 04:12:45 +04:00
2013-09-06 21:43:39 +04:00
this . enterHandler = options . enterHandler || null ;
this . exitHandler = options . exitHandler || null ;
this . pressHandler = options . pressHandler || null ;
2012-02-03 04:12:45 +04:00
this . releaseHandler = options . releaseHandler || null ;
2013-09-06 21:43:39 +04:00
this . moveHandler = options . moveHandler || null ;
this . scrollHandler = options . scrollHandler || null ;
this . clickHandler = options . clickHandler || null ;
this . dragHandler = options . dragHandler || null ;
2014-03-30 04:02:24 +04:00
this . dragEndHandler = options . dragEndHandler || null ;
2014-03-10 22:49:51 +04:00
this . pinchHandler = options . pinchHandler || null ;
2013-10-23 00:54:04 +04:00
this . stopHandler = options . stopHandler || null ;
2013-09-06 21:43:39 +04:00
this . keyHandler = options . keyHandler || null ;
this . focusHandler = options . focusHandler || null ;
this . blurHandler = options . blurHandler || null ;
2012-02-03 04:12:45 +04:00
//Store private properties in a scope sealed hash map
var _this = this ;
2012-02-10 07:16:09 +04:00
2012-02-03 04:12:45 +04:00
/ * *
2013-09-06 21:43:39 +04:00
* @ private
* @ property { Boolean } tracking
2014-04-01 20:32:04 +04:00
* Are we currently tracking pointer events .
2013-09-06 21:43:39 +04:00
* @ property { Boolean } capturing
2014-04-01 20:32:04 +04:00
* Are we curruently capturing mouse events ( legacy mouse events only ) .
2013-09-06 21:43:39 +04:00
* /
2013-09-20 20:58:18 +04:00
THIS [ this . hash ] = {
2014-03-10 22:49:51 +04:00
click : function ( event ) { onClick ( _this , event ) ; } ,
keypress : function ( event ) { onKeyPress ( _this , event ) ; } ,
focus : function ( event ) { onFocus ( _this , event ) ; } ,
blur : function ( event ) { onBlur ( _this , event ) ; } ,
2014-03-21 22:45:20 +04:00
2013-10-23 23:58:36 +04:00
wheel : function ( event ) { onWheel ( _this , event ) ; } ,
mousewheel : function ( event ) { onMouseWheel ( _this , event ) ; } ,
DOMMouseScroll : function ( event ) { onMouseWheel ( _this , event ) ; } ,
2013-10-25 00:39:00 +04:00
MozMousePixelScroll : function ( event ) { onMouseWheel ( _this , event ) ; } ,
2014-03-21 22:45:20 +04:00
mouseover : function ( event ) { onMouseOver ( _this , event ) ; } ,
mouseout : function ( event ) { onMouseOut ( _this , event ) ; } ,
mousedown : function ( event ) { onMouseDown ( _this , event ) ; } ,
mouseup : function ( event ) { onMouseUp ( _this , event ) ; } ,
mouseupcaptured : function ( event ) { onMouseUpCaptured ( _this , event ) ; } ,
2014-03-30 04:02:24 +04:00
//mouseupcapturedie: function ( event ) { onMouseUpCapturedIE( _this, event ); },
2014-03-21 22:45:20 +04:00
mousemove : function ( event ) { onMouseMove ( _this , event ) ; } ,
mousemovecaptured : function ( event ) { onMouseMoveCaptured ( _this , event ) ; } ,
2014-03-30 04:02:24 +04:00
//mousemovecapturedie: function ( event ) { onMouseMoveCapturedIE( _this, event ); },
2014-03-21 22:45:20 +04:00
touchenter : function ( event ) { onTouchEnter ( _this , event ) ; } ,
touchleave : function ( event ) { onTouchLeave ( _this , event ) ; } ,
touchstart : function ( event ) { onTouchStart ( _this , event ) ; } ,
touchend : function ( event ) { onTouchEnd ( _this , event ) ; } ,
touchmove : function ( event ) { onTouchMove ( _this , event ) ; } ,
touchcancel : function ( event ) { onTouchCancel ( _this , event ) ; } ,
gesturestart : function ( event ) { onGestureStart ( _this , event ) ; } ,
gesturechange : function ( event ) { onGestureChange ( _this , event ) ; } ,
2014-03-10 22:49:51 +04:00
pointerover : function ( event ) { onPointerOver ( _this , event ) ; } ,
MSPointerOver : function ( event ) { onPointerOver ( _this , event ) ; } ,
pointerout : function ( event ) { onPointerOut ( _this , event ) ; } ,
MSPointerOut : function ( event ) { onPointerOut ( _this , event ) ; } ,
pointerdown : function ( event ) { onPointerDown ( _this , event ) ; } ,
MSPointerDown : function ( event ) { onPointerDown ( _this , event ) ; } ,
pointerup : function ( event ) { onPointerUp ( _this , event ) ; } ,
MSPointerUp : function ( event ) { onPointerUp ( _this , event ) ; } ,
pointermove : function ( event ) { onPointerMove ( _this , event ) ; } ,
MSPointerMove : function ( event ) { onPointerMove ( _this , event ) ; } ,
pointercancel : function ( event ) { onPointerCancel ( _this , event ) ; } ,
MSPointerCancel : function ( event ) { onPointerCancel ( _this , event ) ; } ,
2014-03-21 22:45:20 +04:00
tracking : false ,
2013-09-10 01:27:58 +04:00
capturing : false ,
2014-03-31 23:54:37 +04:00
2014-03-30 04:02:24 +04:00
// Active Contact Points
mousePoints : new $ . MouseTracker . GesturePointList ( ) ,
touchPoints : new $ . MouseTracker . GesturePointList ( ) ,
penPoints : new $ . MouseTracker . GesturePointList ( ) ,
2014-03-10 22:49:51 +04:00
// Tracking for pinch gesture
2014-03-21 22:45:20 +04:00
pinchGPoints : [ ] ,
2014-03-10 22:49:51 +04:00
lastPinchDist : 0 ,
currentPinchDist : 0 ,
2014-03-15 01:15:09 +04:00
lastPinchCenter : null ,
2014-03-30 04:02:24 +04:00
currentPinchCenter : null
2012-02-02 01:56:04 +04:00
} ;
} ;
2011-12-06 07:50:25 +04:00
2013-11-16 10:19:53 +04:00
$ . MouseTracker . prototype = /** @lends OpenSeadragon.MouseTracker.prototype */ {
2011-12-06 07:50:25 +04:00
2013-08-08 11:49:24 +04:00
/ * *
2014-04-01 20:32:04 +04:00
* Clean up any events or objects created by the tracker .
2013-09-06 21:43:39 +04:00
* @ function
* /
2013-09-06 04:20:17 +04:00
destroy : function ( ) {
2013-08-08 11:49:24 +04:00
stopTracking ( this ) ;
this . element = null ;
} ,
2012-02-02 01:56:04 +04:00
/ * *
2013-09-06 21:43:39 +04:00
* Are we currently tracking events on this element .
* @ deprecated Just use this . tracking
* @ function
* @ returns { Boolean } Are we currently tracking events on this element .
* /
2012-02-02 01:56:04 +04:00
isTracking : function ( ) {
2013-09-20 20:58:18 +04:00
return THIS [ this . hash ] . tracking ;
2012-02-02 01:56:04 +04:00
} ,
/ * *
2013-09-06 21:43:39 +04:00
* Enable or disable whether or not we are tracking events on this element .
* @ function
* @ param { Boolean } track True to start tracking , false to stop tracking .
* @ returns { OpenSeadragon . MouseTracker } Chainable .
* /
2012-02-02 01:56:04 +04:00
setTracking : function ( track ) {
if ( track ) {
2012-02-03 04:12:45 +04:00
startTracking ( this ) ;
2011-12-14 05:04:38 +04:00
} else {
2012-02-03 04:12:45 +04:00
stopTracking ( this ) ;
2011-12-14 05:04:38 +04:00
}
2012-02-03 04:12:45 +04:00
//chain
return this ;
2012-02-02 01:56:04 +04:00
} ,
2013-06-19 21:33:25 +04:00
2012-02-02 01:56:04 +04:00
/ * *
2013-10-31 05:28:10 +04:00
* Implement or assign implementation to these handlers during or after
2013-09-06 21:43:39 +04:00
* calling the constructor .
* @ function
2013-10-11 04:00:15 +04:00
* @ param { Object } event
* @ param { OpenSeadragon . MouseTracker } event . eventSource
2013-09-06 21:43:39 +04:00
* A reference to the tracker instance .
2014-03-30 04:02:24 +04:00
* @ param { String } event . pointerType
2014-03-21 22:45:20 +04:00
* "mouse" , "touch" , "pen" , or "" .
2013-10-11 04:00:15 +04:00
* @ param { OpenSeadragon . Point } event . position
2013-09-12 21:05:50 +04:00
* The position of the event relative to the tracked element .
2013-10-11 04:00:15 +04:00
* @ param { Boolean } event . insideElementPressed
2013-09-12 21:05:50 +04:00
* True if the left mouse button is currently being pressed and was
* initiated inside the tracked element , otherwise false .
2013-10-11 04:00:15 +04:00
* @ param { Boolean } event . buttonDownAny
2013-09-12 21:05:50 +04:00
* Was the button down anywhere in the screen during the event .
2013-10-11 04:00:15 +04:00
* @ param { Boolean } event . isTouchEvent
2014-03-21 22:45:20 +04:00
* True if the original event is a touch event , otherwise false . < span style = "color:red;" > Deprecated . Use pointerType and / or originalEvent instead . < / s p a n >
2013-10-11 04:00:15 +04:00
* @ param { Object } event . originalEvent
2013-09-12 21:05:50 +04:00
* The original event object .
2013-11-18 18:56:32 +04:00
* @ param { Boolean } event . preventDefaultAction
* Set to true to prevent the tracker subscriber from performing its default action ( subscriber implementation dependent ) . Default : false .
2013-10-11 04:00:15 +04:00
* @ param { Object } event . userData
2013-09-12 21:05:50 +04:00
* Arbitrary user - defined object .
2013-09-06 21:43:39 +04:00
* /
2013-09-06 04:20:17 +04:00
enterHandler : function ( ) { } ,
/ * *
2013-10-31 05:28:10 +04:00
* Implement or assign implementation to these handlers during or after
2013-09-06 21:43:39 +04:00
* calling the constructor .
* @ function
2013-10-11 04:00:15 +04:00
* @ param { Object } event
* @ param { OpenSeadragon . MouseTracker } event . eventSource
2013-09-06 21:43:39 +04:00
* A reference to the tracker instance .
2014-03-30 04:02:24 +04:00
* @ param { String } event . pointerType
2014-03-21 22:45:20 +04:00
* "mouse" , "touch" , "pen" , or "" .
2013-10-11 04:00:15 +04:00
* @ param { OpenSeadragon . Point } event . position
2013-09-12 21:05:50 +04:00
* The position of the event relative to the tracked element .
2013-10-11 04:00:15 +04:00
* @ param { Boolean } event . insideElementPressed
2013-09-12 21:05:50 +04:00
* True if the left mouse button is currently being pressed and was
* initiated inside the tracked element , otherwise false .
2013-10-11 04:00:15 +04:00
* @ param { Boolean } event . buttonDownAny
2013-09-12 21:05:50 +04:00
* Was the button down anywhere in the screen during the event .
2013-10-11 04:00:15 +04:00
* @ param { Boolean } event . isTouchEvent
2014-03-21 22:45:20 +04:00
* True if the original event is a touch event , otherwise false . < span style = "color:red;" > Deprecated . Use pointerType and / or originalEvent instead . < / s p a n >
2013-10-11 04:00:15 +04:00
* @ param { Object } event . originalEvent
2013-09-12 21:05:50 +04:00
* The original event object .
2013-11-18 18:56:32 +04:00
* @ param { Boolean } event . preventDefaultAction
* Set to true to prevent the tracker subscriber from performing its default action ( subscriber implementation dependent ) . Default : false .
2013-10-11 04:00:15 +04:00
* @ param { Object } event . userData
2013-09-12 21:05:50 +04:00
* Arbitrary user - defined object .
2013-09-06 21:43:39 +04:00
* /
2013-09-06 04:20:17 +04:00
exitHandler : function ( ) { } ,
2011-12-06 07:50:25 +04:00
2012-02-02 01:56:04 +04:00
/ * *
2013-10-31 05:28:10 +04:00
* Implement or assign implementation to these handlers during or after
2013-09-06 21:43:39 +04:00
* calling the constructor .
* @ function
2013-10-11 04:00:15 +04:00
* @ param { Object } event
* @ param { OpenSeadragon . MouseTracker } event . eventSource
2013-09-06 21:43:39 +04:00
* A reference to the tracker instance .
2014-03-30 04:02:24 +04:00
* @ param { String } event . pointerType
2014-03-21 22:45:20 +04:00
* "mouse" , "touch" , "pen" , or "" .
2013-10-11 04:00:15 +04:00
* @ param { OpenSeadragon . Point } event . position
2013-09-12 21:05:50 +04:00
* The position of the event relative to the tracked element .
2013-10-11 04:00:15 +04:00
* @ param { Boolean } event . isTouchEvent
2014-03-21 22:45:20 +04:00
* True if the original event is a touch event , otherwise false . < span style = "color:red;" > Deprecated . Use pointerType and / or originalEvent instead . < / s p a n >
2013-10-11 04:00:15 +04:00
* @ param { Object } event . originalEvent
2013-09-12 21:05:50 +04:00
* The original event object .
2013-11-18 18:56:32 +04:00
* @ param { Boolean } event . preventDefaultAction
* Set to true to prevent the tracker subscriber from performing its default action ( subscriber implementation dependent ) . Default : false .
2013-10-11 04:00:15 +04:00
* @ param { Object } event . userData
2013-09-12 21:05:50 +04:00
* Arbitrary user - defined object .
2013-09-06 21:43:39 +04:00
* /
2013-09-06 04:20:17 +04:00
pressHandler : function ( ) { } ,
2012-02-02 01:56:04 +04:00
/ * *
2013-10-31 05:28:10 +04:00
* Implement or assign implementation to these handlers during or after
2013-09-06 21:43:39 +04:00
* calling the constructor .
* @ function
2013-10-11 04:00:15 +04:00
* @ param { Object } event
* @ param { OpenSeadragon . MouseTracker } event . eventSource
2013-09-06 21:43:39 +04:00
* A reference to the tracker instance .
2014-03-30 04:02:24 +04:00
* @ param { String } event . pointerType
2014-03-21 22:45:20 +04:00
* "mouse" , "touch" , "pen" , or "" .
2013-10-11 04:00:15 +04:00
* @ param { OpenSeadragon . Point } event . position
2013-09-12 21:05:50 +04:00
* The position of the event relative to the tracked element .
2013-10-11 04:00:15 +04:00
* @ param { Boolean } event . insideElementPressed
2013-09-12 21:05:50 +04:00
* True if the left mouse button is currently being pressed and was
* initiated inside the tracked element , otherwise false .
2013-10-11 04:00:15 +04:00
* @ param { Boolean } event . insideElementReleased
2013-09-12 21:05:50 +04:00
* True if the cursor still inside the tracked element when the button was released .
2013-10-11 04:00:15 +04:00
* @ param { Boolean } event . isTouchEvent
2014-03-21 22:45:20 +04:00
* True if the original event is a touch event , otherwise false . < span style = "color:red;" > Deprecated . Use pointerType and / or originalEvent instead . < / s p a n >
2013-10-11 04:00:15 +04:00
* @ param { Object } event . originalEvent
2013-09-12 21:05:50 +04:00
* The original event object .
2013-11-18 18:56:32 +04:00
* @ param { Boolean } event . preventDefaultAction
* Set to true to prevent the tracker subscriber from performing its default action ( subscriber implementation dependent ) . Default : false .
2013-10-11 04:00:15 +04:00
* @ param { Object } event . userData
2013-09-12 21:05:50 +04:00
* Arbitrary user - defined object .
2013-09-06 21:43:39 +04:00
* /
2013-09-06 04:20:17 +04:00
releaseHandler : function ( ) { } ,
2011-12-06 07:50:25 +04:00
2012-02-02 01:56:04 +04:00
/ * *
2013-10-31 05:28:10 +04:00
* Implement or assign implementation to these handlers during or after
2013-09-06 21:43:39 +04:00
* calling the constructor .
* @ function
2013-10-11 04:00:15 +04:00
* @ param { Object } event
* @ param { OpenSeadragon . MouseTracker } event . eventSource
2013-09-06 21:43:39 +04:00
* A reference to the tracker instance .
2014-03-30 04:02:24 +04:00
* @ param { String } event . pointerType
2014-03-21 22:45:20 +04:00
* "mouse" , "touch" , "pen" , or "" .
2013-10-11 04:00:15 +04:00
* @ param { OpenSeadragon . Point } event . position
2013-09-12 21:05:50 +04:00
* The position of the event relative to the tracked element .
2013-10-11 04:00:15 +04:00
* @ param { Boolean } event . isTouchEvent
2014-03-21 22:45:20 +04:00
* True if the original event is a touch event , otherwise false . < span style = "color:red;" > Deprecated . Use pointerType and / or originalEvent instead . < / s p a n >
2013-10-11 04:00:15 +04:00
* @ param { Object } event . originalEvent
2013-09-12 21:05:50 +04:00
* The original event object .
2013-11-18 18:56:32 +04:00
* @ param { Boolean } event . preventDefaultAction
* Set to true to prevent the tracker subscriber from performing its default action ( subscriber implementation dependent ) . Default : false .
2013-10-11 04:00:15 +04:00
* @ param { Object } event . userData
2013-09-12 21:05:50 +04:00
* Arbitrary user - defined object .
2013-09-06 21:43:39 +04:00
* /
2013-09-06 04:20:17 +04:00
moveHandler : function ( ) { } ,
2011-12-06 07:50:25 +04:00
2012-02-02 01:56:04 +04:00
/ * *
2013-10-31 05:28:10 +04:00
* Implement or assign implementation to these handlers during or after
2013-09-06 21:43:39 +04:00
* calling the constructor .
* @ function
2013-10-11 04:00:15 +04:00
* @ param { Object } event
* @ param { OpenSeadragon . MouseTracker } event . eventSource
2013-09-06 21:43:39 +04:00
* A reference to the tracker instance .
2014-03-30 04:02:24 +04:00
* @ param { String } event . pointerType
2014-03-21 22:45:20 +04:00
* "mouse" , "touch" , "pen" , or "" .
2013-10-11 04:00:15 +04:00
* @ param { OpenSeadragon . Point } event . position
2013-09-12 21:05:50 +04:00
* The position of the event relative to the tracked element .
2013-10-11 04:00:15 +04:00
* @ param { Number } event . scroll
2013-09-12 21:05:50 +04:00
* The scroll delta for the event .
2013-10-11 04:00:15 +04:00
* @ param { Boolean } event . shift
2013-09-12 21:05:50 +04:00
* True if the shift key was pressed during this event .
2013-10-11 04:00:15 +04:00
* @ param { Boolean } event . isTouchEvent
2014-03-21 22:45:20 +04:00
* True if the original event is a touch event , otherwise false . < span style = "color:red;" > Deprecated . Use pointerType and / or originalEvent instead . Touch devices no longer generate scroll event . < / s p a n >
2013-10-11 04:00:15 +04:00
* @ param { Object } event . originalEvent
2013-09-12 21:05:50 +04:00
* The original event object .
2013-11-18 18:56:32 +04:00
* @ param { Boolean } event . preventDefaultAction
* Set to true to prevent the tracker subscriber from performing its default action ( subscriber implementation dependent ) . Default : false .
2013-10-11 04:00:15 +04:00
* @ param { Object } event . userData
2013-09-12 21:05:50 +04:00
* Arbitrary user - defined object .
2013-09-06 21:43:39 +04:00
* /
2013-09-06 04:20:17 +04:00
scrollHandler : function ( ) { } ,
2011-12-06 07:50:25 +04:00
2012-02-02 01:56:04 +04:00
/ * *
2013-10-31 05:28:10 +04:00
* Implement or assign implementation to these handlers during or after
2013-09-06 21:43:39 +04:00
* calling the constructor .
* @ function
2013-10-11 04:00:15 +04:00
* @ param { Object } event
* @ param { OpenSeadragon . MouseTracker } event . eventSource
2013-09-06 21:43:39 +04:00
* A reference to the tracker instance .
2014-03-30 04:02:24 +04:00
* @ param { String } event . pointerType
2014-03-21 22:45:20 +04:00
* "mouse" , "touch" , "pen" , or "" .
2013-10-11 04:00:15 +04:00
* @ param { OpenSeadragon . Point } event . position
2013-09-12 21:05:50 +04:00
* The position of the event relative to the tracked element .
2013-10-11 04:00:15 +04:00
* @ param { Number } event . quick
2013-11-16 10:19:53 +04:00
* True only if the clickDistThreshold and clickDeltaThreshold are both passed . Useful for ignoring events .
2013-10-11 04:00:15 +04:00
* @ param { Boolean } event . shift
2013-09-12 21:05:50 +04:00
* True if the shift key was pressed during this event .
2013-10-11 04:00:15 +04:00
* @ param { Boolean } event . isTouchEvent
2014-03-21 22:45:20 +04:00
* True if the original event is a touch event , otherwise false . < span style = "color:red;" > Deprecated . Use pointerType and / or originalEvent instead . < / s p a n >
2013-10-11 04:00:15 +04:00
* @ param { Object } event . originalEvent
2013-09-12 21:05:50 +04:00
* The original event object .
2013-11-18 18:56:32 +04:00
* @ param { Boolean } event . preventDefaultAction
* Set to true to prevent the tracker subscriber from performing its default action ( subscriber implementation dependent ) . Default : false .
2013-10-11 04:00:15 +04:00
* @ param { Object } event . userData
2013-09-12 21:05:50 +04:00
* Arbitrary user - defined object .
2013-09-06 21:43:39 +04:00
* /
2013-09-06 04:20:17 +04:00
clickHandler : function ( ) { } ,
2011-12-06 07:50:25 +04:00
2012-02-02 01:56:04 +04:00
/ * *
2013-10-31 05:28:10 +04:00
* Implement or assign implementation to these handlers during or after
2013-09-06 21:43:39 +04:00
* calling the constructor .
* @ function
2013-10-11 04:00:15 +04:00
* @ param { Object } event
* @ param { OpenSeadragon . MouseTracker } event . eventSource
2013-09-06 21:43:39 +04:00
* A reference to the tracker instance .
2014-03-30 04:02:24 +04:00
* @ param { String } event . pointerType
2014-03-21 22:45:20 +04:00
* "mouse" , "touch" , "pen" , or "" .
2013-10-11 04:00:15 +04:00
* @ param { OpenSeadragon . Point } event . position
2013-09-12 21:05:50 +04:00
* The position of the event relative to the tracked element .
2013-10-11 04:00:15 +04:00
* @ param { OpenSeadragon . Point } event . delta
2014-03-30 04:02:24 +04:00
* The x , y components of the difference between the current position and the last drag event position . Useful for ignoring or weighting the events .
* @ param { Number } speed
* Current computed speed , in pixels per second .
* @ property { Number } direction
* Current computed direction , expressed as an angle counterclockwise relative to the positive X axis ( - pi to pi , in radians ) . Only valid if speed > 0.
2013-10-11 04:00:15 +04:00
* @ param { Boolean } event . shift
2013-09-12 21:05:50 +04:00
* True if the shift key was pressed during this event .
2013-10-11 04:00:15 +04:00
* @ param { Boolean } event . isTouchEvent
2014-03-21 22:45:20 +04:00
* True if the original event is a touch event , otherwise false . < span style = "color:red;" > Deprecated . Use pointerType and / or originalEvent instead . < / s p a n >
2013-10-11 04:00:15 +04:00
* @ param { Object } event . originalEvent
2013-09-12 21:05:50 +04:00
* The original event object .
2013-11-18 18:56:32 +04:00
* @ param { Boolean } event . preventDefaultAction
* Set to true to prevent the tracker subscriber from performing its default action ( subscriber implementation dependent ) . Default : false .
2013-10-11 04:00:15 +04:00
* @ param { Object } event . userData
2013-09-12 21:05:50 +04:00
* Arbitrary user - defined object .
2013-09-06 21:43:39 +04:00
* /
2013-09-06 04:20:17 +04:00
dragHandler : function ( ) { } ,
2011-12-06 07:50:25 +04:00
2014-03-10 22:49:51 +04:00
/ * *
* Implement or assign implementation to these handlers during or after
* calling the constructor .
* @ function
* @ param { Object } event
* @ param { OpenSeadragon . MouseTracker } event . eventSource
* A reference to the tracker instance .
2014-03-30 04:02:24 +04:00
* @ param { String } event . pointerType
2014-03-21 22:45:20 +04:00
* "mouse" , "touch" , "pen" , or "" .
2014-03-10 22:49:51 +04:00
* @ param { OpenSeadragon . Point } event . position
* The position of the event relative to the tracked element .
2014-03-30 04:02:24 +04:00
* @ param { Number } speed
* Speed at the end of a drag gesture , in pixels per second .
* @ property { Number } direction
* Direction at the end of a drag gesture , expressed as an angle counterclockwise relative to the positive X axis ( - pi to pi , in radians ) . Only valid if speed > 0.
2014-03-10 22:49:51 +04:00
* @ param { Boolean } event . shift
* True if the shift key was pressed during this event .
* @ param { Boolean } event . isTouchEvent
2014-03-21 22:45:20 +04:00
* True if the original event is a touch event , otherwise false . < span style = "color:red;" > Deprecated . Use pointerType and / or originalEvent instead . < / s p a n >
2014-03-10 22:49:51 +04:00
* @ param { Object } event . originalEvent
* The original event object .
* @ param { Boolean } event . preventDefaultAction
* Set to true to prevent the tracker subscriber from performing its default action ( subscriber implementation dependent ) . Default : false .
* @ param { Object } event . userData
* Arbitrary user - defined object .
* /
2014-03-30 04:02:24 +04:00
dragEndHandler : function ( ) { } ,
2014-03-10 22:49:51 +04:00
/ * *
* Implement or assign implementation to these handlers during or after
* calling the constructor .
* @ function
* @ param { Object } event
* @ param { OpenSeadragon . MouseTracker } event . eventSource
* A reference to the tracker instance .
2014-03-30 04:02:24 +04:00
* @ param { String } event . pointerType
2014-03-21 22:45:20 +04:00
* "mouse" , "touch" , "pen" , or "" .
2014-03-30 04:02:24 +04:00
* @ param { Array . < OpenSeadragon . MouseTracker . GesturePoint > } event . gesturePoints
* Gesture points associated with the gesture . Velocity data can be found here .
* @ param { OpenSeadragon . Point } event . lastCenter
* The previous center point of the two pinch contact points relative to the tracked element .
* @ param { OpenSeadragon . Point } event . center
* The center point of the two pinch contact points relative to the tracked element .
* @ param { Number } event . lastDistance
* The previous distance between the two pinch contact points in CSS pixels .
* @ param { Number } event . distance
* The distance between the two pinch contact points in CSS pixels .
2014-03-10 22:49:51 +04:00
* @ param { Boolean } event . shift
* True if the shift key was pressed during this event .
* @ param { Object } event . originalEvent
* The original event object .
* @ param { Boolean } event . preventDefaultAction
* Set to true to prevent the tracker subscriber from performing its default action ( subscriber implementation dependent ) . Default : false .
* @ param { Object } event . userData
* Arbitrary user - defined object .
* /
2014-03-30 04:02:24 +04:00
pinchHandler : function ( ) { } ,
2014-03-10 22:49:51 +04:00
2012-03-16 19:36:28 +04:00
/ * *
2013-10-23 00:54:04 +04:00
* Implement or assign implementation to these handlers during or after
* calling the constructor .
* @ function
* @ param { Object } event
* @ param { OpenSeadragon . MouseTracker } event . eventSource
* A reference to the tracker instance .
2014-03-30 04:02:24 +04:00
* @ param { String } event . pointerType
2014-03-21 22:45:20 +04:00
* "mouse" , "touch" , "pen" , or "" .
2013-10-23 00:54:04 +04:00
* @ param { OpenSeadragon . Point } event . position
* The position of the event relative to the tracked element .
* @ param { Boolean } event . isTouchEvent
2014-03-21 22:45:20 +04:00
* True if the original event is a touch event , otherwise false . < span style = "color:red;" > Deprecated . Use pointerType and / or originalEvent instead . < / s p a n >
2013-10-23 00:54:04 +04:00
* @ param { Object } event . originalEvent
* The original event object .
2013-11-18 18:56:32 +04:00
* @ param { Boolean } event . preventDefaultAction
* Set to true to prevent the tracker subscriber from performing its default action ( subscriber implementation dependent ) . Default : false .
2013-10-23 00:54:04 +04:00
* @ param { Object } event . userData
* Arbitrary user - defined object .
* /
stopHandler : function ( ) { } ,
2012-03-16 19:36:28 +04:00
/ * *
2013-10-31 05:28:10 +04:00
* Implement or assign implementation to these handlers during or after
2013-09-06 21:43:39 +04:00
* calling the constructor .
* @ function
2013-10-11 04:00:15 +04:00
* @ param { Object } event
* @ param { OpenSeadragon . MouseTracker } event . eventSource
2013-09-06 21:43:39 +04:00
* A reference to the tracker instance .
2013-10-11 04:00:15 +04:00
* @ param { Number } event . keyCode
2013-09-12 21:05:50 +04:00
* The key code that was pressed .
2013-10-11 04:00:15 +04:00
* @ param { Boolean } event . shift
2013-09-12 21:05:50 +04:00
* True if the shift key was pressed during this event .
2013-10-11 04:00:15 +04:00
* @ param { Object } event . originalEvent
2013-09-12 21:05:50 +04:00
* The original event object .
2013-11-18 18:56:32 +04:00
* @ param { Boolean } event . preventDefaultAction
* Set to true to prevent the tracker subscriber from performing its default action ( subscriber implementation dependent ) . Default : false .
2013-10-11 04:00:15 +04:00
* @ param { Object } event . userData
2013-09-12 21:05:50 +04:00
* Arbitrary user - defined object .
2013-09-06 21:43:39 +04:00
* /
2013-09-06 04:20:17 +04:00
keyHandler : function ( ) { } ,
/ * *
2013-10-31 05:28:10 +04:00
* Implement or assign implementation to these handlers during or after
2013-09-06 21:43:39 +04:00
* calling the constructor .
* @ function
2013-10-11 04:00:15 +04:00
* @ param { Object } event
* @ param { OpenSeadragon . MouseTracker } event . eventSource
2013-09-06 21:43:39 +04:00
* A reference to the tracker instance .
2013-10-11 04:00:15 +04:00
* @ param { Object } event . originalEvent
2013-09-12 21:05:50 +04:00
* The original event object .
2013-11-18 18:56:32 +04:00
* @ param { Boolean } event . preventDefaultAction
* Set to true to prevent the tracker subscriber from performing its default action ( subscriber implementation dependent ) . Default : false .
2013-10-11 04:00:15 +04:00
* @ param { Object } event . userData
2013-09-12 21:05:50 +04:00
* Arbitrary user - defined object .
2013-09-06 21:43:39 +04:00
* /
2013-09-06 04:20:17 +04:00
focusHandler : function ( ) { } ,
/ * *
2013-10-31 05:28:10 +04:00
* Implement or assign implementation to these handlers during or after
2013-09-06 21:43:39 +04:00
* calling the constructor .
* @ function
2013-10-11 04:00:15 +04:00
* @ param { Object } event
* @ param { OpenSeadragon . MouseTracker } event . eventSource
2013-09-06 21:43:39 +04:00
* A reference to the tracker instance .
2013-10-11 04:00:15 +04:00
* @ param { Object } event . originalEvent
2013-09-12 21:05:50 +04:00
* The original event object .
2013-11-18 18:56:32 +04:00
* @ param { Boolean } event . preventDefaultAction
* Set to true to prevent the tracker subscriber from performing its default action ( subscriber implementation dependent ) . Default : false .
2013-10-11 04:00:15 +04:00
* @ param { Object } event . userData
2013-09-12 21:05:50 +04:00
* Arbitrary user - defined object .
2013-09-06 21:43:39 +04:00
* /
2013-09-06 04:20:17 +04:00
blurHandler : function ( ) { }
2012-02-03 04:12:45 +04:00
} ;
2012-02-02 01:56:04 +04:00
2014-03-10 22:49:51 +04:00
2014-03-30 04:02:24 +04:00
/ * *
* Provides continuous computation of velocity ( speed and direction ) of active pointers .
* This is a singleton , used by all MouseTracker instances . Currently it is extremely unlikely there will ever be more than
* two active gesture pointers at a time .
2014-04-01 20:32:04 +04:00
*
* @ member gesturePointVelocityTracker
* @ memberof OpenSeadragon . MouseTracker
* @ private
2014-03-30 04:02:24 +04:00
* /
$ . MouseTracker . gesturePointVelocityTracker = ( function ( ) {
var trackerPoints = [ ] ,
intervalId = 0 ,
lastTime = 0 ;
// Generates a unique identifier for a tracked gesture point
var _generateGuid = function ( tracker , gPoint ) {
return tracker . hash . toString ( ) + gPoint . type + gPoint . id . toString ( ) ;
} ;
// Interval timer callback. Computes velocity for all tracked gesture points.
var _doTracking = function ( ) {
var i ,
len = trackerPoints . length ,
trackPoint ,
gPoint ,
now = $ . now ( ) ,
elapsedTime ,
distance ,
speed ;
elapsedTime = now - lastTime ;
lastTime = now ;
for ( i = 0 ; i < len ; i ++ ) {
trackPoint = trackerPoints [ i ] ;
gPoint = trackPoint . gPoint ;
// Math.atan2 gives us just what we need for a velocity vector, as we can simply
// use cos()/sin() to extract the x/y velocity components.
gPoint . direction = Math . atan2 ( gPoint . currentPos . y - trackPoint . lastPos . y , gPoint . currentPos . x - trackPoint . lastPos . x ) ;
// speed = distance / elapsed time
distance = trackPoint . lastPos . distanceTo ( gPoint . currentPos ) ;
trackPoint . lastPos = gPoint . currentPos ;
speed = 1000 * distance / ( elapsedTime + 1 ) ;
// Simple biased average, favors the most recent speed computation. Smooths out erratic gestures a bit.
gPoint . speed = 0.75 * speed + 0.25 * gPoint . speed ;
}
} ;
// Public. Add a gesture point to be tracked
var addPoint = function ( tracker , gPoint ) {
var guid = _generateGuid ( tracker , gPoint ) ;
trackerPoints . push (
{
guid : guid ,
gPoint : gPoint ,
lastPos : gPoint . currentPos
} ) ;
// Only fire up the interval timer when there's gesture points to track
if ( trackerPoints . length === 1 ) {
lastTime = $ . now ( ) ;
intervalId = window . setInterval ( _doTracking , 50 ) ;
}
} ;
// Public. Stop tracking a gesture point
var removePoint = function ( tracker , gPoint ) {
var guid = _generateGuid ( tracker , gPoint ) ,
i ,
len = trackerPoints . length ;
for ( i = 0 ; i < len ; i ++ ) {
if ( trackerPoints [ i ] . guid === guid ) {
//gPoint = trackerPoints[ i ].gPoint;
trackerPoints . splice ( i , 1 ) ;
// Only run the interval timer if theres gesture points to track
len -- ;
if ( len === 0 ) {
window . clearInterval ( intervalId ) ;
}
break ;
}
}
} ;
return {
addPoint : addPoint ,
removePoint : removePoint
} ;
} ) ( ) ;
2013-10-23 23:58:36 +04:00
/ * *
2014-03-10 22:49:51 +04:00
* Detect available mouse wheel event name .
2013-10-23 23:58:36 +04:00
* /
2013-10-24 00:55:52 +04:00
$ . MouseTracker . wheelEventName = ( $ . Browser . vendor == $ . BROWSERS . IE && $ . Browser . version > 8 ) ||
( 'onwheel' in document . createElement ( 'div' ) ) ? 'wheel' : // Modern browsers support 'wheel'
document . onmousewheel !== undefined ? 'mousewheel' : // Webkit and IE support at least 'mousewheel'
'DOMMouseScroll' ; // Assume old Firefox
2013-10-23 23:58:36 +04:00
2014-03-10 22:49:51 +04:00
/ * *
2014-03-30 04:02:24 +04:00
* Detect browser pointer device event model ( s ) and build appropriate list of events to subscribe to .
2014-03-10 22:49:51 +04:00
* /
$ . MouseTracker . subscribeEvents = [ "click" , "keypress" , "focus" , "blur" , $ . MouseTracker . wheelEventName ] ;
if ( $ . MouseTracker . wheelEventName == "DOMMouseScroll" ) {
// Older Firefox
$ . MouseTracker . subscribeEvents . push ( "MozMousePixelScroll" ) ;
}
if ( window . PointerEvent ) {
// IE11 and other W3C Pointer Event implementations (see http://www.w3.org/TR/pointerevents)
$ . MouseTracker . subscribeEvents . push ( "pointerover" , "pointerout" , "pointerdown" , "pointerup" , "pointermove" , "pointercancel" ) ;
$ . MouseTracker . unprefixedPointerEvents = true ;
if ( navigator . maxTouchPoints ) {
$ . MouseTracker . maxTouchPoints = navigator . maxTouchPoints ;
}
else {
$ . MouseTracker . maxTouchPoints = 0 ;
}
}
else if ( window . MSPointerEvent ) {
// IE10
$ . MouseTracker . subscribeEvents . push ( "MSPointerOver" , "MSPointerOut" , "MSPointerDown" , "MSPointerUp" , "MSPointerMove" , "MSPointerCancel" ) ;
$ . MouseTracker . unprefixedPointerEvents = false ;
if ( navigator . msMaxTouchPoints ) {
$ . MouseTracker . maxTouchPoints = navigator . msMaxTouchPoints ;
}
else {
$ . MouseTracker . maxTouchPoints = 0 ;
}
}
else {
2014-03-30 04:02:24 +04:00
// Standard mouse events
2014-03-10 22:49:51 +04:00
$ . MouseTracker . subscribeEvents . push ( "mouseover" , "mouseout" , "mousedown" , "mouseup" , "mousemove" ) ;
if ( 'ontouchstart' in window ) {
// iOS, Android, and other W3c Touch Event implementations (see http://www.w3.org/TR/2011/WD-touch-events-20110505)
2014-03-30 04:02:24 +04:00
$ . MouseTracker . subscribeEvents . push ( "touchstart" , "touchend" , "touchmove" , "touchcancel" ) ;
if ( 'ontouchenter' in window ) {
$ . MouseTracker . subscribeEvents . push ( "touchenter" , "touchleave" ) ;
$ . MouseTracker . haveTouchEnter = true ;
}
else {
$ . MouseTracker . haveTouchEnter = false ;
}
2014-03-21 22:45:20 +04:00
}
if ( 'ongesturestart' in window ) {
// iOS (see https://developer.apple.com/library/safari/documentation/UserExperience/Reference/GestureEventClassReference/GestureEvent/GestureEvent.html)
// Subscribe to these to prevent default gesture handling
$ . MouseTracker . subscribeEvents . push ( "gesturestart" , "gesturechange" ) ;
2014-03-10 22:49:51 +04:00
}
$ . MouseTracker . mousePointerId = "legacy-mouse" ;
$ . MouseTracker . maxTouchPoints = 10 ;
}
2014-03-30 04:02:24 +04:00
/ * *
* Represents a point of contact on the screen made by a mouse cursor , pen , touch , or other pointing device .
*
* @ typedef { Object } GesturePoint
* @ memberof OpenSeadragon . MouseTracker
*
* @ property { Number } id
* Identifier unique from all other active GesturePoints for a given pointer device .
* @ property { String } type
2014-03-31 23:54:37 +04:00
* The pointer device type : "mouse" , "touch" , "pen" , or "" .
2014-04-01 20:32:04 +04:00
* @ property { Boolean } isPrimary
* True if the gesture point is a master pointer amongst the set of active pointers for each pointer type . True for mouse and primary ( first ) touch / pen pointers .
2014-03-30 04:02:24 +04:00
* @ property { Boolean } insideElementPressed
2014-04-01 20:32:04 +04:00
* True if button pressed or contact point initiated inside the screen area of the tracked element .
2014-03-30 04:02:24 +04:00
* @ property { Boolean } insideElement
2014-04-01 20:32:04 +04:00
* True if pointer or contact point is currently inside the bounds of the tracked element .
2014-03-30 04:02:24 +04:00
* @ property { Number } speed
2014-04-01 20:32:04 +04:00
* Current computed speed , in pixels per second .
2014-03-30 04:02:24 +04:00
* @ property { Number } direction
2014-04-01 20:32:04 +04:00
* Current computed direction , expressed as an angle counterclockwise relative to the positive X axis ( - pi to pi , in radians ) . Only valid if speed > 0.
2014-03-30 04:02:24 +04:00
* @ property { OpenSeadragon . Point } startPos
* The initial pointer position , relative to the page including any scrolling .
* @ property { Number } startTime
* The initial pointer contact time , in milliseconds .
* @ property { OpenSeadragon . Point } lastPos
* The last pointer position , relative to the page including any scrolling .
* @ property { Number } lastTime
* The last pointer contact time , in milliseconds .
* @ property { OpenSeadragon . Point } currentPos
* The current pointer position , relative to the page including any scrolling .
* @ property { Number } currentTime
* The current pointer contact time , in milliseconds .
* /
2014-04-01 20:32:04 +04:00
/ * * *
2014-03-30 04:02:24 +04:00
* @ class GesturePointList
* @ classdesc Provides an abstraction for a set of { @ link OpenSeadragon . MouseTracker . GesturePoint } objects .
* @ memberof OpenSeadragon . MouseTracker
2014-04-01 20:32:04 +04:00
* @ private
2014-03-30 04:02:24 +04:00
* /
$ . MouseTracker . GesturePointList = function ( ) {
this . _gPoints = [ ] ;
} ;
$ . MouseTracker . GesturePointList . prototype = /** @lends OpenSeadragon.MouseTracker.GesturePointList.prototype */ {
/ * *
* @ function
* @ returns { Number } Number of gesture points in the list .
* /
getLength : function ( ) {
return this . _gPoints . length ;
} ,
/ * *
* @ function
* @ returns { Array . < OpenSeadragon . MouseTracker . GesturePoint > } The list of gesture points in the list as an array ( read - only ) .
* /
asArray : function ( ) {
return this . _gPoints ;
} ,
/ * *
* @ function
* @ param { OpenSeadragon . MouseTracker . GesturePoint } gesturePoint - A gesture point to add to the list .
* @ returns { Number } Number of gesture points in the list .
* /
add : function ( gp ) {
return this . _gPoints . push ( gp ) ;
} ,
/ * *
* @ function
* @ param { Number } id - The id of the gesture point to remove from the list .
* @ returns { Number } Number of gesture points in the list .
* /
removeById : function ( id ) {
var i ,
len = this . _gPoints . length ;
for ( i = 0 ; i < len ; i ++ ) {
if ( this . _gPoints [ i ] . id === id ) {
this . _gPoints . splice ( i , 1 ) ;
break ;
}
}
return this . _gPoints . length ;
} ,
2014-04-01 20:32:04 +04:00
/ * *
* @ function
* @ param { Number } index - The index of the gesture point to retrieve from the list .
* @ returns { OpenSeadragon . MouseTracker . GesturePoint | null } The gesture point at the given index , or null if not found .
* /
getByIndex : function ( index ) {
if ( index < this . _gPoints . length ) {
return this . _gPoints [ index ] ;
}
return null ;
} ,
2014-03-30 04:02:24 +04:00
/ * *
* @ function
* @ param { Number } id - The id of the gesture point to retrieve from the list .
* @ returns { OpenSeadragon . MouseTracker . GesturePoint | null } The gesture point with the given id , or null if not found .
* /
getById : function ( id ) {
var i ,
len = this . _gPoints . length ;
for ( i = 0 ; i < len ; i ++ ) {
if ( this . _gPoints [ i ] . id === id ) {
return this . _gPoints [ i ] ;
}
}
return null ;
2014-04-01 20:32:04 +04:00
} ,
/ * *
* @ function
* @ returns { OpenSeadragon . MouseTracker . GesturePoint | null } The primary gesture point in the list , or null if not found .
* /
getPrimary : function ( id ) {
var i ,
len = this . _gPoints . length ;
for ( i = 0 ; i < len ; i ++ ) {
if ( this . _gPoints [ i ] . isPrimary ) {
return this . _gPoints [ i ] ;
}
}
return null ;
2014-03-30 04:02:24 +04:00
}
} ;
2012-02-03 04:12:45 +04:00
/ * *
2014-04-01 20:32:04 +04:00
* Starts tracking pointer events on this element .
2013-09-06 21:43:39 +04:00
* @ private
* @ inner
* /
2012-02-03 04:12:45 +04:00
function startTracking ( tracker ) {
2014-03-10 22:49:51 +04:00
var delegate = THIS [ tracker . hash ] ,
2013-06-19 21:33:25 +04:00
event ,
2012-02-03 04:12:45 +04:00
i ;
if ( ! delegate . tracking ) {
2014-03-10 22:49:51 +04:00
for ( i = 0 ; i < $ . MouseTracker . subscribeEvents . length ; i ++ ) {
event = $ . MouseTracker . subscribeEvents [ i ] ;
2013-06-19 21:33:25 +04:00
$ . addEvent (
tracker . element ,
event ,
2013-09-20 20:58:18 +04:00
delegate [ event ] ,
2012-02-03 04:12:45 +04:00
false
) ;
2011-12-06 07:50:25 +04:00
}
2012-02-03 04:12:45 +04:00
delegate . tracking = true ;
2014-03-30 04:02:24 +04:00
//ACTIVE[ tracker.hash ] = tracker;
2012-02-03 04:12:45 +04:00
}
2013-01-29 21:32:58 +04:00
}
2011-12-06 07:50:25 +04:00
2012-02-03 04:12:45 +04:00
/ * *
2014-04-01 20:32:04 +04:00
* Stops tracking pointer events on this element .
2013-09-06 21:43:39 +04:00
* @ private
* @ inner
* /
2012-02-03 04:12:45 +04:00
function stopTracking ( tracker ) {
2014-03-10 22:49:51 +04:00
var delegate = THIS [ tracker . hash ] ,
2013-06-19 21:33:25 +04:00
event ,
2012-02-03 04:12:45 +04:00
i ;
2013-06-19 21:33:25 +04:00
2012-02-03 04:12:45 +04:00
if ( delegate . tracking ) {
2014-03-10 22:49:51 +04:00
for ( i = 0 ; i < $ . MouseTracker . subscribeEvents . length ; i ++ ) {
event = $ . MouseTracker . subscribeEvents [ i ] ;
2013-06-19 21:33:25 +04:00
$ . removeEvent (
tracker . element ,
event ,
2013-09-20 20:58:18 +04:00
delegate [ event ] ,
2012-02-03 04:12:45 +04:00
false
) ;
2011-12-06 07:50:25 +04:00
}
2012-02-03 04:12:45 +04:00
releaseMouse ( tracker ) ;
delegate . tracking = false ;
2014-03-30 04:02:24 +04:00
//delete ACTIVE[ tracker.hash ];
2012-02-03 04:12:45 +04:00
}
2013-01-29 21:32:58 +04:00
}
2011-12-06 07:50:25 +04:00
2012-02-03 04:12:45 +04:00
/ * *
2013-09-06 21:43:39 +04:00
* @ private
* @ inner
* /
2012-02-03 04:12:45 +04:00
function hasMouse ( tracker ) {
2013-09-20 20:58:18 +04:00
return THIS [ tracker . hash ] . insideElement ;
2013-01-29 21:32:58 +04:00
}
2011-12-06 07:50:25 +04:00
2012-02-03 04:12:45 +04:00
/ * *
2014-04-01 20:32:04 +04:00
* Begin capturing mouse events on this element ( legacy mouse events only ) .
2013-09-06 21:43:39 +04:00
* @ private
* @ inner
* /
2012-02-03 04:12:45 +04:00
function captureMouse ( tracker ) {
2013-09-20 20:58:18 +04:00
var delegate = THIS [ tracker . hash ] ;
2012-02-03 04:12:45 +04:00
if ( ! delegate . capturing ) {
2014-03-30 04:02:24 +04:00
//if ( $.Browser.vendor == $.BROWSERS.IE && $.Browser.version < 9 ) {
// $.removeEvent(
// tracker.element,
// "mouseup",
// delegate.mouseup,
// false
// );
// $.addEvent(
// tracker.element,
// "mouseup",
// delegate.mouseupcapturedie,
// true
// );
// $.addEvent(
// tracker.element,
// "mousemove",
// delegate.mousemovecapturedie,
// true
// );
//} else {
2013-06-19 21:33:25 +04:00
$ . addEvent (
window ,
"mouseup" ,
2013-09-10 01:27:58 +04:00
delegate . mouseupcaptured ,
2013-06-19 21:33:25 +04:00
true
2012-02-03 04:12:45 +04:00
) ;
2013-06-19 21:33:25 +04:00
$ . addEvent (
window ,
"mousemove" ,
2013-09-10 01:27:58 +04:00
delegate . mousemovecaptured ,
2013-06-19 21:33:25 +04:00
true
2012-02-03 04:12:45 +04:00
) ;
2014-03-30 04:02:24 +04:00
//}
2012-02-03 04:12:45 +04:00
delegate . capturing = true ;
}
2013-01-29 21:32:58 +04:00
}
2012-02-02 01:56:04 +04:00
2013-06-19 21:33:25 +04:00
2012-02-03 04:12:45 +04:00
/ * *
2014-04-01 20:32:04 +04:00
* Stop capturing mouse events on this element ( legacy mouse events only ) .
2013-09-06 21:43:39 +04:00
* @ private
* @ inner
* /
2012-02-03 04:12:45 +04:00
function releaseMouse ( tracker ) {
2013-09-20 20:58:18 +04:00
var delegate = THIS [ tracker . hash ] ;
2012-02-03 04:12:45 +04:00
if ( delegate . capturing ) {
2014-03-30 04:02:24 +04:00
//if ( $.Browser.vendor == $.BROWSERS.IE && $.Browser.version < 9 ) {
// $.removeEvent(
// tracker.element,
// "mousemove",
// delegate.mousemovecapturedie,
// true
// );
// $.removeEvent(
// tracker.element,
// "mouseup",
// delegate.mouseupcapturedie,
// true
// );
// $.addEvent(
// tracker.element,
// "mouseup",
// delegate.mouseup,
// false
// );
//} else {
2013-06-19 21:33:25 +04:00
$ . removeEvent (
window ,
"mousemove" ,
2013-09-10 01:27:58 +04:00
delegate . mousemovecaptured ,
2013-06-19 21:33:25 +04:00
true
2012-02-03 04:12:45 +04:00
) ;
2013-06-19 21:33:25 +04:00
$ . removeEvent (
window ,
"mouseup" ,
2013-09-10 01:27:58 +04:00
delegate . mouseupcaptured ,
2013-06-19 21:33:25 +04:00
true
2012-02-03 04:12:45 +04:00
) ;
2014-03-30 04:02:24 +04:00
//}
2012-02-03 04:12:45 +04:00
delegate . capturing = false ;
}
2013-01-29 21:32:58 +04:00
}
2011-12-06 07:50:25 +04:00
2012-02-10 07:16:09 +04:00
2012-02-03 04:12:45 +04:00
/ * *
2013-09-06 21:43:39 +04:00
* @ private
* @ inner
* /
2014-03-10 22:49:51 +04:00
//function triggerOthers( tracker, handler, event, isTouch ) {
// var otherHash;
// for ( otherHash in ACTIVE ) {
// if ( ACTIVE.hasOwnProperty( otherHash ) && tracker.hash != otherHash ) {
// handler( ACTIVE[ otherHash ], event, isTouch );
// }
// }
//}
2014-03-30 04:02:24 +04:00
/ * *
* @ private
* @ inner
* /
function getGPointsListByType ( tracker , type ) {
var delegate = THIS [ tracker . hash ] ,
list ;
if ( type === 'mouse' ) {
list = delegate . mousePoints ;
}
else if ( type === 'touch' ) {
list = delegate . touchPoints ;
}
else if ( type === 'pen' ) {
list = delegate . penPoints ;
}
else {
list = null ;
}
return list ;
}
2014-03-10 22:49:51 +04:00
/ * *
* @ private
* @ inner
* /
function getPointerType ( event ) {
var pointerTypeStr ;
if ( $ . MouseTracker . unprefixedPointerEvents ) {
pointerTypeStr = event . pointerType ;
}
else {
// IE10
// MSPOINTER_TYPE_TOUCH: 0x00000002
// MSPOINTER_TYPE_PEN: 0x00000003
// MSPOINTER_TYPE_MOUSE: 0x00000004
switch ( event . pointerType )
{
case 0x00000002 :
pointerTypeStr = 'touch' ;
break ;
case 0x00000003 :
pointerTypeStr = 'pen' ;
break ;
case 0x00000004 :
pointerTypeStr = 'mouse' ;
break ;
default :
pointerTypeStr = '' ;
2011-12-06 07:50:25 +04:00
}
2012-02-03 04:12:45 +04:00
}
2014-03-10 22:49:51 +04:00
return pointerTypeStr ;
2013-01-29 21:32:58 +04:00
}
2011-12-06 07:50:25 +04:00
2012-02-10 07:16:09 +04:00
2012-03-16 19:36:28 +04:00
/ * *
2013-09-06 21:43:39 +04:00
* @ private
* @ inner
* /
2014-03-10 22:49:51 +04:00
function getMouseAbsolute ( event ) {
return $ . getMousePosition ( event ) ;
2013-01-29 21:32:58 +04:00
}
2012-03-16 19:36:28 +04:00
2014-03-10 22:49:51 +04:00
/ * *
* @ private
* @ inner
* /
function getMouseRelative ( event , element ) {
2014-03-31 23:54:37 +04:00
return getPointRelativeToAbsolute ( getMouseAbsolute ( event ) , element ) ;
2014-03-10 22:49:51 +04:00
}
2012-03-16 19:36:28 +04:00
/ * *
2013-09-06 21:43:39 +04:00
* @ private
* @ inner
* /
2014-03-31 23:54:37 +04:00
function getPointRelativeToAbsolute ( point , element ) {
2014-03-10 22:49:51 +04:00
var offset = $ . getElementOffset ( element ) ;
return point . minus ( offset ) ;
}
2014-03-15 01:15:09 +04:00
/ * *
* @ private
* @ inner
* /
function getCenterPoint ( point1 , point2 ) {
return new $ . Point ( ( point1 . x + point2 . x ) / 2 , ( point1 . y + point2 . y ) / 2 ) ;
}
2014-03-10 22:49:51 +04:00
/ * *
* @ private
* @ inner
* /
function onClick ( tracker , event ) {
if ( tracker . clickHandler ) {
$ . cancelEvent ( event ) ;
2012-03-16 19:36:28 +04:00
}
2013-01-29 21:32:58 +04:00
}
2012-03-16 19:36:28 +04:00
2013-06-19 21:33:25 +04:00
2012-03-16 19:36:28 +04:00
/ * *
2013-09-06 21:43:39 +04:00
* @ private
* @ inner
* /
2013-09-06 04:20:17 +04:00
function onKeyPress ( tracker , event ) {
2012-03-21 05:58:23 +04:00
//console.log( "keypress %s %s %s %s %s", event.keyCode, event.charCode, event.ctrlKey, event.shiftKey, event.altKey );
2012-03-20 23:30:29 +04:00
var propagate ;
2012-03-16 19:36:28 +04:00
if ( tracker . keyHandler ) {
2014-03-10 22:49:51 +04:00
event = $ . getEvent ( event ) ;
2013-06-19 21:33:25 +04:00
propagate = tracker . keyHandler (
2013-09-06 04:20:17 +04:00
{
2013-11-05 00:41:45 +04:00
eventSource : tracker ,
position : getMouseRelative ( event , tracker . element ) ,
keyCode : event . keyCode ? event . keyCode : event . charCode ,
shift : event . shiftKey ,
originalEvent : event ,
preventDefaultAction : false ,
userData : tracker . userData
2013-09-06 04:20:17 +04:00
}
2012-04-11 01:02:24 +04:00
) ;
2013-09-06 04:20:17 +04:00
if ( ! propagate ) {
2012-04-11 01:02:24 +04:00
$ . cancelEvent ( event ) ;
2012-03-16 19:36:28 +04:00
}
}
2013-01-29 21:32:58 +04:00
}
2012-03-16 19:36:28 +04:00
2012-02-03 04:12:45 +04:00
/ * *
2013-09-06 21:43:39 +04:00
* @ private
* @ inner
* /
2014-03-10 22:49:51 +04:00
function onFocus ( tracker , event ) {
//console.log( "focus %s", event );
var propagate ;
if ( tracker . focusHandler ) {
event = $ . getEvent ( event ) ;
propagate = tracker . focusHandler (
2013-09-06 04:20:17 +04:00
{
2013-11-05 00:41:45 +04:00
eventSource : tracker ,
originalEvent : event ,
preventDefaultAction : false ,
userData : tracker . userData
2013-09-06 04:20:17 +04:00
}
2012-04-11 01:02:24 +04:00
) ;
2013-09-06 04:20:17 +04:00
if ( propagate === false ) {
2012-04-11 01:02:24 +04:00
$ . cancelEvent ( event ) ;
2011-12-06 07:50:25 +04:00
}
2012-02-03 04:12:45 +04:00
}
2013-01-29 21:32:58 +04:00
}
2011-12-06 07:50:25 +04:00
2012-02-10 07:16:09 +04:00
2012-02-03 04:12:45 +04:00
/ * *
2013-09-06 21:43:39 +04:00
* @ private
* @ inner
* /
2014-03-10 22:49:51 +04:00
function onBlur ( tracker , event ) {
//console.log( "blur %s", event );
var propagate ;
if ( tracker . blurHandler ) {
event = $ . getEvent ( event ) ;
propagate = tracker . blurHandler (
2013-09-06 04:20:17 +04:00
{
2013-11-05 00:41:45 +04:00
eventSource : tracker ,
originalEvent : event ,
preventDefaultAction : false ,
userData : tracker . userData
2013-09-06 04:20:17 +04:00
}
2012-04-11 01:02:24 +04:00
) ;
2013-09-06 04:20:17 +04:00
if ( propagate === false ) {
2012-04-11 01:02:24 +04:00
$ . cancelEvent ( event ) ;
2011-12-06 07:50:25 +04:00
}
2012-02-03 04:12:45 +04:00
}
2013-01-29 21:32:58 +04:00
}
2011-12-06 07:50:25 +04:00
2012-02-10 07:16:09 +04:00
2012-02-03 04:12:45 +04:00
/ * *
2014-03-10 22:49:51 +04:00
* Handler for 'wheel' events
*
2013-09-06 21:43:39 +04:00
* @ private
* @ inner
* /
2014-03-10 22:49:51 +04:00
function onWheel ( tracker , event ) {
handleWheelEvent ( tracker , event , event ) ;
}
2011-12-06 07:50:25 +04:00
2013-09-06 04:20:17 +04:00
2014-03-10 22:49:51 +04:00
/ * *
* Handler for 'mousewheel' , 'DOMMouseScroll' , and 'MozMousePixelScroll' events
*
* @ private
* @ inner
* /
function onMouseWheel ( tracker , event ) {
event = $ . getEvent ( event ) ;
2013-09-12 21:05:50 +04:00
2014-03-10 22:49:51 +04:00
// Simulate a 'wheel' event
var simulatedEvent = {
target : event . target || event . srcElement ,
type : "wheel" ,
shiftKey : event . shiftKey || false ,
clientX : event . clientX ,
clientY : event . clientY ,
pageX : event . pageX ? event . pageX : event . clientX ,
pageY : event . pageY ? event . pageY : event . clientY ,
deltaMode : event . type == "MozMousePixelScroll" ? 0 : 1 , // 0=pixel, 1=line, 2=page
deltaX : 0 ,
deltaZ : 0
} ;
2013-02-13 07:40:08 +04:00
2014-03-10 22:49:51 +04:00
// Calculate deltaY
if ( $ . MouseTracker . wheelEventName == "mousewheel" ) {
simulatedEvent . deltaY = - 1 / $ . DEFAULT _SETTINGS . pixelsPerWheelLine * event . wheelDelta ;
} else {
simulatedEvent . deltaY = event . detail ;
2012-02-03 04:12:45 +04:00
}
2011-12-06 07:50:25 +04:00
2014-03-10 22:49:51 +04:00
handleWheelEvent ( tracker , simulatedEvent , event ) ;
}
2012-02-03 04:12:45 +04:00
2012-02-02 01:56:04 +04:00
2012-02-10 07:16:09 +04:00
/ * *
2013-09-06 21:43:39 +04:00
* @ private
* @ inner
* /
2014-03-10 22:49:51 +04:00
function onMouseOver ( tracker , event ) {
2014-03-31 23:54:37 +04:00
var gPoint ;
2012-02-10 07:16:09 +04:00
2014-03-30 04:02:24 +04:00
event = $ . getEvent ( event ) ;
2013-06-19 21:33:25 +04:00
2014-03-21 22:45:20 +04:00
gPoint = {
2014-03-10 22:49:51 +04:00
id : $ . MouseTracker . mousePointerId ,
type : 'mouse' ,
2014-04-01 20:32:04 +04:00
isPrimary : true ,
2014-03-10 22:49:51 +04:00
insideElement : true ,
2014-03-31 23:54:37 +04:00
currentPos : getMouseAbsolute ( event ) ,
currentTime : $ . now ( )
2014-03-10 22:49:51 +04:00
} ;
2014-03-30 04:02:24 +04:00
updatePointersOver ( tracker , event , [ gPoint ] ) ;
2014-03-10 22:49:51 +04:00
}
2012-02-03 04:12:45 +04:00
2014-03-10 22:49:51 +04:00
/ * *
* @ private
* @ inner
* /
function onMouseOut ( tracker , event ) {
2014-03-31 23:54:37 +04:00
var gPoint ;
2013-09-06 04:20:17 +04:00
2014-03-30 04:02:24 +04:00
event = $ . getEvent ( event ) ;
2013-02-13 07:40:08 +04:00
2014-03-21 22:45:20 +04:00
gPoint = {
2014-03-10 22:49:51 +04:00
id : $ . MouseTracker . mousePointerId ,
type : 'mouse' ,
2014-04-01 20:32:04 +04:00
isPrimary : true ,
2014-03-10 22:49:51 +04:00
insideElement : false ,
2014-03-31 23:54:37 +04:00
currentPos : getMouseAbsolute ( event ) ,
currentTime : $ . now ( )
2014-03-10 22:49:51 +04:00
} ;
2014-03-30 04:02:24 +04:00
updatePointersOut ( tracker , event , [ gPoint ] ) ;
2013-01-29 21:32:58 +04:00
}
2012-02-03 04:12:45 +04:00
2012-02-10 07:16:09 +04:00
/ * *
2013-09-06 21:43:39 +04:00
* @ private
* @ inner
* /
2014-03-10 22:49:51 +04:00
function onMouseDown ( tracker , event ) {
2014-03-31 23:54:37 +04:00
var gPoint ;
2014-03-10 22:49:51 +04:00
2014-03-30 04:02:24 +04:00
event = $ . getEvent ( event ) ;
2014-03-10 22:49:51 +04:00
if ( event . button == 2 ) {
return ;
}
2012-02-10 07:16:09 +04:00
2014-03-21 22:45:20 +04:00
gPoint = {
2014-03-10 22:49:51 +04:00
id : $ . MouseTracker . mousePointerId ,
type : 'mouse' ,
2014-04-01 20:32:04 +04:00
isPrimary : true ,
2014-03-31 23:54:37 +04:00
currentPos : getMouseAbsolute ( event ) ,
currentTime : $ . now ( )
2014-03-10 22:49:51 +04:00
} ;
2013-09-06 04:20:17 +04:00
2014-03-30 04:02:24 +04:00
addPointers ( tracker , event , [ gPoint ] ) ;
2012-02-10 07:16:09 +04:00
2014-03-30 04:02:24 +04:00
if ( tracker . pressHandler || tracker . dragHandler ) {
2014-03-10 22:49:51 +04:00
$ . cancelEvent ( event ) ;
2012-02-10 07:16:09 +04:00
}
2014-03-10 22:49:51 +04:00
2014-03-30 04:02:24 +04:00
//if ( !( $.Browser.vendor == $.BROWSERS.IE && $.Browser.version < 9 ) ||
// !IS_CAPTURING ) {
2014-03-10 22:49:51 +04:00
captureMouse ( tracker ) ;
2014-03-30 04:02:24 +04:00
//IS_CAPTURING = true;
//// reset to empty & add us
//CAPTURING = [ tracker ];
//} else if ( $.Browser.vendor == $.BROWSERS.IE && $.Browser.version < 9 ) {
// // add us to the list
// CAPTURING.push( tracker );
//}
2014-03-10 22:49:51 +04:00
}
/ * *
* @ private
* @ inner
* /
function onMouseUp ( tracker , event ) {
handleMouseUp ( tracker , event ) ;
}
/ * *
* Only triggered in W3C browsers by elements within which the mouse was
* initially pressed , since they are now listening to the window for
* mouseup during the capture phase . We shouldn ' t handle the mouseup
* here if the mouse is still inside this element , since the regular
* mouseup handler will still fire .
* @ private
* @ inner
* /
function onMouseUpCaptured ( tracker , event ) {
var delegate = THIS [ tracker . hash ] ,
2014-03-30 04:02:24 +04:00
gPoint = delegate . mousePoints . getById ( $ . MouseTracker . mousePointerId ) ;
2014-03-10 22:49:51 +04:00
2014-03-30 04:02:24 +04:00
if ( gPoint && ! gPoint . insideElement ) {
2014-03-10 22:49:51 +04:00
handleMouseUp ( tracker , event ) ;
}
releaseMouse ( tracker ) ;
2013-01-29 21:32:58 +04:00
}
2012-02-10 07:16:09 +04:00
2012-02-03 04:12:45 +04:00
/ * *
2013-09-06 21:43:39 +04:00
* Only triggered once by the deepest element that initially received
* the mouse down event . We want to make sure THIS event doesn ' t bubble .
* Instead , we want to trigger the elements that initially received the
* mouse down event ( including this one ) only if the mouse is no longer
* inside them . Then , we want to release capture , and emulate a regular
* mouseup on the event that this event was meant for .
* @ private
* @ inner
* /
2014-03-30 04:02:24 +04:00
//function onMouseUpCapturedIE( tracker, event ) {
// var othertracker,
// i;
2012-02-03 04:12:45 +04:00
2014-03-30 04:02:24 +04:00
// event = $.getEvent( event );
2013-02-13 07:40:08 +04:00
2014-03-30 04:02:24 +04:00
// if ( event.button == 2 ) {
// return;
// }
2012-02-03 04:12:45 +04:00
2014-03-30 04:02:24 +04:00
// for ( i = 0; i < CAPTURING.length; i++ ) {
// othertracker = CAPTURING[ i ];
// if ( !hasMouse( othertracker ) ) {
// handleMouseUp( othertracker, event );
// }
// }
2011-12-06 07:50:25 +04:00
2014-03-30 04:02:24 +04:00
// releaseMouse( tracker );
// IS_CAPTURING = false;
// event.srcElement.fireEvent(
// "on" + event.type,
// document.createEventObject( event )
// );
2011-12-06 07:50:25 +04:00
2014-03-30 04:02:24 +04:00
// $.stopEvent( event );
//}
2012-02-03 04:12:45 +04:00
2012-02-10 07:16:09 +04:00
2012-02-03 04:12:45 +04:00
/ * *
2013-09-06 21:43:39 +04:00
* @ private
* @ inner
* /
2013-09-06 04:20:17 +04:00
function onMouseMove ( tracker , event ) {
2014-03-31 23:54:37 +04:00
var delegate = THIS [ tracker . hash ] ;
if ( ! delegate . capturing ) {
handleMouseMove ( tracker , event ) ;
}
}
2014-03-10 22:49:51 +04:00
2013-10-23 00:54:04 +04:00
/ * *
* @ private
* @ inner
* /
2014-03-10 22:49:51 +04:00
function onMouseMoveCaptured ( tracker , event ) {
handleMouseMove ( tracker , event ) ;
2013-09-06 04:20:17 +04:00
}
2014-03-10 22:49:51 +04:00
2013-09-06 04:20:17 +04:00
/ * *
2014-03-10 22:49:51 +04:00
* Only triggered once by the deepest element that initially received
* the mouse down event . Since no other element has captured the mouse ,
* we want to trigger the elements that initially received the mouse
* down event ( including this one ) . The the param tracker isn ' t used
* but for consistency with the other event handlers we include it .
2013-09-06 21:43:39 +04:00
* @ private
* @ inner
* /
2014-03-30 04:02:24 +04:00
//function onMouseMoveCapturedIE( tracker, event ) {
// var i;
// for ( i = 0; i < CAPTURING.length; i++ ) {
// handleMouseMove( CAPTURING[ i ], event );
// }
//
// $.stopEvent( event );
//}
2012-02-03 04:12:45 +04:00
2012-02-10 07:16:09 +04:00
2012-02-03 04:12:45 +04:00
/ * *
2013-09-06 21:43:39 +04:00
* @ private
* @ inner
* /
2014-03-21 22:45:20 +04:00
function onTouchEnter ( tracker , event ) {
2014-03-31 23:54:37 +04:00
var i ,
2014-03-21 22:45:20 +04:00
touchCount = event . changedTouches . length ,
gPoints = [ ] ;
2014-03-10 22:49:51 +04:00
2014-03-21 22:45:20 +04:00
for ( i = 0 ; i < touchCount ; i ++ ) {
gPoints . push ( {
id : event . changedTouches [ i ] . identifier ,
type : 'touch' ,
insideElement : true ,
2014-03-31 23:54:37 +04:00
currentPos : getMouseAbsolute ( event . changedTouches [ i ] ) ,
currentTime : $ . now ( )
2014-03-21 22:45:20 +04:00
} ) ;
}
2014-03-10 22:49:51 +04:00
2014-03-21 22:45:20 +04:00
updatePointersOver ( tracker , event , gPoints ) ;
2013-10-23 23:58:36 +04:00
}
/ * *
* @ private
* @ inner
* /
2014-03-21 22:45:20 +04:00
function onTouchLeave ( tracker , event ) {
2014-03-31 23:54:37 +04:00
var i ,
2014-03-10 22:49:51 +04:00
touchCount = event . changedTouches . length ,
2014-03-21 22:45:20 +04:00
gPoints = [ ] ;
2014-03-10 22:49:51 +04:00
2014-03-21 22:45:20 +04:00
for ( i = 0 ; i < touchCount ; i ++ ) {
gPoints . push ( {
id : event . changedTouches [ i ] . identifier ,
type : 'touch' ,
insideElement : false ,
2014-03-31 23:54:37 +04:00
currentPos : getMouseAbsolute ( event . changedTouches [ i ] ) ,
currentTime : $ . now ( )
2014-03-21 22:45:20 +04:00
} ) ;
}
updatePointersOut ( tracker , event , gPoints ) ;
}
/ * *
* @ private
* @ inner
* /
function onTouchStart ( tracker , event ) {
var delegate = THIS [ tracker . hash ] ,
time ,
2014-04-01 20:32:04 +04:00
primaryPoint ,
primaryId ,
2014-03-21 22:45:20 +04:00
gPoint ,
i ,
touchCount = event . changedTouches . length ,
gPoints = [ ] ;
time = $ . now ( ) ;
2014-03-30 04:02:24 +04:00
if ( ! $ . MouseTracker . haveTouchEnter && touchCount > 0 && delegate . touchPoints . getLength ( ) === 0 ) {
2014-03-21 22:45:20 +04:00
gPoint = {
id : event . changedTouches [ 0 ] . identifier ,
2014-03-10 22:49:51 +04:00
type : 'touch' ,
insideElement : true ,
currentPos : getMouseAbsolute ( event . changedTouches [ 0 ] ) ,
currentTime : time
} ;
2014-03-30 04:02:24 +04:00
updatePointersOver ( tracker , event , [ gPoint ] ) ;
2014-03-10 22:49:51 +04:00
}
2013-10-23 23:58:36 +04:00
2014-04-01 20:32:04 +04:00
primaryPoint = delegate . touchPoints . getPrimary ( ) ;
if ( primaryPoint ) {
primaryId = primaryPoint . id ;
}
else {
primaryId = event . changedTouches [ 0 ] . identifier ;
}
2014-03-10 22:49:51 +04:00
for ( i = 0 ; i < touchCount ; i ++ ) {
2014-03-21 22:45:20 +04:00
gPoints . push ( {
2014-03-10 22:49:51 +04:00
id : event . changedTouches [ i ] . identifier ,
type : 'touch' ,
2014-04-01 20:32:04 +04:00
isPrimary : event . changedTouches [ i ] . identifier === primaryId ,
2014-03-31 23:54:37 +04:00
currentPos : getMouseAbsolute ( event . changedTouches [ i ] ) ,
2014-03-10 22:49:51 +04:00
currentTime : time
} ) ;
}
2013-10-23 23:58:36 +04:00
2014-03-21 22:45:20 +04:00
addPointers ( tracker , event , gPoints ) ;
2014-03-10 22:49:51 +04:00
2014-03-30 04:02:24 +04:00
if ( tracker . pressHandler || tracker . dragHandler || tracker . pinchHandler ) {
$ . stopEvent ( event ) ;
$ . cancelEvent ( event ) ;
2014-03-21 22:45:20 +04:00
return false ;
}
2014-03-10 22:49:51 +04:00
}
/ * *
* @ private
* @ inner
* /
function onTouchEnd ( tracker , event ) {
var delegate = THIS [ tracker . hash ] ,
time ,
2014-04-01 20:32:04 +04:00
primaryPoint ,
2014-03-21 22:45:20 +04:00
gPoint ,
2014-03-10 22:49:51 +04:00
i ,
touchCount = event . changedTouches . length ,
2014-03-21 22:45:20 +04:00
gPoints = [ ] ;
2014-03-10 22:49:51 +04:00
time = $ . now ( ) ;
for ( i = 0 ; i < touchCount ; i ++ ) {
2014-03-21 22:45:20 +04:00
gPoints . push ( {
2014-03-10 22:49:51 +04:00
id : event . changedTouches [ i ] . identifier ,
type : 'touch' ,
2014-03-31 23:54:37 +04:00
currentPos : getMouseAbsolute ( event . changedTouches [ i ] ) ,
2014-03-10 22:49:51 +04:00
currentTime : time
} ) ;
}
2014-03-21 22:45:20 +04:00
removePointers ( tracker , event , gPoints ) ;
2014-03-10 22:49:51 +04:00
2014-04-01 20:32:04 +04:00
primaryPoint = delegate . touchPoints . getPrimary ( ) ;
if ( ! primaryPoint ) {
primaryPoint = delegate . touchPoints . getByIndex ( 0 ) ;
if ( primaryPoint ) {
primaryPoint . isPrimary = true ;
}
}
2014-03-30 04:02:24 +04:00
if ( ! $ . MouseTracker . haveTouchEnter && touchCount > 0 && delegate . touchPoints . getLength ( ) === 0 ) {
2014-03-21 22:45:20 +04:00
gPoint = {
2014-03-10 22:49:51 +04:00
id : event . changedTouches [ 0 ] . identifier ,
type : 'touch' ,
insideElement : false ,
currentPos : getMouseAbsolute ( event . changedTouches [ 0 ] ) ,
currentTime : time
} ;
2014-03-30 04:02:24 +04:00
updatePointersOut ( tracker , event , [ gPoint ] ) ;
2014-03-10 22:49:51 +04:00
}
2014-03-30 04:02:24 +04:00
if ( tracker . pressHandler || tracker . dragHandler || tracker . dragEndHandler || tracker . pinchHandler ) {
$ . stopEvent ( event ) ;
$ . cancelEvent ( event ) ;
2014-03-21 22:45:20 +04:00
return false ;
}
2014-03-10 22:49:51 +04:00
}
/ * *
* @ private
* @ inner
* /
function onTouchMove ( tracker , event ) {
2014-03-31 23:54:37 +04:00
var i ,
2014-03-10 22:49:51 +04:00
touchCount = event . changedTouches . length ,
2014-03-21 22:45:20 +04:00
gPoints = [ ] ;
2014-03-10 22:49:51 +04:00
for ( i = 0 ; i < touchCount ; i ++ ) {
2014-03-21 22:45:20 +04:00
gPoints . push ( {
2014-03-10 22:49:51 +04:00
id : event . changedTouches [ i ] . identifier ,
type : 'touch' ,
2014-03-31 23:54:37 +04:00
currentPos : getMouseAbsolute ( event . changedTouches [ i ] ) ,
currentTime : $ . now ( )
2014-03-10 22:49:51 +04:00
} ) ;
2013-10-23 23:58:36 +04:00
}
2014-03-21 22:45:20 +04:00
updatePointers ( tracker , event , gPoints ) ;
2014-03-10 22:49:51 +04:00
2014-03-30 04:02:24 +04:00
if ( tracker . pressHandler || tracker . dragHandler || tracker . pinchHandler ) {
$ . stopEvent ( event ) ;
$ . cancelEvent ( event ) ;
2014-03-21 22:45:20 +04:00
return false ;
}
2013-10-23 23:58:36 +04:00
}
2014-03-21 22:45:20 +04:00
/ * *
* @ private
* @ inner
* /
function onTouchCancel ( tracker , event ) {
2014-03-31 23:54:37 +04:00
var i ,
2014-03-21 22:45:20 +04:00
touchCount = event . changedTouches . length ,
gPoints = [ ] ;
for ( i = 0 ; i < touchCount ; i ++ ) {
gPoints . push ( {
id : event . changedTouches [ i ] . identifier ,
type : 'touch' ,
} ) ;
}
cancelPointers ( tracker , event , gPoints ) ;
}
2014-03-14 21:42:22 +04:00
/ * *
* @ private
* @ inner
* /
function onGestureStart ( tracker , event ) {
event . stopPropagation ( ) ;
event . preventDefault ( ) ;
return false ;
}
/ * *
* @ private
* @ inner
* /
function onGestureChange ( tracker , event ) {
event . stopPropagation ( ) ;
event . preventDefault ( ) ;
return false ;
}
2014-03-21 22:45:20 +04:00
/ * *
* @ private
* @ inner
* /
function onPointerOver ( tracker , event ) {
2014-03-31 23:54:37 +04:00
var gPoint ;
2014-03-21 22:45:20 +04:00
gPoint = {
id : event . pointerId ,
type : getPointerType ( event ) ,
2014-04-01 20:32:04 +04:00
isPrimary : event . isPrimary ,
2014-03-21 22:45:20 +04:00
insideElement : true ,
2014-03-31 23:54:37 +04:00
currentPos : getMouseAbsolute ( event ) ,
currentTime : $ . now ( )
2014-03-21 22:45:20 +04:00
} ;
2014-03-30 04:02:24 +04:00
updatePointersOver ( tracker , event , [ gPoint ] ) ;
2014-03-21 22:45:20 +04:00
}
/ * *
* @ private
* @ inner
* /
function onPointerOut ( tracker , event ) {
2014-03-31 23:54:37 +04:00
var gPoint ;
2014-03-21 22:45:20 +04:00
gPoint = {
id : event . pointerId ,
type : getPointerType ( event ) ,
2014-04-01 20:32:04 +04:00
isPrimary : event . isPrimary ,
2014-03-21 22:45:20 +04:00
insideElement : false ,
2014-03-31 23:54:37 +04:00
currentPos : getMouseAbsolute ( event ) ,
currentTime : $ . now ( )
2014-03-21 22:45:20 +04:00
} ;
2014-03-30 04:02:24 +04:00
updatePointersOut ( tracker , event , [ gPoint ] ) ;
2014-03-21 22:45:20 +04:00
}
/ * *
* @ private
* @ inner
* /
function onPointerDown ( tracker , event ) {
2014-03-31 23:54:37 +04:00
var gPoint ;
2014-03-21 22:45:20 +04:00
if ( event . button == 2 ) {
return ;
}
if ( $ . MouseTracker . unprefixedPointerEvents ) {
2014-03-30 04:02:24 +04:00
event . currentTarget . setPointerCapture ( event . pointerId ) ;
2014-03-21 22:45:20 +04:00
}
else {
2014-03-30 04:02:24 +04:00
event . currentTarget . msSetPointerCapture ( event . pointerId ) ;
2014-03-21 22:45:20 +04:00
}
gPoint = {
id : event . pointerId ,
type : getPointerType ( event ) ,
2014-04-01 20:32:04 +04:00
isPrimary : event . isPrimary ,
2014-03-31 23:54:37 +04:00
currentPos : getMouseAbsolute ( event ) ,
currentTime : $ . now ( )
2014-03-21 22:45:20 +04:00
} ;
2014-03-30 04:02:24 +04:00
addPointers ( tracker , event , [ gPoint ] ) ;
2014-03-21 22:45:20 +04:00
2014-03-30 04:02:24 +04:00
if ( tracker . pressHandler || tracker . dragHandler || tracker . pinchHandler ) {
$ . stopEvent ( event ) ;
$ . cancelEvent ( event ) ;
2014-03-21 22:45:20 +04:00
return false ;
}
}
/ * *
* @ private
* @ inner
* /
function onPointerUp ( tracker , event ) {
2014-03-31 23:54:37 +04:00
var gPoint ;
2014-03-21 22:45:20 +04:00
if ( event . button == 2 ) {
return ;
}
if ( $ . MouseTracker . unprefixedPointerEvents ) {
2014-03-30 04:02:24 +04:00
event . currentTarget . releasePointerCapture ( event . pointerId ) ;
2014-03-21 22:45:20 +04:00
}
else {
2014-03-30 04:02:24 +04:00
event . currentTarget . msReleasePointerCapture ( event . pointerId ) ;
2014-03-21 22:45:20 +04:00
}
gPoint = {
id : event . pointerId ,
type : getPointerType ( event ) ,
2014-04-01 20:32:04 +04:00
isPrimary : event . isPrimary ,
2014-03-31 23:54:37 +04:00
currentPos : getMouseAbsolute ( event ) ,
currentTime : $ . now ( )
2014-03-21 22:45:20 +04:00
} ;
2014-03-30 04:02:24 +04:00
removePointers ( tracker , event , [ gPoint ] ) ;
2014-03-21 22:45:20 +04:00
2014-03-30 04:02:24 +04:00
if ( tracker . pressHandler || tracker . dragHandler || tracker . dragEndHandler || tracker . pinchHandler ) {
$ . stopEvent ( event ) ;
$ . cancelEvent ( event ) ;
2014-03-21 22:45:20 +04:00
return false ;
}
}
/ * *
* @ private
* @ inner
* /
function onPointerMove ( tracker , event ) {
// Pointer changed coordinates, button state, pressure, tilt, or contact geometry (e.g. width and height)
2014-03-31 23:54:37 +04:00
var gPoint ;
2014-03-21 22:45:20 +04:00
gPoint = {
id : event . pointerId ,
type : getPointerType ( event ) ,
2014-04-01 20:32:04 +04:00
isPrimary : event . isPrimary ,
2014-03-31 23:54:37 +04:00
currentPos : getMouseAbsolute ( event ) ,
currentTime : $ . now ( )
2014-03-21 22:45:20 +04:00
} ;
2014-03-30 04:02:24 +04:00
updatePointers ( tracker , event , [ gPoint ] ) ;
2014-03-21 22:45:20 +04:00
2014-03-30 04:02:24 +04:00
if ( tracker . pressHandler || tracker . dragHandler || tracker . pinchHandler ) {
$ . stopEvent ( event ) ;
$ . cancelEvent ( event ) ;
2014-03-21 22:45:20 +04:00
return false ;
}
}
/ * *
* @ private
* @ inner
* /
function onPointerCancel ( tracker , event ) {
2014-03-31 23:54:37 +04:00
var gPoint ;
2014-03-21 22:45:20 +04:00
gPoint = {
id : event . pointerId ,
type : getPointerType ( event ) ,
2014-04-01 20:32:04 +04:00
isPrimary : event . isPrimary ,
2014-03-21 22:45:20 +04:00
} ;
2014-03-30 04:02:24 +04:00
cancelPointers ( tracker , event , [ gPoint ] ) ;
2014-03-21 22:45:20 +04:00
}
2013-10-23 23:58:36 +04:00
/ * *
* Handles 'wheel' events .
2014-03-10 22:49:51 +04:00
* The event may be simulated by the legacy mouse wheel event handler ( onMouseWheel ( ) ) .
2013-10-23 23:58:36 +04:00
*
* @ private
* @ inner
* /
2014-03-10 22:49:51 +04:00
function handleWheelEvent ( tracker , event , originalEvent ) {
2012-04-03 11:08:27 +04:00
var nDelta = 0 ,
propagate ;
2013-06-19 21:33:25 +04:00
2013-10-23 23:58:36 +04:00
// The nDelta variable is gated to provide smooth z-index scrolling
// since the mouse wheel allows for substantial deltas meant for rapid
// y-index scrolling.
// event.deltaMode: 0=pixel, 1=line, 2=page
// TODO: Deltas in pixel mode should be accumulated then a scroll value computed after $.DEFAULT_SETTINGS.pixelsPerWheelLine threshold reached
nDelta = event . deltaY < 0 ? 1 : - 1 ;
2011-12-06 07:50:25 +04:00
2012-02-03 04:12:45 +04:00
if ( tracker . scrollHandler ) {
2012-04-11 01:02:24 +04:00
propagate = tracker . scrollHandler (
2013-09-06 04:20:17 +04:00
{
2013-11-05 00:41:45 +04:00
eventSource : tracker ,
2014-03-21 22:45:20 +04:00
pointerType : 'mouse' ,
2013-11-05 00:41:45 +04:00
position : getMouseRelative ( event , tracker . element ) ,
scroll : nDelta ,
shift : event . shiftKey ,
2014-03-10 22:49:51 +04:00
isTouchEvent : false ,
2013-11-05 00:41:45 +04:00
originalEvent : originalEvent ,
preventDefaultAction : false ,
userData : tracker . userData
2013-09-06 04:20:17 +04:00
}
2012-04-11 01:02:24 +04:00
) ;
2013-09-06 04:20:17 +04:00
if ( propagate === false ) {
2013-10-24 00:55:52 +04:00
$ . cancelEvent ( originalEvent ) ;
2011-12-06 07:50:25 +04:00
}
2012-02-03 04:12:45 +04:00
}
2013-01-29 21:32:58 +04:00
}
2012-02-03 04:12:45 +04:00
2012-02-10 07:16:09 +04:00
2012-02-03 04:12:45 +04:00
/ * *
2013-09-06 21:43:39 +04:00
* @ private
* @ inner
* /
2014-03-10 22:49:51 +04:00
function handleMouseMove ( tracker , event ) {
2014-03-31 23:54:37 +04:00
var gPoint ;
2014-03-10 22:49:51 +04:00
2014-03-30 04:02:24 +04:00
event = $ . getEvent ( event ) ;
2012-02-03 04:12:45 +04:00
2014-03-21 22:45:20 +04:00
gPoint = {
2014-03-10 22:49:51 +04:00
id : $ . MouseTracker . mousePointerId ,
type : 'mouse' ,
2014-04-01 20:32:04 +04:00
isPrimary : true ,
2014-03-31 23:54:37 +04:00
currentPos : getMouseAbsolute ( event ) ,
currentTime : $ . now ( )
2014-03-10 22:49:51 +04:00
} ;
2013-09-11 04:23:19 +04:00
2014-03-30 04:02:24 +04:00
updatePointers ( tracker , event , [ gPoint ] ) ;
2014-03-10 22:49:51 +04:00
}
/ * *
* @ private
* @ inner
* /
function handleMouseUp ( tracker , event ) {
2014-03-31 23:54:37 +04:00
var gPoint ;
2013-09-11 04:23:19 +04:00
2014-03-30 04:02:24 +04:00
event = $ . getEvent ( event ) ;
2013-02-13 07:40:08 +04:00
2012-02-03 04:12:45 +04:00
if ( event . button == 2 ) {
return ;
}
2014-03-21 22:45:20 +04:00
gPoint = {
2014-03-10 22:49:51 +04:00
id : $ . MouseTracker . mousePointerId ,
type : 'mouse' ,
2014-04-01 20:32:04 +04:00
isPrimary : true ,
2014-03-31 23:54:37 +04:00
currentPos : getMouseAbsolute ( event ) ,
currentTime : $ . now ( )
2014-03-10 22:49:51 +04:00
} ;
2012-02-03 04:12:45 +04:00
2014-03-30 04:02:24 +04:00
removePointers ( tracker , event , [ gPoint ] ) ;
2014-03-10 22:49:51 +04:00
}
/ * *
* @ private
* @ inner
* /
2014-04-01 20:32:04 +04:00
function handlePointerStop ( tracker , originalMoveEvent , pointerType ) {
2014-03-10 22:49:51 +04:00
if ( tracker . stopHandler ) {
tracker . stopHandler ( {
eventSource : tracker ,
2014-04-01 20:32:04 +04:00
pointerType : pointerType ,
2014-03-10 22:49:51 +04:00
position : getMouseRelative ( originalMoveEvent , tracker . element ) ,
2014-04-01 20:32:04 +04:00
isTouchEvent : pointerType === 'touch' ,
2014-03-10 22:49:51 +04:00
originalEvent : originalMoveEvent ,
preventDefaultAction : false ,
userData : tracker . userData
} ) ;
2012-02-03 04:12:45 +04:00
}
2013-01-29 21:32:58 +04:00
}
2011-12-06 07:50:25 +04:00
2012-02-10 07:16:09 +04:00
2012-02-03 04:12:45 +04:00
/ * *
2013-09-06 21:43:39 +04:00
* @ private
* @ inner
* /
2014-03-21 22:45:20 +04:00
function addPointers ( tracker , event , gPoints ) {
2013-09-20 20:58:18 +04:00
var delegate = THIS [ tracker . hash ] ,
2013-02-13 07:40:08 +04:00
propagate ,
2014-03-30 04:02:24 +04:00
pointsList = getGPointsListByType ( tracker , gPoints [ 0 ] . type ) ,
pointsListLength ,
2014-03-10 22:49:51 +04:00
i ,
2014-03-21 22:45:20 +04:00
gPointCount = gPoints . length ,
curGPoint ;
2014-03-10 22:49:51 +04:00
2014-03-30 04:02:24 +04:00
if ( pointsList ) {
for ( i = 0 ; i < gPointCount ; i ++ ) {
curGPoint = gPoints [ i ] ;
// Initialize for drag/swipe/pinch
2014-03-31 23:54:37 +04:00
curGPoint . insideElementPressed = true ;
curGPoint . insideElement = true ;
2014-03-30 04:02:24 +04:00
curGPoint . speed = 0 ;
curGPoint . direction = 0 ;
curGPoint . startPos = curGPoint . currentPos ;
curGPoint . startTime = curGPoint . currentTime ;
curGPoint . lastPos = curGPoint . currentPos ;
curGPoint . lastTime = curGPoint . currentTime ;
if ( tracker . dragHandler || tracker . dragEndHandler || tracker . pinchHandler ) {
$ . MouseTracker . gesturePointVelocityTracker . addPoint ( tracker , curGPoint ) ;
2014-03-10 22:49:51 +04:00
}
2014-03-30 04:02:24 +04:00
pointsListLength = pointsList . add ( curGPoint ) ;
if ( pointsListLength == 1 ) {
// Press
if ( tracker . pressHandler ) {
propagate = tracker . pressHandler (
{
eventSource : tracker ,
pointerType : curGPoint . type ,
2014-03-31 23:54:37 +04:00
position : getPointRelativeToAbsolute ( curGPoint . startPos , tracker . element ) ,
2014-03-30 04:02:24 +04:00
isTouchEvent : curGPoint . type === 'touch' ,
originalEvent : event ,
preventDefaultAction : false ,
userData : tracker . userData
}
) ;
if ( propagate === false ) {
$ . cancelEvent ( event ) ;
2014-03-10 22:49:51 +04:00
}
}
}
2014-03-30 04:02:24 +04:00
else if ( pointsListLength == 2 ) {
if ( tracker . pinchHandler && curGPoint . type === 'touch' ) {
// Initialize for pinch
delegate . pinchGPoints = pointsList . asArray ( ) ;
delegate . lastPinchDist = delegate . currentPinchDist = delegate . pinchGPoints [ 0 ] . currentPos . distanceTo ( delegate . pinchGPoints [ 1 ] . currentPos ) ;
delegate . lastPinchCenter = delegate . currentPinchCenter = getCenterPoint ( delegate . pinchGPoints [ 0 ] . currentPos , delegate . pinchGPoints [ 1 ] . currentPos ) ;
2014-03-10 22:49:51 +04:00
}
}
}
}
}
2013-09-06 04:20:17 +04:00
2012-02-03 04:12:45 +04:00
2014-03-10 22:49:51 +04:00
/ * *
* @ private
* @ inner
* /
2014-03-21 22:45:20 +04:00
function updatePointersOver ( tracker , event , gPoints ) {
2014-03-10 22:49:51 +04:00
var delegate = THIS [ tracker . hash ] ,
2014-03-30 04:02:24 +04:00
pointsList = getGPointsListByType ( tracker , gPoints [ 0 ] . type ) ,
2014-03-10 22:49:51 +04:00
i ,
2014-03-21 22:45:20 +04:00
gPointCount = gPoints . length ,
curGPoint ,
updateGPoint ,
2014-03-10 22:49:51 +04:00
insideElementPressed ,
propagate ;
2012-02-03 04:12:45 +04:00
2014-03-30 04:02:24 +04:00
if ( pointsList ) {
for ( i = 0 ; i < gPointCount ; i ++ ) {
curGPoint = gPoints [ i ] ;
updateGPoint = pointsList . getById ( curGPoint . id ) ;
2014-03-10 22:49:51 +04:00
2014-03-30 04:02:24 +04:00
if ( updateGPoint ) {
updateGPoint . insideElement = true ;
updateGPoint . lastPos = updateGPoint . currentPos ;
updateGPoint . lastTime = updateGPoint . currentTime ;
updateGPoint . currentPos = curGPoint . currentPos ;
updateGPoint . currentTime = curGPoint . currentTime ;
insideElementPressed = updateGPoint . insideElementPressed ;
}
else {
insideElementPressed = false ;
}
2014-03-10 22:49:51 +04:00
2014-03-30 04:02:24 +04:00
// Enter
if ( tracker . enterHandler ) {
propagate = tracker . enterHandler (
{
eventSource : tracker ,
pointerType : curGPoint . type ,
2014-03-31 23:54:37 +04:00
position : getPointRelativeToAbsolute ( curGPoint . currentPos , tracker . element ) ,
2014-03-30 04:02:24 +04:00
insideElementPressed : insideElementPressed ,
buttonDownAny : IS _BUTTON _DOWN ,
isTouchEvent : curGPoint . type === 'touch' ,
originalEvent : event ,
preventDefaultAction : false ,
userData : tracker . userData
}
) ;
if ( propagate === false ) {
$ . cancelEvent ( event ) ;
2014-03-10 22:49:51 +04:00
}
2013-09-06 04:20:17 +04:00
}
2011-12-06 07:50:25 +04:00
}
2012-02-02 01:56:04 +04:00
}
2013-01-29 21:32:58 +04:00
}
2011-12-06 07:50:25 +04:00
2012-02-10 07:16:09 +04:00
/ * *
2013-09-06 21:43:39 +04:00
* @ private
* @ inner
* /
2014-03-21 22:45:20 +04:00
function updatePointersOut ( tracker , event , gPoints ) {
2014-03-10 22:49:51 +04:00
var delegate = THIS [ tracker . hash ] ,
2014-03-30 04:02:24 +04:00
pointsList = getGPointsListByType ( tracker , gPoints [ 0 ] . type ) ,
2014-03-10 22:49:51 +04:00
i ,
2014-03-21 22:45:20 +04:00
gPointCount = gPoints . length ,
curGPoint ,
updateGPoint ,
2014-03-10 22:49:51 +04:00
insideElementPressed ,
propagate ;
2012-02-10 07:16:09 +04:00
2014-03-30 04:02:24 +04:00
if ( pointsList ) {
for ( i = 0 ; i < gPointCount ; i ++ ) {
curGPoint = gPoints [ i ] ;
updateGPoint = pointsList . getById ( curGPoint . id ) ;
2013-08-16 21:09:49 +04:00
2014-03-30 04:02:24 +04:00
if ( updateGPoint ) {
updateGPoint . insideElement = false ;
updateGPoint . lastPos = updateGPoint . currentPos ;
updateGPoint . lastTime = updateGPoint . currentTime ;
updateGPoint . currentPos = curGPoint . currentPos ;
updateGPoint . currentTime = curGPoint . currentTime ;
insideElementPressed = updateGPoint . insideElementPressed ;
}
else {
insideElementPressed = false ;
}
2014-03-10 22:49:51 +04:00
2014-03-30 04:02:24 +04:00
// Exit
if ( tracker . exitHandler ) {
propagate = tracker . exitHandler (
{
eventSource : tracker ,
pointerType : curGPoint . type ,
2014-03-31 23:54:37 +04:00
position : getPointRelativeToAbsolute ( curGPoint . currentPos , tracker . element ) ,
2014-03-30 04:02:24 +04:00
insideElementPressed : insideElementPressed ,
buttonDownAny : IS _BUTTON _DOWN ,
isTouchEvent : curGPoint . type === 'touch' ,
originalEvent : event ,
preventDefaultAction : false ,
userData : tracker . userData
}
) ;
2014-03-10 22:49:51 +04:00
2014-03-30 04:02:24 +04:00
if ( propagate === false ) {
$ . cancelEvent ( event ) ;
}
2014-03-10 22:49:51 +04:00
}
2012-02-10 07:16:09 +04:00
}
}
2013-01-29 21:32:58 +04:00
}
2012-02-10 07:16:09 +04:00
2014-03-10 22:49:51 +04:00
2012-02-03 04:12:45 +04:00
/ * *
2013-09-06 21:43:39 +04:00
* @ private
* @ inner
* /
2014-03-21 22:45:20 +04:00
function updatePointers ( tracker , event , gPoints ) {
2014-03-10 22:49:51 +04:00
// Pointer(s) changed coordinates, button state, pressure, tilt, or contact geometry (e.g. width and height)
var delegate = THIS [ tracker . hash ] ,
2014-03-30 04:02:24 +04:00
pointsList = getGPointsListByType ( tracker , gPoints [ 0 ] . type ) ,
pointsListLength ,
2014-03-10 22:49:51 +04:00
i ,
2014-03-21 22:45:20 +04:00
gPointCount = gPoints . length ,
curGPoint ,
updateGPoint ,
2014-03-30 04:02:24 +04:00
gPointArray ,
2014-03-10 22:49:51 +04:00
delta ,
2014-03-15 01:15:09 +04:00
propagate ;
2014-03-10 22:49:51 +04:00
2014-03-30 04:02:24 +04:00
if ( pointsList ) {
pointsListLength = pointsList . getLength ( ) ;
for ( i = 0 ; i < gPointCount ; i ++ ) {
curGPoint = gPoints [ i ] ;
updateGPoint = pointsList . getById ( curGPoint . id ) ;
if ( updateGPoint ) {
updateGPoint . lastPos = updateGPoint . currentPos ;
updateGPoint . lastTime = updateGPoint . currentTime ;
updateGPoint . currentPos = curGPoint . currentPos ;
updateGPoint . currentTime = curGPoint . currentTime ;
}
2014-04-01 20:32:04 +04:00
}
2012-02-03 04:12:45 +04:00
2014-04-01 20:32:04 +04:00
// Stop (mouse only)
if ( gPoints [ 0 ] . type === 'mouse' && tracker . stopHandler ) {
clearTimeout ( tracker . stopTimeOut ) ;
tracker . stopTimeOut = setTimeout ( function ( ) {
handlePointerStop ( tracker , event , gPoints [ 0 ] . type ) ;
} , tracker . stopDelay ) ;
2014-03-30 04:02:24 +04:00
}
2014-03-10 22:49:51 +04:00
2014-03-31 23:54:37 +04:00
if ( pointsListLength === 0 ) {
2014-04-01 20:32:04 +04:00
// Move (no contacts, mouse or other hover-capable device)
2014-03-31 23:54:37 +04:00
if ( tracker . moveHandler ) {
propagate = tracker . moveHandler (
{
eventSource : tracker ,
2014-04-01 20:32:04 +04:00
pointerType : gPoints [ 0 ] . type ,
position : getPointRelativeToAbsolute ( gPoints [ 0 ] . currentPos , tracker . element ) ,
isTouchEvent : gPoints [ 0 ] . type === 'touch' ,
2014-03-31 23:54:37 +04:00
originalEvent : event ,
preventDefaultAction : false ,
userData : tracker . userData
}
) ;
if ( propagate === false ) {
$ . cancelEvent ( event ) ;
}
}
}
else if ( pointsListLength === 1 ) {
2014-03-30 04:02:24 +04:00
// Move (1 contact)
if ( tracker . moveHandler ) {
updateGPoint = pointsList . asArray ( ) [ 0 ] ;
propagate = tracker . moveHandler (
{
eventSource : tracker ,
pointerType : updateGPoint . type ,
2014-03-31 23:54:37 +04:00
position : getPointRelativeToAbsolute ( updateGPoint . currentPos , tracker . element ) ,
2014-03-30 04:02:24 +04:00
isTouchEvent : updateGPoint . type === 'touch' ,
originalEvent : event ,
preventDefaultAction : false ,
userData : tracker . userData
}
) ;
if ( propagate === false ) {
$ . cancelEvent ( event ) ;
}
}
2014-03-10 22:49:51 +04:00
2014-03-30 04:02:24 +04:00
// Drag
if ( tracker . dragHandler ) {
updateGPoint = pointsList . asArray ( ) [ 0 ] ;
2014-03-21 22:45:20 +04:00
delta = updateGPoint . currentPos . minus ( updateGPoint . lastPos ) ;
2014-03-10 22:49:51 +04:00
propagate = tracker . dragHandler (
{
eventSource : tracker ,
2014-03-30 04:02:24 +04:00
pointerType : updateGPoint . type ,
2014-03-31 23:54:37 +04:00
position : getPointRelativeToAbsolute ( updateGPoint . currentPos , tracker . element ) ,
2014-03-10 22:49:51 +04:00
delta : delta ,
2014-03-30 04:02:24 +04:00
speed : updateGPoint . speed ,
direction : updateGPoint . direction ,
2014-03-10 22:49:51 +04:00
shift : event . shiftKey ,
2014-03-30 04:02:24 +04:00
isTouchEvent : updateGPoint . type === 'touch' ,
2014-03-10 22:49:51 +04:00
originalEvent : event ,
preventDefaultAction : false ,
userData : tracker . userData
}
) ;
if ( propagate === false ) {
$ . cancelEvent ( event ) ;
}
}
}
2014-03-31 23:54:37 +04:00
else if ( pointsListLength === 2 ) {
2014-03-30 04:02:24 +04:00
// Move (2 contacts, use center)
if ( tracker . moveHandler ) {
gPointArray = pointsList . asArray ( ) ;
propagate = tracker . moveHandler (
{
eventSource : tracker ,
pointerType : gPointArray [ 0 ] . type ,
2014-03-31 23:54:37 +04:00
position : getPointRelativeToAbsolute ( getCenterPoint ( gPointArray [ 0 ] . currentPos , gPointArray [ 1 ] . currentPos ) , tracker . element ) ,
2014-03-30 04:02:24 +04:00
isTouchEvent : gPointArray [ 0 ] . type === 'touch' ,
originalEvent : event ,
preventDefaultAction : false ,
userData : tracker . userData
}
) ;
if ( propagate === false ) {
$ . cancelEvent ( event ) ;
2014-03-10 22:49:51 +04:00
}
}
2014-03-30 04:02:24 +04:00
// Pinch
if ( tracker . pinchHandler && gPoints [ 0 ] . type === 'touch' ) {
delta = delegate . pinchGPoints [ 0 ] . currentPos . distanceTo ( delegate . pinchGPoints [ 1 ] . currentPos ) ;
if ( delta != delegate . currentPinchDist ) {
delegate . lastPinchDist = delegate . currentPinchDist ;
delegate . currentPinchDist = delta ;
delegate . lastPinchCenter = delegate . currentPinchCenter ;
delegate . currentPinchCenter = getCenterPoint ( delegate . pinchGPoints [ 0 ] . currentPos , delegate . pinchGPoints [ 1 ] . currentPos ) ;
propagate = tracker . pinchHandler (
{
eventSource : tracker ,
pointerType : 'touch' ,
gesturePoints : delegate . pinchGPoints ,
2014-03-31 23:54:37 +04:00
lastCenter : getPointRelativeToAbsolute ( delegate . lastPinchCenter , tracker . element ) ,
center : getPointRelativeToAbsolute ( delegate . currentPinchCenter , tracker . element ) ,
2014-03-30 04:02:24 +04:00
lastDistance : delegate . lastPinchDist ,
distance : delegate . currentPinchDist ,
shift : event . shiftKey ,
originalEvent : event ,
preventDefaultAction : false ,
userData : tracker . userData
}
) ;
if ( propagate === false ) {
$ . cancelEvent ( event ) ;
}
2014-03-10 22:49:51 +04:00
}
}
}
}
2013-01-29 21:32:58 +04:00
}
2011-12-06 07:50:25 +04:00
2014-03-10 22:49:51 +04:00
2012-02-01 06:01:37 +04:00
/ * *
2013-09-06 21:43:39 +04:00
* @ private
* @ inner
* /
2014-03-21 22:45:20 +04:00
function removePointers ( tracker , event , gPoints ) {
2014-03-10 22:49:51 +04:00
var delegate = THIS [ tracker . hash ] ,
2014-03-30 04:02:24 +04:00
pointsList = getGPointsListByType ( tracker , gPoints [ 0 ] . type ) ,
pointsListLength ,
2014-03-10 22:49:51 +04:00
propagate ,
insideElementPressed ,
insideElementReleased ,
releasePoint ,
2014-03-30 04:02:24 +04:00
releaseTime ,
2014-03-10 22:49:51 +04:00
i ,
2014-03-21 22:45:20 +04:00
gPointCount = gPoints . length ,
curGPoint ,
2014-03-30 04:02:24 +04:00
updateGPoint ,
removedGPoint ;
2014-03-10 22:49:51 +04:00
2014-03-30 04:02:24 +04:00
if ( pointsList ) {
for ( i = 0 ; i < gPointCount ; i ++ ) {
curGPoint = gPoints [ i ] ;
2014-03-10 22:49:51 +04:00
2014-03-30 04:02:24 +04:00
removedGPoint = pointsList . getById ( curGPoint . id ) ;
2014-03-10 22:49:51 +04:00
2014-03-30 04:02:24 +04:00
if ( removedGPoint ) {
releasePoint = removedGPoint . currentPos ;
releaseTime = removedGPoint . currentTime ;
if ( tracker . dragHandler || tracker . dragEndHandler || tracker . pinchHandler ) {
$ . MouseTracker . gesturePointVelocityTracker . removePoint ( tracker , removedGPoint ) ;
2014-03-10 22:49:51 +04:00
}
2014-03-30 04:02:24 +04:00
pointsListLength = pointsList . removeById ( curGPoint . id ) ;
if ( pointsListLength === 0 ) {
insideElementPressed = removedGPoint . insideElementPressed ;
2014-03-31 23:54:37 +04:00
insideElementReleased = removedGPoint . insideElement || $ . pointInElement ( tracker . element , releasePoint ) ;
2014-03-30 04:02:24 +04:00
// Release
if ( tracker . releaseHandler ) {
propagate = tracker . releaseHandler (
{
eventSource : tracker ,
pointerType : removedGPoint . type ,
2014-03-31 23:54:37 +04:00
position : getPointRelativeToAbsolute ( releasePoint , tracker . element ) ,
2014-03-30 04:02:24 +04:00
insideElementPressed : insideElementPressed ,
insideElementReleased : insideElementReleased ,
isTouchEvent : removedGPoint . type === 'touch' ,
originalEvent : event ,
preventDefaultAction : false ,
userData : tracker . userData
}
) ;
if ( propagate === false ) {
$ . cancelEvent ( event ) ;
}
}
2014-03-10 22:49:51 +04:00
2014-03-30 04:02:24 +04:00
// Drag End
if ( tracker . dragEndHandler ) {
propagate = tracker . dragEndHandler (
{
eventSource : tracker ,
pointerType : removedGPoint . type ,
2014-03-31 23:54:37 +04:00
position : getPointRelativeToAbsolute ( removedGPoint . currentPos , tracker . element ) ,
2014-03-30 04:02:24 +04:00
speed : removedGPoint . speed ,
direction : removedGPoint . direction ,
shift : event . shiftKey ,
isTouchEvent : removedGPoint . type === 'touch' ,
originalEvent : event ,
preventDefaultAction : false ,
userData : tracker . userData
}
) ;
if ( propagate === false ) {
$ . cancelEvent ( event ) ;
}
}
// Click
if ( tracker . clickHandler && insideElementPressed && insideElementReleased ) {
var time = releaseTime - removedGPoint . startTime ,
distance = removedGPoint . startPos . distanceTo ( releasePoint ) ,
quick = time <= tracker . clickTimeThreshold &&
distance <= tracker . clickDistThreshold ;
propagate = tracker . clickHandler (
{
eventSource : tracker ,
pointerType : curGPoint . type ,
2014-03-31 23:54:37 +04:00
position : getPointRelativeToAbsolute ( curGPoint . currentPos , tracker . element ) ,
2014-03-30 04:02:24 +04:00
quick : quick ,
shift : event . shiftKey ,
isTouchEvent : curGPoint . type === 'touch' ,
originalEvent : event ,
preventDefaultAction : false ,
userData : tracker . userData
}
) ;
if ( propagate === false ) {
$ . cancelEvent ( event ) ;
}
}
}
//else if ( pointsListLength === 1 ) {
//}
else if ( pointsListLength === 2 ) {
if ( tracker . pinchHandler && curGPoint . type === 'touch' ) {
// Reset for pinch
delegate . pinchGPoints = pointsList . asArray ( ) ;
delegate . lastPinchDist = delegate . currentPinchDist = delegate . pinchGPoints [ 0 ] . currentPos . distanceTo ( delegate . pinchGPoints [ 1 ] . currentPos ) ;
delegate . lastPinchCenter = delegate . currentPinchCenter = getCenterPoint ( delegate . pinchGPoints [ 0 ] . currentPos , delegate . pinchGPoints [ 1 ] . currentPos ) ;
2014-03-10 22:49:51 +04:00
}
}
}
}
}
2013-01-29 21:32:58 +04:00
}
2011-12-06 07:50:25 +04:00
2014-03-10 22:49:51 +04:00
2012-02-01 06:01:37 +04:00
/ * *
2013-09-06 21:43:39 +04:00
* @ private
* @ inner
* /
2014-03-21 22:45:20 +04:00
function cancelPointers ( tracker , event , gPoints ) {
2014-03-30 04:02:24 +04:00
removePointers ( tracker , event , gPoints ) ;
2013-01-29 21:32:58 +04:00
}
2011-12-06 07:50:25 +04:00
2014-03-10 22:49:51 +04:00
///**
2014-04-01 20:32:04 +04:00
// * @private
// * @inner
// * Returns true if elementB is a child node of elementA, or if they're equal.
// */
//function isChild( elementA, elementB ) {
// var body = document.body;
// while ( elementB && elementA != elementB && body != elementB ) {
// try {
// elementB = elementB.parentNode;
// } catch ( e ) {
// return false;
2014-03-10 22:49:51 +04:00
// }
// }
2014-04-01 20:32:04 +04:00
// return elementA == elementB;
2014-03-10 22:49:51 +04:00
//}
2012-02-01 06:01:37 +04:00
/ * *
2013-09-06 21:43:39 +04:00
* @ private
* @ inner
* /
2011-12-14 05:04:38 +04:00
function onGlobalMouseDown ( ) {
2012-02-03 04:12:45 +04:00
IS _BUTTON _DOWN = true ;
2013-01-29 21:32:58 +04:00
}
2011-12-14 05:04:38 +04:00
2012-02-01 06:01:37 +04:00
/ * *
2013-09-06 21:43:39 +04:00
* @ private
* @ inner
* /
2011-12-14 05:04:38 +04:00
function onGlobalMouseUp ( ) {
2012-02-03 04:12:45 +04:00
IS _BUTTON _DOWN = false ;
2013-01-29 21:32:58 +04:00
}
2011-12-06 07:50:25 +04:00
2011-12-14 05:04:38 +04:00
( function ( ) {
2012-04-11 01:02:24 +04:00
if ( $ . Browser . vendor == $ . BROWSERS . IE && $ . Browser . version < 9 ) {
2012-02-02 01:56:04 +04:00
$ . addEvent ( document , "mousedown" , onGlobalMouseDown , false ) ;
$ . addEvent ( document , "mouseup" , onGlobalMouseUp , false ) ;
2011-12-14 05:04:38 +04:00
} else {
2012-02-02 01:56:04 +04:00
$ . addEvent ( window , "mousedown" , onGlobalMouseDown , true ) ;
$ . addEvent ( window , "mouseup" , onGlobalMouseUp , true ) ;
2011-12-14 05:04:38 +04:00
}
2013-09-06 04:20:17 +04:00
} ) ( ) ;
2013-06-19 21:33:25 +04:00
2013-09-06 04:20:17 +04:00
} ( OpenSeadragon ) ) ;