Commit 31293063 authored by Ariel Flesler's avatar Ariel Flesler

jquery event: closes #3127. jQuery.event.special built-in methods were...

jquery event: closes #3127. jQuery.event.special built-in methods were optimized. The mouse(enter|leave) special case is only added for non-IE browsers.Thanks to Mike Helgeson for his help.
parent a3e97062
...@@ -360,60 +360,46 @@ jQuery.event = { ...@@ -360,60 +360,46 @@ jQuery.event = {
special: { special: {
ready: { ready: {
setup: function() {
// Make sure the ready event is setup // Make sure the ready event is setup
bindReady(); setup: bindReady,
return; teardown: function() {}
}, }
}
teardown: function() { return; } };
},
mouseenter: {
setup: function( data ) {
if ( jQuery.browser.msie ) return false;
jQuery(this).bind("mouseover", data, jQuery.event.special.mouseenter.handler);
return true;
},
teardown: function() { if ( !jQuery.browser.msie ){
if ( jQuery.browser.msie ) return false; // Checks if an event happened on an element within another element
jQuery(this).unbind("mouseover", jQuery.event.special.mouseenter.handler); // Used in jQuery.event.special.mouseenter and mouseleave handlers
return true; var withinElement = function(event) {
}, // Check if mouse(over|out) are still within the same parent element
var parent = event.relatedTarget;
// Traverse up the tree
while ( parent && parent != this )
try { parent = parent.parentNode; }
catch(e) { parent = this; }
handler: function(event) { if( parent != this ){
// If we actually just moused on to a sub-element, ignore it // set the correct event type
if ( withinElement(event, this) ) return true; event.type = event.data;
// Execute the right handlers by setting the event type to mouseenter // handle event if we actually just moused on to a non sub-element
event.type = "mouseenter"; jQuery.event.handle.apply( this, arguments );
return jQuery.event.handle.apply(this, arguments);
} }
}, };
mouseleave: {
setup: function( data ) {
if ( jQuery.browser.msie ) return false;
jQuery(this).bind("mouseout", data, jQuery.event.special.mouseleave.handler);
return true;
},
teardown: function() { jQuery.each({
if ( jQuery.browser.msie ) return false; mouseover: 'mouseenter',
jQuery(this).unbind("mouseout", jQuery.event.special.mouseleave.handler); mouseout: 'mouseleave'
return true; }, function( orig, fix ){
jQuery.event.special[ fix ] = {
setup: function(){
jQuery.event.add( this, orig, withinElement, fix );
}, },
teardown: function(){
handler: function(event) { jQuery.event.remove( this, orig, withinElement );
// If we actually just moused on to a sub-element, ignore it
if ( withinElement(event, this) ) return true;
// Execute the right handlers by setting the event type to mouseleave
event.type = "mouseleave";
return jQuery.event.handle.apply(this, arguments);
} }
} };
} });
}; }
jQuery.fn.extend({ jQuery.fn.extend({
bind: function( type, data, fn ) { bind: function( type, data, fn ) {
...@@ -589,17 +575,6 @@ jQuery.each( ("blur,focus,load,resize,scroll,unload,click,dblclick," + ...@@ -589,17 +575,6 @@ jQuery.each( ("blur,focus,load,resize,scroll,unload,click,dblclick," +
}; };
}); });
// Checks if an event happened on an element within another element
// Used in jQuery.event.special.mouseenter and mouseleave handlers
var withinElement = function(event, elem) {
// Check if mouse(over|out) are still within the same parent element
var parent = event.relatedTarget;
// Traverse up the tree
while ( parent && parent != elem ) try { parent = parent.parentNode; } catch(error) { parent = elem; }
// Return true if we actually just moused on to a sub-element
return parent == elem;
};
// Prevent memory leaks in IE // Prevent memory leaks in IE
// And prevent errors on refresh with events like mouseover in other browsers // And prevent errors on refresh with events like mouseover in other browsers
// Window isn't included so as not to unbind existing unload events // Window isn't included so as not to unbind existing unload events
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment