From c82dbf1928f54385e83df9ec6de47616f83fe682 Mon Sep 17 00:00:00 2001 From: Dave Methvin Date: Wed, 26 Oct 2011 22:56:26 -0400 Subject: [PATCH] Make sure `.data("events")` still works, for now. --- src/data.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/data.js b/src/data.js index 24011c6b7..15faa6fdc 100644 --- a/src/data.js +++ b/src/data.js @@ -32,7 +32,7 @@ jQuery.extend({ return; } - var thisCache, ret, + var privateCache, thisCache, ret, internalKey = jQuery.expando, getByName = typeof name === "string", @@ -46,11 +46,12 @@ jQuery.extend({ // Only defining an ID for JS objects if its cache already exists allows // the code to shortcut on the same path as a DOM node with no cache - id = isNode ? elem[ jQuery.expando ] : elem[ jQuery.expando ] && jQuery.expando; + id = isNode ? elem[ jQuery.expando ] : elem[ jQuery.expando ] && jQuery.expando, + isEvents = name === "events"; // Avoid doing any more work than we need to when trying to get data on an // object that has no data at all - if ( (!id || !cache[id] || (!pvt && !cache[id].data)) && getByName && data === undefined ) { + if ( (!id || !cache[id] || (!isEvents && !pvt && !cache[id].data)) && getByName && data === undefined ) { return; } @@ -67,7 +68,7 @@ jQuery.extend({ if ( !cache[ id ] ) { cache[ id ] = {}; - // Avoids exposing jQuery metadata on plain JS objects when the object + // Avoids exposing jQuery metadata on plain JS objects when the object // is serialized using JSON.stringify if ( !isNode ) { cache[ id ].toJSON = jQuery.noop; @@ -84,7 +85,7 @@ jQuery.extend({ } } - thisCache = cache[ id ]; + privateCache = thisCache = cache[ id ]; // jQuery data() is stored in a separate object inside the object's internal data // cache in order to avoid key collisions between internal data and user-defined @@ -103,8 +104,8 @@ jQuery.extend({ // Users should not attempt to inspect the internal events object using jQuery.data, // it is undocumented and subject to change. But does anyone listen? No. - if ( name === "events" && !thisCache[name] ) { - return thisCache[ internalKey ] && thisCache[ internalKey ].events; + if ( isEvents && !thisCache[ name ] ) { + return privateCache.events; } // Check for both converted-to-camel and non-converted data property names -- 2.39.5