2011-12-05 22:50:25 -05:00
|
|
|
|
|
|
|
(function( $ ){
|
|
|
|
|
2011-12-13 20:04:38 -05:00
|
|
|
//Ensures we dont break existing instances of mousetracker if we are dumb
|
|
|
|
//enough to load openseadragon.js onto the page twice. I don't know how
|
|
|
|
//useful this pattern is, but if we decide to use it we should use it
|
|
|
|
//everywhere
|
2012-02-01 16:56:04 -05:00
|
|
|
if ( $.MouseTracker ) {
|
2011-12-05 22:50:25 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-01 16:56:04 -05:00
|
|
|
var buttonDownAny = false,
|
2011-12-13 20:04:38 -05:00
|
|
|
ieCapturingAny = false,
|
|
|
|
ieTrackersActive = {}, // dictionary from hash to MouseTracker
|
|
|
|
ieTrackersCapturing = []; // list of trackers interested in capture
|
2011-12-05 22:50:25 -05:00
|
|
|
|
2012-01-25 14:14:02 -05:00
|
|
|
/**
|
|
|
|
* @class
|
|
|
|
*/
|
2012-02-01 16:56:04 -05:00
|
|
|
$.MouseTracker = function ( element, clickTimeThreshold, clickDistThreshold ) {
|
2011-12-05 22:50:25 -05:00
|
|
|
//Start Thatcher - TODO: remove local function definitions in favor of
|
2011-12-20 07:39:02 -05:00
|
|
|
// - a global closure for MouseTracker so the number
|
2011-12-05 22:50:25 -05:00
|
|
|
// - of Viewers has less memory impact. Also use
|
|
|
|
// - prototype pattern instead of Singleton pattern.
|
|
|
|
//End Thatcher
|
|
|
|
|
2012-02-01 16:56:04 -05:00
|
|
|
this.hash = Math.random(); // a unique hash for this tracker
|
|
|
|
this.element = $.getElement( element );
|
2011-12-05 22:50:25 -05:00
|
|
|
|
2012-02-01 16:56:04 -05:00
|
|
|
this.tracking = false;
|
|
|
|
this.capturing = false;
|
|
|
|
this.buttonDownElement = false;
|
|
|
|
this.insideElement = false;
|
2011-12-05 22:50:25 -05:00
|
|
|
|
2012-02-01 16:56:04 -05:00
|
|
|
this.lastPoint = null; // position of last mouse down/move
|
|
|
|
this.lastMouseDownTime = null; // time of last mouse down
|
|
|
|
this.lastMouseDownPoint = null; // position of last mouse down
|
|
|
|
this.clickTimeThreshold = clickTimeThreshold;
|
|
|
|
this.clickDistThreshold = clickDistThreshold;
|
2011-12-05 22:50:25 -05:00
|
|
|
|
|
|
|
|
2012-02-01 16:56:04 -05:00
|
|
|
this.target = element;
|
|
|
|
this.enterHandler = null; // function(tracker, position, buttonDownElement, buttonDownAny)
|
|
|
|
this.exitHandler = null; // function(tracker, position, buttonDownElement, buttonDownAny)
|
2011-12-13 20:04:38 -05:00
|
|
|
this.pressHandler = null; // function(tracker, position)
|
2012-02-01 16:56:04 -05:00
|
|
|
this.releaseHandler = null; // function(tracker, position, insideElementPress, insideElementRelease)
|
2011-12-13 20:04:38 -05:00
|
|
|
this.scrollHandler = null; // function(tracker, position, scroll, shift)
|
|
|
|
this.clickHandler = null; // function(tracker, position, quick, shift)
|
|
|
|
this.dragHandler = null; // function(tracker, position, delta, shift)
|
2011-12-05 22:50:25 -05:00
|
|
|
|
2012-02-01 16:56:04 -05:00
|
|
|
this.delegates = {
|
|
|
|
"mouseover": $.delegate(this, this.onMouseOver),
|
|
|
|
"mouseout": $.delegate(this, this.onMouseOut),
|
|
|
|
"mousedown": $.delegate(this, this.onMouseDown),
|
|
|
|
"mouseup": $.delegate(this, this.onMouseUp),
|
|
|
|
"click": $.delegate(this, this.onMouseClick),
|
|
|
|
"DOMMouseScroll": $.delegate(this, this.onMouseWheelSpin),
|
|
|
|
"mousewheel": $.delegate(this, this.onMouseWheelSpin),
|
|
|
|
"mouseupie": $.delegate(this, this.onMouseUpIE),
|
|
|
|
"mousemoveie": $.delegate(this, this.onMouseMoveIE),
|
|
|
|
"mouseupwindow": $.delegate(this, this.onMouseUpWindow),
|
|
|
|
"mousemove": $.delegate(this, this.onMouseMove)
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
2011-12-05 22:50:25 -05:00
|
|
|
|
2012-02-01 16:56:04 -05:00
|
|
|
$.MouseTracker.prototype = {
|
2011-12-05 22:50:25 -05:00
|
|
|
|
2011-12-13 20:04:38 -05:00
|
|
|
|
2012-02-01 16:56:04 -05:00
|
|
|
/**
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
isTracking: function () {
|
|
|
|
return this.tracking;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
setTracking: function ( track ) {
|
|
|
|
if ( track ) {
|
|
|
|
this.startTracking();
|
2011-12-13 20:04:38 -05:00
|
|
|
} else {
|
2012-02-01 16:56:04 -05:00
|
|
|
this.stopTracking();
|
2011-12-13 20:04:38 -05:00
|
|
|
}
|
2012-02-01 16:56:04 -05:00
|
|
|
},
|
2011-12-13 20:04:38 -05:00
|
|
|
|
2012-02-01 16:56:04 -05:00
|
|
|
/**
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
startTracking: function() {
|
|
|
|
if ( !this.tracking ) {
|
|
|
|
$.addEvent( this.element, "mouseover", this.delegates["mouseover"], false);
|
|
|
|
$.addEvent( this.element, "mouseout", this.delegates["mouseout"], false);
|
|
|
|
$.addEvent( this.element, "mousedown", this.delegates["mousedown"], false);
|
|
|
|
$.addEvent( this.element, "mouseup", this.delegates["mouseup"], false);
|
|
|
|
$.addEvent( this.element, "click", this.delegates["click"], false);
|
|
|
|
$.addEvent( this.element, "DOMMouseScroll", this.delegates["DOMMouseScroll"], false);
|
|
|
|
$.addEvent( this.element, "mousewheel", this.delegates["mousewheel"], false); // Firefox
|
2011-12-05 22:50:25 -05:00
|
|
|
|
2012-02-01 16:56:04 -05:00
|
|
|
this.tracking = true;
|
|
|
|
ieTrackersActive[ this.hash ] = this;
|
2011-12-05 22:50:25 -05:00
|
|
|
}
|
2012-02-01 16:56:04 -05:00
|
|
|
},
|
2011-12-05 22:50:25 -05:00
|
|
|
|
2012-02-01 16:56:04 -05:00
|
|
|
/**
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
stopTracking: function() {
|
|
|
|
if ( this.tracking ) {
|
|
|
|
$.removeEvent( this.element, "mouseover", this.delegates["mouseover"], false);
|
|
|
|
$.removeEvent( this.element, "mouseout", this.delegates["mouseout"], false);
|
|
|
|
$.removeEvent( this.element, "mousedown", this.delegates["mousedown"], false);
|
|
|
|
$.removeEvent( this.element, "mouseup", this.delegates["mouseup"], false);
|
|
|
|
$.removeEvent( this.element, "click", this.delegates["click"], false);
|
|
|
|
$.removeEvent( this.element, "DOMMouseScroll", this.delegates["DOMMouseScroll"], false);
|
|
|
|
$.removeEvent( this.element, "mousewheel", this.delegates["mousewheel"], false);
|
|
|
|
|
|
|
|
this.releaseMouse();
|
|
|
|
this.tracking = false;
|
|
|
|
delete ieTrackersActive[ this.hash ];
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
captureMouse: function() {
|
|
|
|
if ( !this.capturing ) {
|
|
|
|
if ( $.Browser.vendor == $.BROWSERS.IE ) {
|
|
|
|
$.removeEvent( this.element, "mouseup", this.delegates["mouseup"], false );
|
|
|
|
$.addEvent( this.element, "mouseup", this.delegates["mouseupie"], true );
|
|
|
|
$.addEvent( this.element, "mousemove", this.delegates["mousemoveie"], true );
|
2011-12-05 22:50:25 -05:00
|
|
|
} else {
|
2012-02-01 16:56:04 -05:00
|
|
|
$.addEvent( window, "mouseup", this.delegates["mouseupwindow"], true );
|
|
|
|
$.addEvent( window, "mousemove", this.delegates["mousemove"], true );
|
2011-12-05 22:50:25 -05:00
|
|
|
}
|
|
|
|
|
2012-02-01 16:56:04 -05:00
|
|
|
this.capturing = true;
|
2011-12-05 22:50:25 -05:00
|
|
|
}
|
2012-02-01 16:56:04 -05:00
|
|
|
},
|
2011-12-05 22:50:25 -05:00
|
|
|
|
2012-02-01 16:56:04 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
releaseMouse: function() {
|
|
|
|
if ( this.capturing ) {
|
|
|
|
if ( $.Browser.vendor == $.BROWSERS.IE ) {
|
|
|
|
$.removeEvent( this.element, "mousemove", this.delegates["mousemoveie"], true );
|
|
|
|
$.removeEvent( this.element, "mouseup", this.delegates["mouseupie"], true );
|
|
|
|
$.addEvent( this.element, "mouseup", this.delegates["mouseup"], false );
|
2011-12-05 22:50:25 -05:00
|
|
|
} else {
|
2012-02-01 16:56:04 -05:00
|
|
|
$.removeEvent( window, "mousemove", this.delegates["mousemove"], true );
|
|
|
|
$.removeEvent( window, "mouseup", this.delegates["mouseupwindow"], true );
|
2011-12-05 22:50:25 -05:00
|
|
|
}
|
|
|
|
|
2012-02-01 16:56:04 -05:00
|
|
|
this.capturing = false;
|
2011-12-05 22:50:25 -05:00
|
|
|
}
|
2012-02-01 16:56:04 -05:00
|
|
|
},
|
2011-12-05 22:50:25 -05:00
|
|
|
|
|
|
|
|
2012-02-01 16:56:04 -05:00
|
|
|
/**
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
triggerOthers: function( eventName, event ) {
|
|
|
|
var trackers = ieTrackersActive,
|
|
|
|
otherHash;
|
|
|
|
for ( otherHash in trackers ) {
|
|
|
|
if ( trackers.hasOwnProperty( otherHash ) && this.hash != otherHash ) {
|
|
|
|
trackers[ otherHash ][ eventName ]( event );
|
2011-12-05 22:50:25 -05:00
|
|
|
}
|
|
|
|
}
|
2012-02-01 16:56:04 -05:00
|
|
|
},
|
2011-12-05 22:50:25 -05:00
|
|
|
|
2012-02-01 16:56:04 -05:00
|
|
|
/**
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
hasMouse: function() {
|
|
|
|
return this.insideElement;
|
|
|
|
},
|
2011-12-05 22:50:25 -05:00
|
|
|
|
|
|
|
|
2012-02-01 16:56:04 -05:00
|
|
|
/**
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
onMouseOver: function( event ) {
|
|
|
|
var event = $.getEvent( event );
|
2011-12-05 22:50:25 -05:00
|
|
|
|
2012-02-01 16:56:04 -05:00
|
|
|
if ( $.Browser.vendor == $.BROWSERS.IE &&
|
|
|
|
this.capturing &&
|
|
|
|
!isChild( event.srcElement, this.element ) ) {
|
|
|
|
this.triggerOthers( "onMouseOver", event );
|
2011-12-05 22:50:25 -05:00
|
|
|
}
|
|
|
|
|
2012-02-01 16:56:04 -05:00
|
|
|
var to = event.target ?
|
|
|
|
event.target :
|
|
|
|
event.srcElement,
|
|
|
|
from = event.relatedTarget ?
|
|
|
|
event.relatedTarget :
|
|
|
|
event.fromElement;
|
|
|
|
|
|
|
|
if ( !isChild( this.element, to ) || isChild( this.element, from ) ) {
|
2011-12-05 22:50:25 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-01 16:56:04 -05:00
|
|
|
this.insideElement = true;
|
2011-12-05 22:50:25 -05:00
|
|
|
|
2012-02-01 16:56:04 -05:00
|
|
|
if ( typeof( this.enterHandler ) == "function") {
|
2011-12-05 22:50:25 -05:00
|
|
|
try {
|
2012-02-01 16:56:04 -05:00
|
|
|
this.enterHandler(
|
|
|
|
this,
|
|
|
|
getMouseRelative( event, this.element ),
|
|
|
|
this.buttonDownElement,
|
|
|
|
buttonDownAny
|
|
|
|
);
|
|
|
|
} catch ( e ) {
|
|
|
|
$.console.error(
|
|
|
|
e.name + " while executing enter handler: " + e.message,
|
|
|
|
e
|
|
|
|
);
|
2011-12-05 22:50:25 -05:00
|
|
|
}
|
|
|
|
}
|
2012-02-01 16:56:04 -05:00
|
|
|
},
|
2011-12-05 22:50:25 -05:00
|
|
|
|
2012-02-01 16:56:04 -05:00
|
|
|
/**
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
onMouseOut: function( event ) {
|
|
|
|
var event = $.getEvent( event );
|
2011-12-05 22:50:25 -05:00
|
|
|
|
2012-02-01 16:56:04 -05:00
|
|
|
if ( $.Browser.vendor == $.BROWSERS.IE &&
|
|
|
|
this.capturing &&
|
|
|
|
!isChild( event.srcElement, this.element ) ) {
|
|
|
|
this.triggerOthers( "onMouseOut", event );
|
2011-12-05 22:50:25 -05:00
|
|
|
}
|
|
|
|
|
2012-02-01 16:56:04 -05:00
|
|
|
var from = event.target ?
|
|
|
|
event.target :
|
|
|
|
event.srcElement,
|
|
|
|
to = event.relatedTarget ?
|
|
|
|
event.relatedTarget :
|
|
|
|
event.toElement;
|
|
|
|
|
|
|
|
if ( !isChild( this.element, from ) || isChild( this.element, to ) ) {
|
2011-12-05 22:50:25 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-01 16:56:04 -05:00
|
|
|
this.insideElement = false;
|
2011-12-05 22:50:25 -05:00
|
|
|
|
2012-02-01 16:56:04 -05:00
|
|
|
if ( typeof( this.exitHandler ) == "function" ) {
|
2011-12-05 22:50:25 -05:00
|
|
|
try {
|
2012-02-01 16:56:04 -05:00
|
|
|
this.exitHandler(
|
|
|
|
this,
|
|
|
|
getMouseRelative( event, this.element ),
|
|
|
|
this.buttonDownElement,
|
|
|
|
buttonDownAny
|
|
|
|
);
|
|
|
|
} catch ( e ) {
|
|
|
|
$.console.error(
|
|
|
|
e.name + " while executing exit handler: " + e.message,
|
|
|
|
e
|
|
|
|
);
|
2011-12-05 22:50:25 -05:00
|
|
|
}
|
|
|
|
}
|
2012-02-01 16:56:04 -05:00
|
|
|
},
|
2011-12-05 22:50:25 -05:00
|
|
|
|
2012-02-01 16:56:04 -05:00
|
|
|
/**
|
|
|
|
* @method
|
|
|
|
* @inner
|
|
|
|
*/
|
|
|
|
onMouseDown: function( event ) {
|
|
|
|
var event = $.getEvent( event );
|
2011-12-05 22:50:25 -05:00
|
|
|
|
2012-02-01 16:56:04 -05:00
|
|
|
if ( event.button == 2 ) {
|
2011-12-05 22:50:25 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-01 16:56:04 -05:00
|
|
|
this.buttonDownElement = true;
|
2011-12-05 22:50:25 -05:00
|
|
|
|
2012-02-01 16:56:04 -05:00
|
|
|
this.lastPoint = getMouseAbsolute( event );
|
|
|
|
this.lastMouseDownPoint = this.lastPoint;
|
|
|
|
this.lastMouseDownTime = new Date().getTime();
|
2011-12-05 22:50:25 -05:00
|
|
|
|
2012-02-01 16:56:04 -05:00
|
|
|
if ( typeof( this.pressHandler ) == "function" ) {
|
2011-12-05 22:50:25 -05:00
|
|
|
try {
|
2012-02-01 16:56:04 -05:00
|
|
|
this.pressHandler(
|
|
|
|
this,
|
|
|
|
getMouseRelative( event, this.element )
|
|
|
|
);
|
2011-12-05 22:50:25 -05:00
|
|
|
} catch (e) {
|
2012-02-01 16:56:04 -05:00
|
|
|
$.console.error(
|
|
|
|
e.name + " while executing press handler: " + e.message,
|
|
|
|
e
|
|
|
|
);
|
2011-12-05 22:50:25 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-01 16:56:04 -05:00
|
|
|
if ( this.pressHandler || this.dragHandler ) {
|
|
|
|
$.cancelEvent( event );
|
2011-12-05 22:50:25 -05:00
|
|
|
}
|
|
|
|
|
2012-02-01 16:56:04 -05:00
|
|
|
if ( !( $.Browser.vendor == $.BROWSERS.IE ) || !ieCapturingAny ) {
|
|
|
|
this.captureMouse();
|
2011-12-05 22:50:25 -05:00
|
|
|
ieCapturingAny = true;
|
2012-02-01 16:56:04 -05:00
|
|
|
ieTrackersCapturing = [ this ]; // reset to empty & add us
|
|
|
|
} else if ( $.Browser.vendor == $.BROWSERS.IE ) {
|
|
|
|
ieTrackersCapturing.push( this ); // add us to the list
|
2011-12-05 22:50:25 -05:00
|
|
|
}
|
2012-02-01 16:56:04 -05:00
|
|
|
},
|
2011-12-05 22:50:25 -05:00
|
|
|
|
2012-02-01 16:56:04 -05:00
|
|
|
/**
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
onMouseUp: function( event ) {
|
|
|
|
var event = $.getEvent( event ),
|
|
|
|
insideElementPress = this.buttonDownElement,
|
|
|
|
insideElementRelease = this.insideElement;
|
2011-12-05 22:50:25 -05:00
|
|
|
|
2012-02-01 16:56:04 -05:00
|
|
|
if ( event.button == 2 ) {
|
2011-12-05 22:50:25 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-01 16:56:04 -05:00
|
|
|
this.buttonDownElement = false;
|
2011-12-05 22:50:25 -05:00
|
|
|
|
2012-02-01 16:56:04 -05:00
|
|
|
if ( typeof( this.releaseHandler ) == "function" ) {
|
2011-12-05 22:50:25 -05:00
|
|
|
try {
|
2012-02-01 16:56:04 -05:00
|
|
|
this.releaseHandler(
|
|
|
|
this,
|
|
|
|
getMouseRelative( event, this.element ),
|
|
|
|
insideElementPress,
|
|
|
|
insideElementRelease
|
|
|
|
);
|
2011-12-05 22:50:25 -05:00
|
|
|
} catch (e) {
|
2012-02-01 16:56:04 -05:00
|
|
|
$.console.error(
|
|
|
|
e.name + " while executing release handler: " + e.message,
|
|
|
|
e
|
|
|
|
);
|
2011-12-05 22:50:25 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-01 16:56:04 -05:00
|
|
|
if ( insideElementPress && insideElementRelease ) {
|
|
|
|
this.handleMouseClick( event );
|
2011-12-05 22:50:25 -05:00
|
|
|
}
|
2012-02-01 16:56:04 -05:00
|
|
|
},
|
2011-12-05 22:50:25 -05:00
|
|
|
|
|
|
|
/**
|
2012-02-01 16:56:04 -05:00
|
|
|
* @method
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
onMouseUpIE: function( event ) {
|
|
|
|
var event = $.getEvent( event ),
|
|
|
|
tracker,
|
|
|
|
i;
|
|
|
|
|
|
|
|
if ( event.button == 2 ) {
|
2011-12-05 22:50:25 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-01 16:56:04 -05:00
|
|
|
for ( i = 0; i < ieTrackersCapturing.length; i++ ) {
|
|
|
|
tracker = ieTrackersCapturing[ i ];
|
|
|
|
if ( !tracker.hasMouse() ) {
|
|
|
|
tracker.onMouseUp( event );
|
2011-12-05 22:50:25 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-01 16:56:04 -05:00
|
|
|
this.releaseMouse();
|
2011-12-05 22:50:25 -05:00
|
|
|
ieCapturingAny = false;
|
2012-02-01 16:56:04 -05:00
|
|
|
event.srcElement.fireEvent(
|
|
|
|
"on" + event.type,
|
|
|
|
document.createEventObject( event )
|
|
|
|
);
|
2011-12-05 22:50:25 -05:00
|
|
|
|
2012-02-01 16:56:04 -05:00
|
|
|
$.stopEvent( event );
|
|
|
|
},
|
2011-12-05 22:50:25 -05:00
|
|
|
|
|
|
|
/**
|
2012-02-01 16:56:04 -05:00
|
|
|
* @method
|
2012-01-31 21:01:37 -05:00
|
|
|
* 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.
|
|
|
|
*/
|
2012-02-01 16:56:04 -05:00
|
|
|
onMouseUpWindow: function( event ) {
|
|
|
|
if ( !this.insideElement ) {
|
|
|
|
this.onMouseUp( event );
|
2011-12-05 22:50:25 -05:00
|
|
|
}
|
|
|
|
|
2012-02-01 16:56:04 -05:00
|
|
|
this.releaseMouse();
|
|
|
|
},
|
2011-12-05 22:50:25 -05:00
|
|
|
|
2012-01-31 21:01:37 -05:00
|
|
|
/**
|
2012-02-01 16:56:04 -05:00
|
|
|
* @method
|
2012-01-31 21:01:37 -05:00
|
|
|
*/
|
2012-02-01 16:56:04 -05:00
|
|
|
onMouseClick: function( event ) {
|
2011-12-05 22:50:25 -05:00
|
|
|
|
2012-02-01 16:56:04 -05:00
|
|
|
if ( this.clickHandler ) {
|
|
|
|
$.cancelEvent( event );
|
2011-12-05 22:50:25 -05:00
|
|
|
}
|
2012-02-01 16:56:04 -05:00
|
|
|
},
|
2011-12-05 22:50:25 -05:00
|
|
|
|
2012-01-31 21:01:37 -05:00
|
|
|
/**
|
2012-02-01 16:56:04 -05:00
|
|
|
* @method
|
2012-01-31 21:01:37 -05:00
|
|
|
*/
|
2012-02-01 16:56:04 -05:00
|
|
|
onMouseWheelSpin: function( event ) {
|
2011-12-05 22:50:25 -05:00
|
|
|
var nDelta = 0;
|
2012-02-01 16:56:04 -05:00
|
|
|
|
|
|
|
if ( !event ) { // For IE, access the global (window) event object
|
2011-12-05 22:50:25 -05:00
|
|
|
event = window.event;
|
|
|
|
}
|
2012-02-01 16:56:04 -05:00
|
|
|
|
|
|
|
if ( event.wheelDelta ) { // IE and Opera
|
2011-12-05 22:50:25 -05:00
|
|
|
nDelta = event.wheelDelta;
|
2012-02-01 16:56:04 -05:00
|
|
|
if ( window.opera ) { // Opera has the values reversed
|
2011-12-05 22:50:25 -05:00
|
|
|
nDelta = -nDelta;
|
|
|
|
}
|
2012-02-01 16:56:04 -05:00
|
|
|
} else if (event.detail) { // Mozilla FireFox
|
2011-12-05 22:50:25 -05:00
|
|
|
nDelta = -event.detail;
|
|
|
|
}
|
|
|
|
|
|
|
|
nDelta = nDelta > 0 ? 1 : -1;
|
|
|
|
|
2012-02-01 16:56:04 -05:00
|
|
|
if ( typeof( this.scrollHandler ) == "function" ) {
|
2011-12-05 22:50:25 -05:00
|
|
|
try {
|
2012-02-01 16:56:04 -05:00
|
|
|
this.scrollHandler(
|
|
|
|
this,
|
|
|
|
getMouseRelative( event, this.element ),
|
|
|
|
nDelta,
|
|
|
|
event.shiftKey
|
|
|
|
);
|
2011-12-05 22:50:25 -05:00
|
|
|
} catch (e) {
|
2012-02-01 16:56:04 -05:00
|
|
|
$.console.error(
|
|
|
|
e.name + " while executing scroll handler: " + e.message,
|
|
|
|
e
|
|
|
|
);
|
2011-12-05 22:50:25 -05:00
|
|
|
}
|
|
|
|
|
2012-02-01 16:56:04 -05:00
|
|
|
$.cancelEvent( event );
|
2011-12-05 22:50:25 -05:00
|
|
|
}
|
2012-02-01 16:56:04 -05:00
|
|
|
},
|
2011-12-05 22:50:25 -05:00
|
|
|
|
2012-01-31 21:01:37 -05:00
|
|
|
/**
|
2012-02-01 16:56:04 -05:00
|
|
|
* @method
|
2012-01-31 21:01:37 -05:00
|
|
|
*/
|
2012-02-01 16:56:04 -05:00
|
|
|
handleMouseClick: function( event ) {
|
|
|
|
var event = $.getEvent( event );
|
2011-12-05 22:50:25 -05:00
|
|
|
|
2012-02-01 16:56:04 -05:00
|
|
|
if ( event.button == 2 ) {
|
2011-12-05 22:50:25 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-01 16:56:04 -05:00
|
|
|
var time = new Date().getTime() - this.lastMouseDownTime;
|
|
|
|
var point = getMouseAbsolute( event );
|
|
|
|
var distance = this.lastMouseDownPoint.distanceTo( point );
|
|
|
|
var quick = (
|
|
|
|
time <= this.clickTimeThreshold
|
|
|
|
) && (
|
|
|
|
distance <= this.clickDistThreshold
|
|
|
|
);
|
2011-12-05 22:50:25 -05:00
|
|
|
|
2012-02-01 16:56:04 -05:00
|
|
|
if ( typeof( this.clickHandler ) == "function" ) {
|
2011-12-05 22:50:25 -05:00
|
|
|
try {
|
2012-02-01 16:56:04 -05:00
|
|
|
this.clickHandler(
|
|
|
|
this,
|
|
|
|
getMouseRelative( event, this.element ),
|
|
|
|
quick,
|
|
|
|
event.shiftKey
|
|
|
|
);
|
|
|
|
} catch ( e ) {
|
|
|
|
$.console.error(
|
|
|
|
e.name + " while executing click handler: " + e.message,
|
|
|
|
e
|
|
|
|
);
|
2011-12-05 22:50:25 -05:00
|
|
|
}
|
|
|
|
}
|
2012-02-01 16:56:04 -05:00
|
|
|
},
|
2011-12-05 22:50:25 -05:00
|
|
|
|
2012-01-31 21:01:37 -05:00
|
|
|
/**
|
2012-02-01 16:56:04 -05:00
|
|
|
* @method
|
2012-01-31 21:01:37 -05:00
|
|
|
*/
|
2012-02-01 16:56:04 -05:00
|
|
|
onMouseMove: function( event ) {
|
|
|
|
var event = $.getEvent( event );
|
|
|
|
var point = getMouseAbsolute( event );
|
|
|
|
var delta = point.minus( this.lastPoint );
|
2011-12-05 22:50:25 -05:00
|
|
|
|
2012-02-01 16:56:04 -05:00
|
|
|
this.lastPoint = point;
|
2011-12-05 22:50:25 -05:00
|
|
|
|
2012-02-01 16:56:04 -05:00
|
|
|
if ( typeof( this.dragHandler ) == "function" ) {
|
2011-12-05 22:50:25 -05:00
|
|
|
try {
|
2012-02-01 16:56:04 -05:00
|
|
|
this.dragHandler(
|
|
|
|
this,
|
|
|
|
getMouseRelative( event, this.element ),
|
2012-01-17 18:30:41 -05:00
|
|
|
delta,
|
|
|
|
event.shiftKey
|
|
|
|
);
|
2011-12-05 22:50:25 -05:00
|
|
|
} catch (e) {
|
2012-01-25 14:14:02 -05:00
|
|
|
$.console.error(
|
2012-02-01 16:56:04 -05:00
|
|
|
e.name + " while executing drag handler: " + e.message,
|
2012-01-17 18:30:41 -05:00
|
|
|
e
|
|
|
|
);
|
2011-12-05 22:50:25 -05:00
|
|
|
}
|
|
|
|
|
2012-02-01 16:56:04 -05:00
|
|
|
$.cancelEvent( event );
|
2011-12-05 22:50:25 -05:00
|
|
|
}
|
2012-02-01 16:56:04 -05:00
|
|
|
},
|
2011-12-05 22:50:25 -05:00
|
|
|
|
|
|
|
/**
|
2012-01-31 21:01:37 -05: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).
|
2012-02-01 16:56:04 -05:00
|
|
|
* @method
|
2012-01-31 21:01:37 -05:00
|
|
|
*/
|
2012-02-01 16:56:04 -05:00
|
|
|
onMouseMoveIE: function( event ) {
|
|
|
|
var i;
|
|
|
|
for ( i = 0; i < ieTrackersCapturing.length; i++ ) {
|
|
|
|
ieTrackersCapturing[ i ].onMouseMove( event );
|
2011-12-05 22:50:25 -05:00
|
|
|
}
|
|
|
|
|
2012-02-01 16:56:04 -05:00
|
|
|
$.stopEvent( event );
|
|
|
|
}
|
2011-12-05 22:50:25 -05:00
|
|
|
|
2011-12-13 20:04:38 -05:00
|
|
|
};
|
2011-12-05 22:50:25 -05:00
|
|
|
|
2012-01-31 21:01:37 -05:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @inner
|
|
|
|
*/
|
2011-12-13 20:04:38 -05:00
|
|
|
function getMouseAbsolute( event ) {
|
2012-02-01 16:56:04 -05:00
|
|
|
return $.getMousePosition( event );
|
|
|
|
};
|
2011-12-05 22:50:25 -05:00
|
|
|
|
2012-01-31 21:01:37 -05:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @inner
|
|
|
|
*/
|
2012-02-01 16:56:04 -05:00
|
|
|
function getMouseRelative( event, element ) {
|
|
|
|
var mouse = $.getMousePosition( event ),
|
|
|
|
offset = $.getElementPosition( element );
|
2011-12-05 22:50:25 -05:00
|
|
|
|
2012-02-01 16:56:04 -05:00
|
|
|
return mouse.minus( offset );
|
|
|
|
};
|
2011-12-05 22:50:25 -05:00
|
|
|
|
2011-12-13 20:04:38 -05:00
|
|
|
/**
|
2012-01-25 14:14:02 -05:00
|
|
|
* @private
|
2012-01-31 21:01:37 -05:00
|
|
|
* @inner
|
2012-02-01 16:56:04 -05:00
|
|
|
* Returns true if elementB is a child node of elementA, or if they're equal.
|
2011-12-13 20:04:38 -05:00
|
|
|
*/
|
2012-02-01 16:56:04 -05:00
|
|
|
function isChild( elementA, elementB ) {
|
2011-12-13 20:04:38 -05:00
|
|
|
var body = document.body;
|
2012-02-01 16:56:04 -05:00
|
|
|
while ( elementB && elementA != elementB && body != elementB ) {
|
2011-12-13 20:04:38 -05:00
|
|
|
try {
|
2012-02-01 16:56:04 -05:00
|
|
|
elementB = elementB.parentNode;
|
2011-12-13 20:04:38 -05:00
|
|
|
} catch (e) {
|
|
|
|
return false;
|
2011-12-05 22:50:25 -05:00
|
|
|
}
|
2011-12-13 20:04:38 -05:00
|
|
|
}
|
2012-02-01 16:56:04 -05:00
|
|
|
return elementA == elementB;
|
|
|
|
};
|
2011-12-13 20:04:38 -05:00
|
|
|
|
2012-01-31 21:01:37 -05:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @inner
|
|
|
|
*/
|
2011-12-13 20:04:38 -05:00
|
|
|
function onGlobalMouseDown() {
|
|
|
|
buttonDownAny = true;
|
2012-02-01 16:56:04 -05:00
|
|
|
};
|
2011-12-13 20:04:38 -05:00
|
|
|
|
2012-01-31 21:01:37 -05:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @inner
|
|
|
|
*/
|
2011-12-13 20:04:38 -05:00
|
|
|
function onGlobalMouseUp() {
|
|
|
|
buttonDownAny = false;
|
2012-02-01 16:56:04 -05:00
|
|
|
};
|
2011-12-05 22:50:25 -05:00
|
|
|
|
|
|
|
|
2011-12-13 20:04:38 -05:00
|
|
|
(function () {
|
2012-02-01 16:56:04 -05:00
|
|
|
if ( $.Browser.vendor == $.BROWSERS.IE ) {
|
|
|
|
$.addEvent( document, "mousedown", onGlobalMouseDown, false );
|
|
|
|
$.addEvent( document, "mouseup", onGlobalMouseUp, false );
|
2011-12-13 20:04:38 -05:00
|
|
|
} else {
|
2012-02-01 16:56:04 -05:00
|
|
|
$.addEvent( window, "mousedown", onGlobalMouseDown, true );
|
|
|
|
$.addEvent( window, "mouseup", onGlobalMouseUp, true );
|
2011-12-13 20:04:38 -05:00
|
|
|
}
|
|
|
|
})();
|
2011-12-05 22:50:25 -05:00
|
|
|
|
|
|
|
}( OpenSeadragon ));
|