From 755c4752c099f4279abb338d086e5e20b2666e6e Mon Sep 17 00:00:00 2001 From: Mark Salsbery Date: Wed, 23 Oct 2013 13:55:52 -0700 Subject: [PATCH] 'wheel' Event Support Fixes Whitespace, cancel handling --- src/mousetracker.js | 79 ++++++++++++++++++-------------------------- src/openseadragon.js | 6 ---- 2 files changed, 33 insertions(+), 52 deletions(-) diff --git a/src/mousetracker.js b/src/mousetracker.js index d274fe8b..2f337711 100644 --- a/src/mousetracker.js +++ b/src/mousetracker.js @@ -440,9 +440,10 @@ /** * Detect available mouse wheel event. */ - $.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 + $.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 /** * Starts tracking mouse events on this element. @@ -1088,39 +1089,32 @@ * @private * @inner */ - function onMouseWheel( tracker, originalEvent ) { + function onMouseWheel( tracker, event ) { // For legacy IE, access the global (window) event object - originalEvent = originalEvent || window.event; + event = event || window.event; // Simulate a 'wheel' event - var event = { - target: originalEvent.target || originalEvent.srcElement, - type: "wheel", - shiftKey: originalEvent.shiftKey || false, - clientX: originalEvent.clientX, - clientY: originalEvent.clientY, - pageX: originalEvent.pageX ? originalEvent.pageX : originalEvent.clientX, - pageY: originalEvent.pageY ? originalEvent.pageY : originalEvent.clientY, - deltaMode: originalEvent.type == "MozMousePixelScroll" ? 0 : 1, // 0=pixel, 1=line, 2=page - deltaX: 0, - deltaZ: 0, - preventDefault: function() { - if ( originalEvent.preventDefault ) { - originalEvent.preventDefault(); - } else { - originalEvent.returnValue = false; - } - } + 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 }; - // Calculate event.deltaY + // Calculate deltaY if ( $.MouseTracker.wheelEventName == "mousewheel" ) { - event.deltaY = - 1 / $.DEFAULT_SETTINGS.pixelsPerWheelLine * originalEvent.wheelDelta; + simulatedEvent.deltaY = - 1 / $.DEFAULT_SETTINGS.pixelsPerWheelLine * event.wheelDelta; } 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 ) { - $.cancelEvent( event ); + $.cancelEvent( originalEvent ); } } } @@ -1278,24 +1272,17 @@ // 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: 1, // 0=pixel, 1=line, 2=page - deltaX: 0, - deltaY: ( THIS[ tracker.hash ].lastPinchDelta > pinchDelta ) ? 1 : -1, - deltaZ: 0, - preventDefault: function() { - if ( event.preventDefault ) { - event.preventDefault(); - } else { - event.returnValue = false; - } - } + target: event.target || event.srcElement, + type: "wheel", + shiftKey: event.shiftKey || false, + clientX: THIS[ tracker.hash ].pinchMidpoint.x, + clientY: THIS[ tracker.hash ].pinchMidpoint.y, + pageX: THIS[ tracker.hash ].pinchMidpoint.x, + pageY: THIS[ tracker.hash ].pinchMidpoint.y, + deltaMode: 1, // 0=pixel, 1=line, 2=page + deltaX: 0, + deltaY: ( THIS[ tracker.hash ].lastPinchDelta > pinchDelta ) ? 1 : -1, + deltaZ: 0 }; handleWheelEvent( tracker, simulatedEvent, event, true ); diff --git a/src/openseadragon.js b/src/openseadragon.js index 34d275ca..3d19f727 100644 --- a/src/openseadragon.js +++ b/src/openseadragon.js @@ -390,15 +390,11 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){ * Detect event model and create appropriate _addEvent/_removeEvent methods */ if ( window.addEventListener ) { - //$._addEventListener = 'addEventListener'; - //$._eventNamePrefix = ''; $._addEvent = function ( element, eventName, handler, useCapture ) { element = $.getElement( element ); element.addEventListener( eventName, handler, useCapture ); }; } else if ( window.attachEvent ) { - //$._addEventListener = 'attachEvent'; - //$._eventNamePrefix = 'on'; $._addEvent = function ( element, eventName, handler, useCapture ) { element = $.getElement( element ); element.attachEvent( 'on' + eventName, handler ); @@ -411,13 +407,11 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){ } if ( window.removeEventListener ) { - //$._removeEventListener = 'removeEventListener'; $._removeEvent = function ( element, eventName, handler, useCapture ) { element = $.getElement( element ); element.removeEventListener( eventName, handler, useCapture ); }; } else if ( window.detachEvent ) { - //$._removeEventListener = 'detachEvent'; $._removeEvent = function( element, eventName, handler, useCapture ) { element = $.getElement( element ); element.detachEvent( 'on' + eventName, handler );