2013-08-15 18:15:49 +00:00
|
|
|
define([
|
|
|
|
"./core",
|
|
|
|
"./var/deletedIds",
|
2013-09-02 17:21:09 +00:00
|
|
|
"./data/support",
|
2013-08-15 18:15:49 +00:00
|
|
|
"./data/accepts"
|
2013-09-02 17:21:09 +00:00
|
|
|
], function( jQuery, deletedIds, support ) {
|
2013-08-15 18:15:49 +00:00
|
|
|
|
2013-09-28 15:57:46 +00:00
|
|
|
var rbrace = /(?:\{[\w\W]*\}|\[[\w\W]*\])$/,
|
2011-09-07 14:13:22 +00:00
|
|
|
rmultiDash = /([A-Z])/g;
|
2013-01-31 01:40:39 +00:00
|
|
|
|
2013-08-15 18:15:49 +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 ) {
|
|
|
|
|
|
|
|
var name = "data-" + key.replace( rmultiDash, "-$1" ).toLowerCase();
|
|
|
|
|
|
|
|
data = elem.getAttribute( name );
|
|
|
|
|
|
|
|
if ( typeof data === "string" ) {
|
|
|
|
try {
|
|
|
|
data = data === "true" ? true :
|
|
|
|
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;
|
|
|
|
} catch( e ) {}
|
|
|
|
|
|
|
|
// Make sure we set the data so it isn't changed later
|
|
|
|
jQuery.data( elem, key, data );
|
|
|
|
|
|
|
|
} else {
|
|
|
|
data = undefined;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
// checks a cache object for emptiness
|
|
|
|
function isEmptyDataObject( obj ) {
|
|
|
|
var name;
|
|
|
|
for ( name in obj ) {
|
|
|
|
|
|
|
|
// if the public data object is empty, the private is still empty
|
|
|
|
if ( name === "data" && jQuery.isEmptyObject( obj[name] ) ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ( name !== "toJSON" ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-01-29 00:04:58 +00:00
|
|
|
function internalData( elem, name, data, pvt /* Internal Use Only */ ){
|
2012-10-16 15:15:41 +00:00
|
|
|
if ( !jQuery.acceptData( elem ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-12 05:45:35 +00:00
|
|
|
var ret, thisCache,
|
2012-10-16 15:15:41 +00:00
|
|
|
internalKey = jQuery.expando,
|
|
|
|
|
|
|
|
// 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
|
2013-02-12 05:45:35 +00:00
|
|
|
if ( (!id || !cache[id] || (!pvt && !cache[id].data)) && data === undefined && typeof name === "string" ) {
|
2012-10-16 15:15:41 +00:00
|
|
|
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 ) {
|
2013-08-15 18:15:49 +00:00
|
|
|
id = elem[ internalKey ] = 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 ] ) {
|
2013-02-12 05:45:35 +00:00
|
|
|
// Avoid exposing jQuery metadata on plain JS objects when the object
|
2012-10-16 15:15:41 +00:00
|
|
|
// is serialized using JSON.stringify
|
2013-02-12 05:45:35 +00:00
|
|
|
cache[ id ] = isNode ? {} : { toJSON: jQuery.noop };
|
2012-10-16 15:15:41 +00:00
|
|
|
}
|
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
|
2013-02-12 05:45:35 +00:00
|
|
|
if ( typeof name === "string" ) {
|
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
|
|
|
|
2013-02-12 05:45:35 +00:00
|
|
|
var thisCache, i,
|
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
|
|
|
}
|
|
|
|
|
2013-02-12 05:45:35 +00:00
|
|
|
i = name.length;
|
|
|
|
while ( i-- ) {
|
2012-10-16 15:15:41 +00:00
|
|
|
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
|
2013-02-12 05:45:35 +00:00
|
|
|
if ( pvt ? !isEmptyDataObject(thisCache) : !jQuery.isEmptyObject(thisCache) ) {
|
2012-10-16 15:15:41 +00:00
|
|
|
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)
|
2013-03-13 23:23:36 +00:00
|
|
|
/* jshint eqeqeq: false */
|
2013-09-02 17:21:09 +00:00
|
|
|
} else if ( support.deleteExpando || cache != cache.window ) {
|
2013-03-13 23:23:36 +00:00
|
|
|
/* jshint eqeqeq: true */
|
2012-10-16 15:15:41 +00:00
|
|
|
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
|
|
|
// The following elements throw uncatchable exceptions if you
|
|
|
|
// attempt to add expando properties to them.
|
|
|
|
noData: {
|
2013-02-12 05:45:35 +00:00
|
|
|
"applet": true,
|
2012-10-16 15:15:41 +00:00
|
|
|
"embed": true,
|
|
|
|
// Ban all objects except for Flash (which handle expandos)
|
2013-02-12 05:45:35 +00:00
|
|
|
"object": "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
|
2012-10-16 15:15:41 +00:00
|
|
|
},
|
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 );
|
|
|
|
},
|
2013-01-29 00:04:58 +00:00
|
|
|
|
2012-10-16 15:15:41 +00:00
|
|
|
_removeData: function( elem, name ) {
|
|
|
|
return internalRemoveData( elem, name, true );
|
2009-11-25 17:09:53 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
jQuery.fn.extend({
|
2009-12-22 00:58:13 +00:00
|
|
|
data: function( key, value ) {
|
2013-09-28 15:57:46 +00:00
|
|
|
var i, name,
|
2013-02-12 05:45:35 +00:00
|
|
|
data = null,
|
2013-09-28 15:57:46 +00:00
|
|
|
elem = this[0],
|
|
|
|
attrs = elem && elem.attributes;
|
2013-02-12 05:45:35 +00:00
|
|
|
|
|
|
|
// Special expections of .data basically thwart jQuery.access,
|
|
|
|
// so implement the relevant behavior ourselves
|
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" ) ) {
|
2013-09-28 15:57:46 +00:00
|
|
|
i = attrs.length;
|
|
|
|
while ( i-- ) {
|
2012-10-31 17:55:51 +00:00
|
|
|
name = attrs[i].name;
|
2010-12-19 21:33:53 +00:00
|
|
|
|
2013-02-12 05:45:35 +00:00
|
|
|
if ( name.indexOf("data-") === 0 ) {
|
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
|
|
|
}
|
|
|
|
|
2013-02-12 05:45:35 +00:00
|
|
|
return arguments.length > 1 ?
|
2010-07-27 17:45:32 +00:00
|
|
|
|
2013-02-12 05:45:35 +00:00
|
|
|
// Sets one value
|
2011-12-06 20:25:38 +00:00
|
|
|
this.each(function() {
|
2009-11-25 17:09:53 +00:00
|
|
|
jQuery.data( this, key, value );
|
2013-02-12 05:45:35 +00:00
|
|
|
}) :
|
|
|
|
|
|
|
|
// Gets one value
|
|
|
|
// Try to fetch any internally stored data first
|
|
|
|
elem ? dataAttr( elem, key, jQuery.data( elem, key ) ) : null;
|
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
|
|
|
|
2013-09-09 01:25:27 +00:00
|
|
|
return jQuery;
|
2013-08-15 18:15:49 +00:00
|
|
|
});
|