aboutsummaryrefslogtreecommitdiffstats
path: root/src/event.js
diff options
context:
space:
mode:
authorColin Snover <github.com@zetafleet.com>2010-10-11 23:35:18 -0500
committerColin Snover <github.com@zetafleet.com>2010-10-11 23:35:18 -0500
commitff6ceadbfd470463e63708413eb5a55bd7e90c69 (patch)
treede0a35901e93405d8272657ce14042af47c3194f /src/event.js
parent6245ecb2b91cca73f66dc0543beb6626c138bcfc (diff)
downloadjquery-ff6ceadbfd470463e63708413eb5a55bd7e90c69.tar.gz
jquery-ff6ceadbfd470463e63708413eb5a55bd7e90c69.zip
Use a key name less likely to result in collisions for events on plain JS objects. Fixes bug #7150.
Diffstat (limited to 'src/event.js')
-rw-r--r--src/event.js18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/event.js b/src/event.js
index d949d0f0f..1bbf1348d 100644
--- a/src/event.js
+++ b/src/event.js
@@ -54,7 +54,10 @@ jQuery.event = {
return;
}
- var events = elemData.events,
+ // Use a key less likely to result in collisions for plain JS objects.
+ // Fixes bug #7150.
+ var eventKey = elem.nodeType ? "events" : "__events__",
+ events = elemData[ eventKey ],
eventHandle = elemData.handle;
if ( typeof events === "function" ) {
@@ -68,7 +71,7 @@ jQuery.event = {
if ( !elem.nodeType ) {
// On plain objects, create a fn that acts as the holder
// of the values to avoid JSON serialization of event data
- elemData.events = elemData = function(){};
+ elemData[ eventKey ] = elemData = function(){};
}
elemData.events = events = {};
@@ -170,8 +173,9 @@ jQuery.event = {
}
var ret, type, fn, j, i = 0, all, namespaces, namespace, special, eventType, handleObj, origType,
+ eventKey = elem.nodeType ? "events" : "__events__",
elemData = jQuery.data( elem ),
- events = elemData && elemData.events;
+ events = elemData && elemData[ eventKey ];
if ( !elemData || !events ) {
return;
@@ -278,7 +282,7 @@ jQuery.event = {
handle.elem = null;
}
- delete elemData.events;
+ delete elemData[ eventKey ];
delete elemData.handle;
if ( typeof elemData === "function" ) {
@@ -346,7 +350,7 @@ jQuery.event = {
// Trigger the event, it is assumed that "handle" is a function
var handle = elem.nodeType ?
jQuery.data( elem, "handle" ) :
- (jQuery.data( elem, "events" ) || {}).handle;
+ (jQuery.data( elem, "__events__" ) || {}).handle;
if ( handle ) {
handle.apply( elem, data );
@@ -420,7 +424,7 @@ jQuery.event = {
event.namespace = event.namespace || namespace_sort.join(".");
- events = jQuery.data(this, "events");
+ events = jQuery.data(this, this.nodeType ? "events" : "__events__");
if ( typeof events === "function" ) {
events = events.events;
@@ -1044,7 +1048,7 @@ jQuery.each(["live", "die"], function( i, name ) {
function liveHandler( event ) {
var stop, maxLevel, elems = [], selectors = [],
related, match, handleObj, elem, j, i, l, data, close, namespace, ret,
- events = jQuery.data( this, "events" );
+ events = jQuery.data( this, this.nodeType ? "events" : "__events__" );
if ( typeof events === "function" ) {
events = events.events;