2012-08-24 02:19:06 +00:00
|
|
|
var rbrace = /(?:\{[\s\S]*\}|\[[\s\S]*\])$/,
|
2011-09-07 14:13:22 +00:00
|
|
|
rmultiDash = /([A-Z])/g;
|
2013-01-31 01:40:39 +00:00
|
|
|
|
|
|
|
function internalData( elem, name, data, pvt ) {
|
2012-10-16 15:15:41 +00:00
|
|
|
if ( !jQuery.acceptData( elem ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var thisCache, ret,
|
|
|
|
internalKey = jQuery.expando,
|
|
|
|
getByName = typeof name === "string",
|
|
|
|
|
|
|
|
// We have to handle DOM nodes and JS objects differently because IE6-7
|
|
|
|
// can't GC object references properly across the DOM-JS boundary
|
|
|
|
isNode = elem.nodeType,
|
|
|
|
|
|
|
|
// Only DOM nodes need the global jQuery cache; JS object data is
|
|
|
|
// attached directly to the object so GC can occur automatically
|
|
|
|
cache = isNode ? jQuery.cache : elem,
|
|
|
|
|
|
|
|
// 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[ internalKey ] : elem[ internalKey ] && internalKey;
|
|
|
|
|
|
|
|
// 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 ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !id ) {
|
|
|
|
// Only DOM nodes need a new unique ID for each element since their data
|
|
|
|
// ends up in the global cache
|
|
|
|
if ( isNode ) {
|
2012-10-21 01:02:01 +00:00
|
|
|
elem[ internalKey ] = id = core_deletedIds.pop() || jQuery.guid++;
|
2012-10-16 15:15:41 +00:00
|
|
|
} else {
|
|
|
|
id = internalKey;
|
|
|
|
}
|
|
|
|
}
|
2009-11-25 17:09:53 +00:00
|
|
|
|
2012-10-16 15:15:41 +00:00
|
|
|
if ( !cache[ id ] ) {
|
|
|
|
cache[ id ] = {};
|
2010-04-24 21:15:45 +00:00
|
|
|
|
2012-10-16 15:15:41 +00:00
|
|
|
// Avoids exposing jQuery metadata on plain JS objects when the object
|
|
|
|
// is serialized using JSON.stringify
|
|
|
|
if ( !isNode ) {
|
|
|
|
cache[ id ].toJSON = jQuery.noop;
|
|
|
|
}
|
|
|
|
}
|
2009-11-25 17:09:53 +00:00
|
|
|
|
2012-10-16 15:15:41 +00:00
|
|
|
// An object can be passed to jQuery.data instead of a key/value pair; this gets
|
|
|
|
// shallow copied over onto the existing cache
|
|
|
|
if ( typeof name === "object" || typeof name === "function" ) {
|
|
|
|
if ( pvt ) {
|
|
|
|
cache[ id ] = jQuery.extend( cache[ id ], name );
|
|
|
|
} else {
|
|
|
|
cache[ id ].data = jQuery.extend( cache[ id ].data, name );
|
|
|
|
}
|
|
|
|
}
|
2009-12-07 04:00:31 +00:00
|
|
|
|
2012-10-16 15:15:41 +00:00
|
|
|
thisCache = cache[ id ];
|
2010-12-19 21:33:53 +00:00
|
|
|
|
2012-10-16 15:15:41 +00:00
|
|
|
// 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
|
|
|
|
// data.
|
|
|
|
if ( !pvt ) {
|
|
|
|
if ( !thisCache.data ) {
|
|
|
|
thisCache.data = {};
|
2009-12-07 04:00:31 +00:00
|
|
|
}
|
|
|
|
|
2012-10-16 15:15:41 +00:00
|
|
|
thisCache = thisCache.data;
|
|
|
|
}
|
2011-01-09 21:52:33 +00:00
|
|
|
|
2012-10-16 15:15:41 +00:00
|
|
|
if ( data !== undefined ) {
|
|
|
|
thisCache[ jQuery.camelCase( name ) ] = data;
|
|
|
|
}
|
2011-01-09 21:52:33 +00:00
|
|
|
|
2012-10-16 15:15:41 +00:00
|
|
|
// Check for both converted-to-camel and non-converted data property names
|
|
|
|
// If a data property was specified
|
|
|
|
if ( getByName ) {
|
2009-11-25 17:09:53 +00:00
|
|
|
|
2012-10-16 15:15:41 +00:00
|
|
|
// First Try to find as-is property data
|
|
|
|
ret = thisCache[ name ];
|
2009-11-25 17:09:53 +00:00
|
|
|
|
2012-10-16 15:15:41 +00:00
|
|
|
// Test for null|undefined property data
|
|
|
|
if ( ret == null ) {
|
2009-11-25 17:09:53 +00:00
|
|
|
|
2012-10-16 15:15:41 +00:00
|
|
|
// Try to find the camelCased property
|
|
|
|
ret = thisCache[ jQuery.camelCase( name ) ];
|
2011-01-09 21:52:33 +00:00
|
|
|
}
|
2012-10-16 15:15:41 +00:00
|
|
|
} else {
|
|
|
|
ret = thisCache;
|
|
|
|
}
|
2010-02-27 14:49:58 +00:00
|
|
|
|
2012-10-16 15:15:41 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2011-02-14 22:22:23 +00:00
|
|
|
|
2013-01-31 01:40:39 +00:00
|
|
|
function internalRemoveData( elem, name, pvt ) {
|
2012-10-16 15:15:41 +00:00
|
|
|
if ( !jQuery.acceptData( elem ) ) {
|
|
|
|
return;
|
|
|
|
}
|
2009-11-25 17:09:53 +00:00
|
|
|
|
2012-10-16 15:15:41 +00:00
|
|
|
var thisCache, i, l,
|
2010-09-22 15:52:32 +00:00
|
|
|
|
2012-10-16 15:15:41 +00:00
|
|
|
isNode = elem.nodeType,
|
2011-01-09 21:52:33 +00:00
|
|
|
|
2012-10-16 15:15:41 +00:00
|
|
|
// See jQuery.data for more information
|
|
|
|
cache = isNode ? jQuery.cache : elem,
|
|
|
|
id = isNode ? elem[ jQuery.expando ] : jQuery.expando;
|
2010-01-28 19:12:44 +00:00
|
|
|
|
2012-10-16 15:15:41 +00:00
|
|
|
// If there is already no cache entry for this object, there is no
|
|
|
|
// purpose in continuing
|
|
|
|
if ( !cache[ id ] ) {
|
|
|
|
return;
|
|
|
|
}
|
2009-12-09 21:16:18 +00:00
|
|
|
|
2012-10-16 15:15:41 +00:00
|
|
|
if ( name ) {
|
|
|
|
|
|
|
|
thisCache = pvt ? cache[ id ] : cache[ id ].data;
|
2009-12-09 21:16:18 +00:00
|
|
|
|
2012-10-16 15:15:41 +00:00
|
|
|
if ( thisCache ) {
|
2011-07-11 01:42:40 +00:00
|
|
|
|
2012-10-16 15:15:41 +00:00
|
|
|
// Support array or space separated string names for data keys
|
|
|
|
if ( !jQuery.isArray( name ) ) {
|
2011-07-11 01:42:40 +00:00
|
|
|
|
2012-10-16 15:15:41 +00:00
|
|
|
// try the string as a key before any manipulation
|
|
|
|
if ( name in thisCache ) {
|
|
|
|
name = [ name ];
|
|
|
|
} else {
|
2011-07-11 01:42:40 +00:00
|
|
|
|
2012-10-16 15:15:41 +00:00
|
|
|
// split the camel cased version by spaces unless a key with the spaces exists
|
|
|
|
name = jQuery.camelCase( name );
|
|
|
|
if ( name in thisCache ) {
|
|
|
|
name = [ name ];
|
|
|
|
} else {
|
|
|
|
name = name.split(" ");
|
|
|
|
}
|
|
|
|
}
|
2012-10-24 18:12:28 +00:00
|
|
|
} else {
|
|
|
|
// If "name" is an array of keys...
|
|
|
|
// When data is initially created, via ("key", "val") signature,
|
|
|
|
// keys will be converted to camelCase.
|
|
|
|
// Since there is no way to tell _how_ a key was added, remove
|
|
|
|
// both plain key and camelCase key. #12786
|
|
|
|
// This will only penalize the array argument path.
|
|
|
|
name = name.concat( jQuery.map( name, jQuery.camelCase ) );
|
2011-07-11 01:42:40 +00:00
|
|
|
}
|
|
|
|
|
2012-10-16 15:15:41 +00:00
|
|
|
for ( i = 0, l = name.length; i < l; i++ ) {
|
|
|
|
delete thisCache[ name[i] ];
|
|
|
|
}
|
2009-11-25 17:09:53 +00:00
|
|
|
|
2012-10-16 15:15:41 +00:00
|
|
|
// If there is no data left in the cache, we want to continue
|
|
|
|
// and let the cache object itself get destroyed
|
|
|
|
if ( !( pvt ? isEmptyDataObject : jQuery.isEmptyObject )( thisCache ) ) {
|
|
|
|
return;
|
|
|
|
}
|
2009-12-07 04:00:31 +00:00
|
|
|
}
|
2012-10-16 15:15:41 +00:00
|
|
|
}
|
2009-12-07 04:00:31 +00:00
|
|
|
|
2012-10-16 15:15:41 +00:00
|
|
|
// See jQuery.data for more information
|
|
|
|
if ( !pvt ) {
|
|
|
|
delete cache[ id ].data;
|
2011-01-09 21:52:33 +00:00
|
|
|
|
2012-10-16 15:15:41 +00:00
|
|
|
// Don't destroy the parent cache unless the internal data object
|
|
|
|
// had been the only thing left in it
|
|
|
|
if ( !isEmptyDataObject( cache[ id ] ) ) {
|
2011-01-09 21:52:33 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-10-16 15:15:41 +00:00
|
|
|
}
|
2009-11-25 17:09:53 +00:00
|
|
|
|
2012-10-16 15:15:41 +00:00
|
|
|
// Destroy the cache
|
|
|
|
if ( isNode ) {
|
|
|
|
jQuery.cleanData( [ elem ], true );
|
2011-08-05 13:43:58 +00:00
|
|
|
|
2012-10-16 15:15:41 +00:00
|
|
|
// Use delete when supported for expandos or `cache` is not a window per isWindow (#10080)
|
|
|
|
} else if ( jQuery.support.deleteExpando || cache != cache.window ) {
|
|
|
|
delete cache[ id ];
|
2011-11-06 22:24:44 +00:00
|
|
|
|
2012-10-16 15:15:41 +00:00
|
|
|
// When all else fails, null
|
|
|
|
} else {
|
|
|
|
cache[ id ] = null;
|
|
|
|
}
|
|
|
|
}
|
2011-11-06 22:24:44 +00:00
|
|
|
|
2012-10-16 15:15:41 +00:00
|
|
|
jQuery.extend({
|
|
|
|
cache: {},
|
2011-08-05 13:43:58 +00:00
|
|
|
|
2012-10-16 15:15:41 +00:00
|
|
|
// Unique for each copy of jQuery on the page
|
|
|
|
// Non-digits removed to match rinlinejQuery
|
2012-11-26 08:20:43 +00:00
|
|
|
expando: "jQuery" + ( core_version + Math.random() ).replace( /\D/g, "" ),
|
2011-01-09 21:52:33 +00:00
|
|
|
|
2012-10-16 15:15:41 +00:00
|
|
|
// 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
|
|
|
|
},
|
2011-01-09 21:52:33 +00:00
|
|
|
|
2012-10-16 15:15:41 +00:00
|
|
|
hasData: function( elem ) {
|
|
|
|
elem = elem.nodeType ? jQuery.cache[ elem[jQuery.expando] ] : elem[ jQuery.expando ];
|
|
|
|
return !!elem && !isEmptyDataObject( elem );
|
|
|
|
},
|
2012-07-06 13:22:44 +00:00
|
|
|
|
2012-10-16 15:15:41 +00:00
|
|
|
data: function( elem, name, data ) {
|
2013-01-31 01:40:39 +00:00
|
|
|
return internalData( elem, name, data );
|
2012-10-16 15:15:41 +00:00
|
|
|
},
|
2012-07-06 13:22:44 +00:00
|
|
|
|
2012-10-16 15:15:41 +00:00
|
|
|
removeData: function( elem, name ) {
|
2013-01-31 01:40:39 +00:00
|
|
|
return internalRemoveData( elem, name );
|
2010-09-24 20:24:07 +00:00
|
|
|
},
|
|
|
|
|
2011-01-09 21:52:33 +00:00
|
|
|
// For internal use only.
|
|
|
|
_data: function( elem, name, data ) {
|
2012-10-16 15:15:41 +00:00
|
|
|
return internalData( elem, name, data, true );
|
|
|
|
},
|
|
|
|
|
|
|
|
_removeData: function( elem, name ) {
|
|
|
|
return internalRemoveData( elem, name, true );
|
2011-01-09 21:52:33 +00:00
|
|
|
},
|
|
|
|
|
2010-09-24 20:24:07 +00:00
|
|
|
// A method for determining if a DOM node can handle the data expando
|
|
|
|
acceptData: function( elem ) {
|
2013-01-11 15:04:50 +00:00
|
|
|
// Do not set data on non-element because it will not be cleared (#8335).
|
|
|
|
if ( elem.nodeType && elem.nodeType !== 1 && elem.nodeType !== 9 ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-07-06 13:22:44 +00:00
|
|
|
var noData = elem.nodeName && jQuery.noData[ elem.nodeName.toLowerCase() ];
|
2010-09-24 20:24:07 +00:00
|
|
|
|
2012-07-06 13:22:44 +00:00
|
|
|
// nodes accept data unless otherwise specified; rejection can be conditional
|
|
|
|
return !noData || noData !== true && elem.getAttribute("classid") === noData;
|
2009-11-25 17:09:53 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
jQuery.fn.extend({
|
2009-12-22 00:58:13 +00:00
|
|
|
data: function( key, value ) {
|
2012-10-31 17:55:51 +00:00
|
|
|
var attrs, name,
|
2011-12-06 20:25:38 +00:00
|
|
|
elem = this[0],
|
|
|
|
i = 0,
|
2011-09-19 20:13:57 +00:00
|
|
|
data = null;
|
2010-10-17 15:42:53 +00:00
|
|
|
|
2011-12-06 20:25:38 +00:00
|
|
|
// Gets all values
|
|
|
|
if ( key === undefined ) {
|
2010-10-17 15:42:53 +00:00
|
|
|
if ( this.length ) {
|
2011-12-06 20:25:38 +00:00
|
|
|
data = jQuery.data( elem );
|
2010-10-17 15:42:53 +00:00
|
|
|
|
2011-12-06 20:25:38 +00:00
|
|
|
if ( elem.nodeType === 1 && !jQuery._data( elem, "parsedAttrs" ) ) {
|
2012-10-31 17:55:51 +00:00
|
|
|
attrs = elem.attributes;
|
|
|
|
for ( ; i < attrs.length; i++ ) {
|
|
|
|
name = attrs[i].name;
|
2010-12-19 21:33:53 +00:00
|
|
|
|
2012-09-18 21:39:44 +00:00
|
|
|
if ( !name.indexOf( "data-" ) ) {
|
2013-01-17 22:00:29 +00:00
|
|
|
name = jQuery.camelCase( name.slice(5) );
|
2011-04-10 19:17:00 +00:00
|
|
|
|
2011-12-06 20:25:38 +00:00
|
|
|
dataAttr( elem, name, data[ name ] );
|
2010-12-03 07:19:39 +00:00
|
|
|
}
|
2010-10-17 15:42:53 +00:00
|
|
|
}
|
2011-12-06 20:25:38 +00:00
|
|
|
jQuery._data( elem, "parsedAttrs", true );
|
2010-10-17 15:42:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return data;
|
2011-12-06 20:25:38 +00:00
|
|
|
}
|
2009-12-09 21:16:18 +00:00
|
|
|
|
2011-12-06 20:25:38 +00:00
|
|
|
// Sets multiple values
|
|
|
|
if ( typeof key === "object" ) {
|
2009-12-09 21:16:18 +00:00
|
|
|
return this.each(function() {
|
|
|
|
jQuery.data( this, key );
|
|
|
|
});
|
2009-11-25 17:09:53 +00:00
|
|
|
}
|
|
|
|
|
2011-12-06 20:25:38 +00:00
|
|
|
return jQuery.access( this, function( value ) {
|
|
|
|
|
|
|
|
if ( value === undefined ) {
|
|
|
|
// Try to fetch any internally stored data first
|
2012-10-31 17:55:51 +00:00
|
|
|
return elem ? dataAttr( elem, key, jQuery.data( elem, key ) ) : null;
|
2009-11-27 19:28:42 +00:00
|
|
|
}
|
2010-07-27 17:45:32 +00:00
|
|
|
|
2011-12-06 20:25:38 +00:00
|
|
|
this.each(function() {
|
2009-11-25 17:09:53 +00:00
|
|
|
jQuery.data( this, key, value );
|
|
|
|
});
|
2012-11-06 14:53:00 +00:00
|
|
|
}, null, value, arguments.length > 1, null, true );
|
2009-11-25 17:09:53 +00:00
|
|
|
},
|
|
|
|
|
2009-12-22 00:58:13 +00:00
|
|
|
removeData: function( key ) {
|
|
|
|
return this.each(function() {
|
2009-11-25 17:09:53 +00:00
|
|
|
jQuery.removeData( this, key );
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2010-09-08 17:54:33 +00:00
|
|
|
|
2010-10-17 15:42:53 +00:00
|
|
|
function dataAttr( elem, key, data ) {
|
|
|
|
// If nothing was found internally, try to fetch any
|
|
|
|
// data from the HTML5 data-* attribute
|
|
|
|
if ( data === undefined && elem.nodeType === 1 ) {
|
2011-09-07 14:13:22 +00:00
|
|
|
|
|
|
|
var name = "data-" + key.replace( rmultiDash, "-$1" ).toLowerCase();
|
2011-04-10 19:17:00 +00:00
|
|
|
|
|
|
|
data = elem.getAttribute( name );
|
2010-10-17 15:42:53 +00:00
|
|
|
|
|
|
|
if ( typeof data === "string" ) {
|
|
|
|
try {
|
|
|
|
data = data === "true" ? true :
|
2013-01-31 01:40:39 +00:00
|
|
|
data === "false" ? false :
|
|
|
|
data === "null" ? null :
|
|
|
|
// Only convert to a number if it doesn't change the string
|
|
|
|
+data + "" === data ? +data :
|
|
|
|
rbrace.test( data ) ? jQuery.parseJSON( data ) :
|
|
|
|
data;
|
2010-10-17 15:42:53 +00:00
|
|
|
} catch( e ) {}
|
|
|
|
|
|
|
|
// Make sure we set the data so it isn't changed later
|
|
|
|
jQuery.data( elem, key, data );
|
|
|
|
|
|
|
|
} else {
|
|
|
|
data = undefined;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2011-09-19 20:13:14 +00:00
|
|
|
// checks a cache object for emptiness
|
2011-02-14 22:22:23 +00:00
|
|
|
function isEmptyDataObject( obj ) {
|
2012-07-10 01:38:11 +00:00
|
|
|
var name;
|
|
|
|
for ( name in obj ) {
|
2011-09-19 20:13:14 +00:00
|
|
|
|
|
|
|
// if the public data object is empty, the private is still empty
|
|
|
|
if ( name === "data" && jQuery.isEmptyObject( obj[name] ) ) {
|
|
|
|
continue;
|
|
|
|
}
|
2011-02-14 22:22:23 +00:00
|
|
|
if ( name !== "toJSON" ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|