mirror of
https://github.com/openseadragon/openseadragon.git
synced 2024-11-29 08:36:10 +03:00
'wheel' Event Support Fixes
Whitespace, cancel handling
This commit is contained in:
parent
e76c9e65ab
commit
755c4752c0
@ -440,9 +440,10 @@
|
|||||||
/**
|
/**
|
||||||
* Detect available mouse wheel event.
|
* Detect available mouse wheel event.
|
||||||
*/
|
*/
|
||||||
$.MouseTracker.wheelEventName = (($.Browser.vendor == $.BROWSERS.IE && $.Browser.version > 8) || ("onwheel" in document.createElement("div"))) ? "wheel" : // Modern browsers support "wheel"
|
$.MouseTracker.wheelEventName = ( $.Browser.vendor == $.BROWSERS.IE && $.Browser.version > 8 ) ||
|
||||||
document.onmousewheel !== undefined ? "mousewheel" : // Webkit and IE support at least "mousewheel"
|
( 'onwheel' in document.createElement( 'div' ) ) ? 'wheel' : // Modern browsers support 'wheel'
|
||||||
"DOMMouseScroll"; // Assume old Firefox
|
document.onmousewheel !== undefined ? 'mousewheel' : // Webkit and IE support at least 'mousewheel'
|
||||||
|
'DOMMouseScroll'; // Assume old Firefox
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts tracking mouse events on this element.
|
* Starts tracking mouse events on this element.
|
||||||
@ -1088,39 +1089,32 @@
|
|||||||
* @private
|
* @private
|
||||||
* @inner
|
* @inner
|
||||||
*/
|
*/
|
||||||
function onMouseWheel( tracker, originalEvent ) {
|
function onMouseWheel( tracker, event ) {
|
||||||
// For legacy IE, access the global (window) event object
|
// For legacy IE, access the global (window) event object
|
||||||
originalEvent = originalEvent || window.event;
|
event = event || window.event;
|
||||||
|
|
||||||
// Simulate a 'wheel' event
|
// Simulate a 'wheel' event
|
||||||
var event = {
|
var simulatedEvent = {
|
||||||
target: originalEvent.target || originalEvent.srcElement,
|
target: event.target || event.srcElement,
|
||||||
type: "wheel",
|
type: "wheel",
|
||||||
shiftKey: originalEvent.shiftKey || false,
|
shiftKey: event.shiftKey || false,
|
||||||
clientX: originalEvent.clientX,
|
clientX: event.clientX,
|
||||||
clientY: originalEvent.clientY,
|
clientY: event.clientY,
|
||||||
pageX: originalEvent.pageX ? originalEvent.pageX : originalEvent.clientX,
|
pageX: event.pageX ? event.pageX : event.clientX,
|
||||||
pageY: originalEvent.pageY ? originalEvent.pageY : originalEvent.clientY,
|
pageY: event.pageY ? event.pageY : event.clientY,
|
||||||
deltaMode: originalEvent.type == "MozMousePixelScroll" ? 0 : 1, // 0=pixel, 1=line, 2=page
|
deltaMode: event.type == "MozMousePixelScroll" ? 0 : 1, // 0=pixel, 1=line, 2=page
|
||||||
deltaX: 0,
|
deltaX: 0,
|
||||||
deltaZ: 0,
|
deltaZ: 0
|
||||||
preventDefault: function() {
|
|
||||||
if ( originalEvent.preventDefault ) {
|
|
||||||
originalEvent.preventDefault();
|
|
||||||
} else {
|
|
||||||
originalEvent.returnValue = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Calculate event.deltaY
|
// Calculate deltaY
|
||||||
if ( $.MouseTracker.wheelEventName == "mousewheel" ) {
|
if ( $.MouseTracker.wheelEventName == "mousewheel" ) {
|
||||||
event.deltaY = - 1 / $.DEFAULT_SETTINGS.pixelsPerWheelLine * originalEvent.wheelDelta;
|
simulatedEvent.deltaY = - 1 / $.DEFAULT_SETTINGS.pixelsPerWheelLine * event.wheelDelta;
|
||||||
} else {
|
} else {
|
||||||
event.deltaY = originalEvent.detail;
|
simulatedEvent.deltaY = event.detail;
|
||||||
}
|
}
|
||||||
|
|
||||||
handleWheelEvent( tracker, event, originalEvent, false );
|
handleWheelEvent( tracker, simulatedEvent, event, false );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1157,7 +1151,7 @@
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
if ( propagate === false ) {
|
if ( propagate === false ) {
|
||||||
$.cancelEvent( event );
|
$.cancelEvent( originalEvent );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1281,21 +1275,14 @@
|
|||||||
target: event.target || event.srcElement,
|
target: event.target || event.srcElement,
|
||||||
type: "wheel",
|
type: "wheel",
|
||||||
shiftKey: event.shiftKey || false,
|
shiftKey: event.shiftKey || false,
|
||||||
clientX: event.clientX,
|
clientX: THIS[ tracker.hash ].pinchMidpoint.x,
|
||||||
clientY: event.clientY,
|
clientY: THIS[ tracker.hash ].pinchMidpoint.y,
|
||||||
pageX: event.pageX ? event.pageX : event.clientX,
|
pageX: THIS[ tracker.hash ].pinchMidpoint.x,
|
||||||
pageY: event.pageY ? event.pageY : event.clientY,
|
pageY: THIS[ tracker.hash ].pinchMidpoint.y,
|
||||||
deltaMode: 1, // 0=pixel, 1=line, 2=page
|
deltaMode: 1, // 0=pixel, 1=line, 2=page
|
||||||
deltaX: 0,
|
deltaX: 0,
|
||||||
deltaY: ( THIS[ tracker.hash ].lastPinchDelta > pinchDelta ) ? 1 : -1,
|
deltaY: ( THIS[ tracker.hash ].lastPinchDelta > pinchDelta ) ? 1 : -1,
|
||||||
deltaZ: 0,
|
deltaZ: 0
|
||||||
preventDefault: function() {
|
|
||||||
if ( event.preventDefault ) {
|
|
||||||
event.preventDefault();
|
|
||||||
} else {
|
|
||||||
event.returnValue = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
handleWheelEvent( tracker, simulatedEvent, event, true );
|
handleWheelEvent( tracker, simulatedEvent, event, true );
|
||||||
|
@ -390,15 +390,11 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){
|
|||||||
* Detect event model and create appropriate _addEvent/_removeEvent methods
|
* Detect event model and create appropriate _addEvent/_removeEvent methods
|
||||||
*/
|
*/
|
||||||
if ( window.addEventListener ) {
|
if ( window.addEventListener ) {
|
||||||
//$._addEventListener = 'addEventListener';
|
|
||||||
//$._eventNamePrefix = '';
|
|
||||||
$._addEvent = function ( element, eventName, handler, useCapture ) {
|
$._addEvent = function ( element, eventName, handler, useCapture ) {
|
||||||
element = $.getElement( element );
|
element = $.getElement( element );
|
||||||
element.addEventListener( eventName, handler, useCapture );
|
element.addEventListener( eventName, handler, useCapture );
|
||||||
};
|
};
|
||||||
} else if ( window.attachEvent ) {
|
} else if ( window.attachEvent ) {
|
||||||
//$._addEventListener = 'attachEvent';
|
|
||||||
//$._eventNamePrefix = 'on';
|
|
||||||
$._addEvent = function ( element, eventName, handler, useCapture ) {
|
$._addEvent = function ( element, eventName, handler, useCapture ) {
|
||||||
element = $.getElement( element );
|
element = $.getElement( element );
|
||||||
element.attachEvent( 'on' + eventName, handler );
|
element.attachEvent( 'on' + eventName, handler );
|
||||||
@ -411,13 +407,11 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( window.removeEventListener ) {
|
if ( window.removeEventListener ) {
|
||||||
//$._removeEventListener = 'removeEventListener';
|
|
||||||
$._removeEvent = function ( element, eventName, handler, useCapture ) {
|
$._removeEvent = function ( element, eventName, handler, useCapture ) {
|
||||||
element = $.getElement( element );
|
element = $.getElement( element );
|
||||||
element.removeEventListener( eventName, handler, useCapture );
|
element.removeEventListener( eventName, handler, useCapture );
|
||||||
};
|
};
|
||||||
} else if ( window.detachEvent ) {
|
} else if ( window.detachEvent ) {
|
||||||
//$._removeEventListener = 'detachEvent';
|
|
||||||
$._removeEvent = function( element, eventName, handler, useCapture ) {
|
$._removeEvent = function( element, eventName, handler, useCapture ) {
|
||||||
element = $.getElement( element );
|
element = $.getElement( element );
|
||||||
element.detachEvent( 'on' + eventName, handler );
|
element.detachEvent( 'on' + eventName, handler );
|
||||||
|
Loading…
Reference in New Issue
Block a user