Commit 08e13454 authored by carldanley's avatar carldanley Committed by Rick Waldron

Create private methods for processing data/removeData requests. Fixes #12519, Closes gh-976

parent 2e3ca6ca
var rbrace = /(?:\{[\s\S]*\}|\[[\s\S]*\])$/, var rbrace = /(?:\{[\s\S]*\}|\[[\s\S]*\])$/,
rmultiDash = /([A-Z])/g; rmultiDash = /([A-Z])/g;
jQuery.extend({ function internalData( elem, name, data, pvt /* Internal Use Only */ ){
cache: {},
deletedIds: [],
// Remove at next major release (1.9/2.0)
uuid: 0,
// Unique for each copy of jQuery on the page
// Non-digits removed to match rinlinejQuery
expando: "jQuery" + ( jQuery.fn.jquery + Math.random() ).replace( /\D/g, "" ),
// The following elements throw uncatchable exceptions if you
// attempt to add expando properties to them.
noData: {
"embed": true,
// Ban all objects except for Flash (which handle expandos)
"object": "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",
"applet": true
},
hasData: function( elem ) {
elem = elem.nodeType ? jQuery.cache[ elem[jQuery.expando] ] : elem[ jQuery.expando ];
return !!elem && !isEmptyDataObject( elem );
},
data: function( elem, name, data, pvt /* Internal Use Only */ ) {
if ( !jQuery.acceptData( elem ) ) { if ( !jQuery.acceptData( elem ) ) {
return; return;
} }
...@@ -119,9 +93,9 @@ jQuery.extend({ ...@@ -119,9 +93,9 @@ jQuery.extend({
} }
return ret; return ret;
}, }
removeData: function( elem, name, pvt /* Internal Use Only */ ) { function internalRemoveData( elem, name, pvt /* For internal use only */ ){
if ( !jQuery.acceptData( elem ) ) { if ( !jQuery.acceptData( elem ) ) {
return; return;
} }
...@@ -199,11 +173,49 @@ jQuery.extend({ ...@@ -199,11 +173,49 @@ jQuery.extend({
} else { } else {
cache[ id ] = null; cache[ id ] = null;
} }
}
jQuery.extend({
cache: {},
deletedIds: [],
// Remove at next major release (1.9/2.0)
uuid: 0,
// Unique for each copy of jQuery on the page
// Non-digits removed to match rinlinejQuery
expando: "jQuery" + ( jQuery.fn.jquery + Math.random() ).replace( /\D/g, "" ),
// The following elements throw uncatchable exceptions if you
// attempt to add expando properties to them.
noData: {
"embed": true,
// Ban all objects except for Flash (which handle expandos)
"object": "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",
"applet": true
},
hasData: function( elem ) {
elem = elem.nodeType ? jQuery.cache[ elem[jQuery.expando] ] : elem[ jQuery.expando ];
return !!elem && !isEmptyDataObject( elem );
},
data: function( elem, name, data ) {
return internalData( elem, name, data, false );
},
removeData: function( elem, name ) {
return internalRemoveData( elem, name, false );
}, },
// For internal use only. // For internal use only.
_data: function( elem, name, data ) { _data: function( elem, name, data ) {
return jQuery.data( elem, name, data, true ); return internalData( elem, name, data, true );
},
_removeData: function( elem, name ) {
return internalRemoveData( elem, name, true );
}, },
// A method for determining if a DOM node can handle the data expando // A method for determining if a DOM node can handle the data expando
......
...@@ -327,7 +327,7 @@ function defaultPrefilter( elem, props, opts ) { ...@@ -327,7 +327,7 @@ function defaultPrefilter( elem, props, opts ) {
} }
anim.done(function() { anim.done(function() {
var prop; var prop;
jQuery.removeData( elem, "fxshow", true ); jQuery._removeData( elem, "fxshow" );
for ( prop in orig ) { for ( prop in orig ) {
jQuery.style( elem, prop, orig[ prop ] ); jQuery.style( elem, prop, orig[ prop ] );
} }
......
...@@ -15,7 +15,6 @@ var rformElems = /^(?:textarea|input|select)$/i, ...@@ -15,7 +15,6 @@ var rformElems = /^(?:textarea|input|select)$/i,
jQuery.event = { jQuery.event = {
add: function( elem, types, handler, data, selector ) { add: function( elem, types, handler, data, selector ) {
var elemData, eventHandle, events, var elemData, eventHandle, events,
t, tns, type, namespaces, handleObj, t, tns, type, namespaces, handleObj,
handleObjIn, handlers, special; handleObjIn, handlers, special;
...@@ -196,7 +195,7 @@ jQuery.event = { ...@@ -196,7 +195,7 @@ jQuery.event = {
// removeData also checks for emptiness and clears the expando if empty // removeData also checks for emptiness and clears the expando if empty
// so use it instead of delete // so use it instead of delete
jQuery.removeData( elem, "events", true ); jQuery._removeData( elem, "events" );
} }
}, },
......
...@@ -58,8 +58,8 @@ jQuery.extend({ ...@@ -58,8 +58,8 @@ jQuery.extend({
var key = type + "queueHooks"; var key = type + "queueHooks";
return jQuery._data( elem, key ) || jQuery._data( elem, key, { return jQuery._data( elem, key ) || jQuery._data( elem, key, {
empty: jQuery.Callbacks("once memory").add(function() { empty: jQuery.Callbacks("once memory").add(function() {
jQuery.removeData( elem, type + "queue", true ); jQuery._removeData( elem, type + "queue" );
jQuery.removeData( elem, key, true ); jQuery._removeData( elem, key );
}) })
}); });
} }
......
...@@ -50,7 +50,7 @@ function dataTests (elem) { ...@@ -50,7 +50,7 @@ function dataTests (elem) {
strictEqual( jQuery.data(elem, "foo"), "foo1", "Passing an object extends the data object instead of replacing it" ); strictEqual( jQuery.data(elem, "foo"), "foo1", "Passing an object extends the data object instead of replacing it" );
equal( jQuery.data(elem, "boom"), "bloz", "Extending the data object works" ); equal( jQuery.data(elem, "boom"), "bloz", "Extending the data object works" );
jQuery._data(elem, "foo", "foo2"); jQuery._data(elem, "foo", "foo2", true);
equal( jQuery._data(elem, "foo"), "foo2", "Setting internal data works" ); equal( jQuery._data(elem, "foo"), "foo2", "Setting internal data works" );
equal( jQuery.data(elem, "foo"), "foo1", "Setting internal data does not override user data" ); equal( jQuery.data(elem, "foo"), "foo1", "Setting internal data does not override user data" );
...@@ -66,9 +66,9 @@ function dataTests (elem) { ...@@ -66,9 +66,9 @@ function dataTests (elem) {
jQuery.removeData(elem); jQuery.removeData(elem);
strictEqual( jQuery._data(elem), internalDataObj, "jQuery.removeData does not remove internal data if it exists" ); strictEqual( jQuery._data(elem), internalDataObj, "jQuery.removeData does not remove internal data if it exists" );
jQuery.removeData(elem, undefined, true); jQuery._removeData(elem);
strictEqual( jQuery.data(elem, jQuery.expando), undefined, "jQuery.removeData on internal data works" ); strictEqual( jQuery._data(elem, jQuery.expando), undefined, "jQuery.removeData on internal data works" );
strictEqual( jQuery.hasData(elem), false, "jQuery.hasData agrees all data has been removed from object" ); strictEqual( jQuery.hasData(elem), false, "jQuery.hasData agrees all data has been removed from object" );
jQuery._data(elem, "foo", "foo2"); jQuery._data(elem, "foo", "foo2");
...@@ -79,7 +79,7 @@ function dataTests (elem) { ...@@ -79,7 +79,7 @@ function dataTests (elem) {
// delete the last private data key so we can test removing public data // delete the last private data key so we can test removing public data
// will destroy the cache // will destroy the cache
jQuery.removeData( elem, "foo", true ); jQuery._removeData( elem, "foo" );
if (elem.nodeType) { if (elem.nodeType) {
oldCacheLength = getCacheLength(); oldCacheLength = getCacheLength();
...@@ -109,9 +109,9 @@ function dataTests (elem) { ...@@ -109,9 +109,9 @@ function dataTests (elem) {
equal( jQuery.data(elem, "foo"), "foo1", "(sanity check) Ensure data is set in user data object" ); equal( jQuery.data(elem, "foo"), "foo1", "(sanity check) Ensure data is set in user data object" );
equal( jQuery._data(elem, "foo"), "foo2", "(sanity check) Ensure data is set in internal data object" ); equal( jQuery._data(elem, "foo"), "foo2", "(sanity check) Ensure data is set in internal data object" );
jQuery.removeData(elem, "foo", true); jQuery._removeData(elem, "foo");
strictEqual( jQuery.data(elem, jQuery.expando), undefined, "Removing the last item in internal data destroys the internal data object" ); strictEqual( jQuery._data(elem, jQuery.expando), undefined, "Removing the last item in internal data destroys the internal data object" );
jQuery._data(elem, "foo", "foo2"); jQuery._data(elem, "foo", "foo2");
equal( jQuery._data(elem, "foo"), "foo2", "(sanity check) Ensure data is set in internal data object" ); equal( jQuery._data(elem, "foo"), "foo2", "(sanity check) Ensure data is set in internal data object" );
...@@ -121,11 +121,11 @@ function dataTests (elem) { ...@@ -121,11 +121,11 @@ function dataTests (elem) {
if ( elem.nodeType ) { if ( elem.nodeType ) {
oldCacheLength = getCacheLength(); oldCacheLength = getCacheLength();
jQuery.removeData(elem, "foo", true); jQuery._removeData(elem, "foo");
equal( getCacheLength(), oldCacheLength - 1, "Removing the last item in the internal data object also destroys the user data object when it is empty" ); equal( getCacheLength(), oldCacheLength - 1, "Removing the last item in the internal data object also destroys the user data object when it is empty" );
} }
else { else {
jQuery.removeData(elem, "foo", true); jQuery._removeData(elem, "foo");
if (jQuery.support.deleteExpando) { if (jQuery.support.deleteExpando) {
expected = false; expected = false;
......
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