Skip to content
Permalink
Browse files

Make sure `.data("events")` still works, for now.

  • Loading branch information...
dmethvin committed Oct 27, 2011
1 parent c2da514 commit c82dbf1928f54385e83df9ec6de47616f83fe682
Showing with 8 additions and 7 deletions.
  1. +8 −7 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

0 comments on commit c82dbf1

Please sign in to comment.
You can’t perform that action at this time.