Fix scope issue in DOM 2 event handlers
This commit is contained in:
parent
2ad223aedd
commit
e0aa10a664
|
@ -49,11 +49,17 @@ jQuery.event = {
|
||||||
// Add the function to the element's handler list
|
// Add the function to the element's handler list
|
||||||
handlers[handler.guid] = handler;
|
handlers[handler.guid] = handler;
|
||||||
|
|
||||||
// And bind the global event handler to the element
|
if (!element.$handle) {
|
||||||
if (element.addEventListener)
|
element.$handle = function() {
|
||||||
element.addEventListener(type, this.handle, false);
|
jQuery.event.handle.apply(element, arguments);
|
||||||
else if (element.attachEvent)
|
};
|
||||||
element.attachEvent("on" + type, this.handle, false);
|
|
||||||
|
// And bind the global event handler to the element
|
||||||
|
if (element.addEventListener)
|
||||||
|
element.addEventListener(type, element.$handle, false);
|
||||||
|
else if (element.attachEvent)
|
||||||
|
element.attachEvent("on" + type, element.$handle, false);
|
||||||
|
}
|
||||||
|
|
||||||
// Remember the function in a global list (for triggering)
|
// Remember the function in a global list (for triggering)
|
||||||
if (!this.global[type])
|
if (!this.global[type])
|
||||||
|
@ -92,11 +98,11 @@ jQuery.event = {
|
||||||
// remove generic event handler if no more handlers exist
|
// remove generic event handler if no more handlers exist
|
||||||
for ( ret in events[type] ) break;
|
for ( ret in events[type] ) break;
|
||||||
if ( !ret ) {
|
if ( !ret ) {
|
||||||
ret = null;
|
|
||||||
if (element.removeEventListener)
|
if (element.removeEventListener)
|
||||||
element.removeEventListener(type, this.handle, false);
|
element.removeEventListener(type, element.$handle, false);
|
||||||
else if (element.detachEvent)
|
else if (element.detachEvent)
|
||||||
element.detachEvent("on" + type, this.handle, false);
|
element.detachEvent("on" + type, element.$handle, false);
|
||||||
|
ret = element.$handle = null;
|
||||||
delete events[type];
|
delete events[type];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue