From 5b995eb04b7a391353420bbfb85a61e16f2635b4 Mon Sep 17 00:00:00 2001 From: Mark Salsbery Date: Fri, 2 May 2014 23:01:38 -0700 Subject: [PATCH] Removed mousenter/mouseleave DOM Event Handling Fixes #394 mouseenter/mouseleave are not implemented in Webkit very well, so reverted to mouseover/mouseout. --- src/mousetracker.js | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/mousetracker.js b/src/mousetracker.js index 957d9124..03ed2b43 100644 --- a/src/mousetracker.js +++ b/src/mousetracker.js @@ -174,8 +174,6 @@ * Are we curruently capturing mouse events (legacy mouse events only). */ THIS[ this.hash ] = { - setCaptureCapable: !!this.element.setCapture && !!this.element.releaseCapture, - click: function ( event ) { onClick( _this, event ); }, dblclick: function ( event ) { onDblClick( _this, event ); }, keypress: function ( event ) { onKeyPress( _this, event ); }, @@ -795,6 +793,14 @@ document.onmousewheel !== undefined ? 'mousewheel' : // Webkit and IE support at least 'mousewheel' 'DOMMouseScroll'; // Assume old Firefox + /** + * Detect legacy mouse capture support. + */ + $.MouseTracker.supportsMouseCapture = (function () { + var divElement = document.createElement( 'div' ); + return $.isFunction( divElement.setCapture ) && $.isFunction( divElement.releaseCapture ); + }()); + /** * Detect browser pointer device event model(s) and build appropriate list of events to subscribe to. */ @@ -829,14 +835,9 @@ $.MouseTracker.haveMouseEnter = true; } else { // Legacy W3C mouse events - $.MouseTracker.subscribeEvents.push( "mousedown", "mouseup", "mousemove" ); - if ( 'onmouseenter' in window ) { - $.MouseTracker.subscribeEvents.push( "mouseenter", "mouseleave" ); - $.MouseTracker.haveMouseEnter = true; - } else { - $.MouseTracker.subscribeEvents.push( "mouseover", "mouseout" ); - $.MouseTracker.haveMouseEnter = false; - } + // TODO: Favor mouseenter/mouseleave over mouseover/mouseout when Webkit browser support is better + $.MouseTracker.subscribeEvents.push( "mouseover", "mouseout", "mousedown", "mouseup", "mousemove" ); + $.MouseTracker.haveMouseEnter = false; if ( 'ontouchstart' in window ) { // iOS, Android, and other W3c Touch Event implementations (see http://www.w3.org/TR/2011/WD-touch-events-20110505) $.MouseTracker.subscribeEvents.push( "touchstart", "touchend", "touchmove", "touchcancel" ); @@ -1082,7 +1083,7 @@ var delegate = THIS[ tracker.hash ]; if ( !delegate.capturing ) { - if ( delegate.setCaptureCapable ) { + if ( $.MouseTracker.supportsMouseCapture ) { // IE<10, Firefox, other browsers with setCapture()/releaseCapture() tracker.element.setCapture( true ); } else { @@ -1115,7 +1116,7 @@ var delegate = THIS[ tracker.hash ]; if ( delegate.capturing ) { - if ( delegate.setCaptureCapable ) { + if ( $.MouseTracker.supportsMouseCapture ) { // IE<10, Firefox, other browsers with setCapture()/releaseCapture() tracker.element.releaseCapture(); } else {