2010-09-08 17:54:33 +00:00
|
|
|
(function( jQuery ) {
|
|
|
|
|
2011-04-10 19:17:00 +00:00
|
|
|
var rbrace = /^(?:\{.*\}|\[.*\])$/,
|
2011-09-07 14:13:22 +00:00
|
|
|
rmultiDash = /([A-Z])/g;
|
2009-11-25 17:09:53 +00:00
|
|
|
|
|
|
|
jQuery.extend({
|
|
|
|
cache: {},
|
2010-04-24 21:15:45 +00:00
|
|
|
|
|
|
|
// Please use with caution
|
|
|
|
uuid: 0,
|
|
|
|
|
2010-12-19 21:33:53 +00:00
|
|
|
// Unique for each copy of jQuery on the page
|
2010-10-11 16:54:00 +00:00
|
|
|
// Non-digits removed to match rinlinejQuery
|
|
|
|
expando: "jQuery" + ( jQuery.fn.jquery + Math.random() ).replace( /\D/g, "" ),
|
2009-11-25 17:09:53 +00:00
|
|
|
|
2009-12-07 04:00:31 +00:00
|
|
|
// The following elements throw uncatchable exceptions if you
|
|
|
|
// attempt to add expando properties to them.
|
|
|
|
noData: {
|
|
|
|
"embed": true,
|
2010-09-24 20:24:07 +00:00
|
|
|
// Ban all objects except for Flash (which handle expandos)
|
|
|
|
"object": "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",
|
2009-12-07 04:00:31 +00:00
|
|
|
"applet": true
|
|
|
|
},
|
|
|
|
|
2010-12-19 21:33:53 +00:00
|
|
|
hasData: function( elem ) {
|
2011-01-09 21:52:33 +00:00
|
|
|
elem = elem.nodeType ? jQuery.cache[ elem[jQuery.expando] ] : elem[ jQuery.expando ];
|
2011-02-14 22:22:23 +00:00
|
|
|
return !!elem && !isEmptyDataObject( elem );
|
2010-12-19 21:33:53 +00:00
|
|
|
},
|
|
|
|
|
2011-01-09 21:52:33 +00:00
|
|
|
data: function( elem, name, data, pvt /* Internal Use Only */ ) {
|
2010-09-24 20:24:07 +00:00
|
|
|
if ( !jQuery.acceptData( elem ) ) {
|
2009-12-07 04:00:31 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-10-27 02:56:26 +00:00
|
|
|
var privateCache, thisCache, ret,
|
2011-07-11 01:42:40 +00:00
|
|
|
internalKey = jQuery.expando,
|
|
|
|
getByName = typeof name === "string",
|
2011-01-09 21:52:33 +00:00
|
|
|
|
|
|
|
// 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,
|
2009-11-25 17:09:53 +00:00
|
|
|
|
2011-01-09 21:52:33 +00:00
|
|
|
// 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
|
2011-11-04 20:57:02 +00:00
|
|
|
id = isNode ? elem[ internalKey ] : elem[ internalKey ] && internalKey,
|
2011-10-27 02:56:26 +00:00
|
|
|
isEvents = name === "events";
|
2009-11-25 17:09:53 +00:00
|
|
|
|
2011-01-09 21:52:33 +00:00
|
|
|
// Avoid doing any more work than we need to when trying to get data on an
|
|
|
|
// object that has no data at all
|
2011-10-27 02:56:26 +00:00
|
|
|
if ( (!id || !cache[id] || (!isEvents && !pvt && !cache[id].data)) && getByName && data === undefined ) {
|
2010-02-26 17:35:04 +00:00
|
|
|
return;
|
2009-11-25 17:09:53 +00:00
|
|
|
}
|
|
|
|
|
2011-01-09 21:52:33 +00:00
|
|
|
if ( !id ) {
|
|
|
|
// Only DOM nodes need a new unique ID for each element since their data
|
|
|
|
// ends up in the global cache
|
|
|
|
if ( isNode ) {
|
2011-11-04 20:57:02 +00:00
|
|
|
elem[ internalKey ] = id = ++jQuery.uuid;
|
2011-01-09 21:52:33 +00:00
|
|
|
} else {
|
2011-11-04 20:57:02 +00:00
|
|
|
id = internalKey;
|
2011-01-09 21:52:33 +00:00
|
|
|
}
|
|
|
|
}
|
2010-02-27 14:49:58 +00:00
|
|
|
|
2011-01-09 21:52:33 +00:00
|
|
|
if ( !cache[ id ] ) {
|
2011-02-08 18:13:27 +00:00
|
|
|
cache[ id ] = {};
|
2011-02-14 22:22:23 +00:00
|
|
|
|
2011-10-27 02:56:26 +00:00
|
|
|
// Avoids exposing jQuery metadata on plain JS objects when the object
|
2011-09-19 20:13:14 +00:00
|
|
|
// is serialized using JSON.stringify
|
2011-02-16 03:41:08 +00:00
|
|
|
if ( !isNode ) {
|
|
|
|
cache[ id ].toJSON = jQuery.noop;
|
|
|
|
}
|
2009-11-25 17:09:53 +00:00
|
|
|
}
|
|
|
|
|
2011-01-09 21:52:33 +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
|
2011-02-07 16:48:38 +00:00
|
|
|
if ( typeof name === "object" || typeof name === "function" ) {
|
2011-01-09 21:52:33 +00:00
|
|
|
if ( pvt ) {
|
2011-09-19 20:13:14 +00:00
|
|
|
cache[ id ] = jQuery.extend( cache[ id ], name );
|
2011-01-09 21:52:33 +00:00
|
|
|
} else {
|
2011-09-19 20:13:14 +00:00
|
|
|
cache[ id ].data = jQuery.extend( cache[ id ].data, name );
|
2011-01-09 21:52:33 +00:00
|
|
|
}
|
|
|
|
}
|
2010-09-22 15:52:32 +00:00
|
|
|
|
2011-10-27 02:56:26 +00:00
|
|
|
privateCache = thisCache = cache[ id ];
|
2011-01-09 21:52:33 +00:00
|
|
|
|
2011-09-19 20:13:14 +00:00
|
|
|
// jQuery data() is stored in a separate object inside the object's internal data
|
2011-01-09 21:52:33 +00:00
|
|
|
// cache in order to avoid key collisions between internal data and user-defined
|
2011-09-19 20:13:14 +00:00
|
|
|
// data.
|
|
|
|
if ( !pvt ) {
|
|
|
|
if ( !thisCache.data ) {
|
|
|
|
thisCache.data = {};
|
2010-07-20 21:53:36 +00:00
|
|
|
}
|
2010-01-28 19:12:44 +00:00
|
|
|
|
2011-09-19 20:13:14 +00:00
|
|
|
thisCache = thisCache.data;
|
2009-11-25 17:09:53 +00:00
|
|
|
}
|
2009-12-09 21:16:18 +00:00
|
|
|
|
2009-11-25 17:09:53 +00:00
|
|
|
if ( data !== undefined ) {
|
2011-05-10 15:56:42 +00:00
|
|
|
thisCache[ jQuery.camelCase( name ) ] = data;
|
2009-11-25 17:09:53 +00:00
|
|
|
}
|
2009-12-09 21:16:18 +00:00
|
|
|
|
2011-10-26 21:04:15 +00:00
|
|
|
// 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.
|
2011-10-27 02:56:26 +00:00
|
|
|
if ( isEvents && !thisCache[ name ] ) {
|
|
|
|
return privateCache.events;
|
2011-01-17 21:22:49 +00:00
|
|
|
}
|
|
|
|
|
2011-07-11 01:42:40 +00:00
|
|
|
// Check for both converted-to-camel and non-converted data property names
|
|
|
|
// If a data property was specified
|
|
|
|
if ( getByName ) {
|
|
|
|
|
2011-07-25 18:17:59 +00:00
|
|
|
// First Try to find as-is property data
|
|
|
|
ret = thisCache[ name ];
|
2011-07-11 01:42:40 +00:00
|
|
|
|
2011-07-25 18:17:59 +00:00
|
|
|
// Test for null|undefined property data
|
2011-07-11 01:42:40 +00:00
|
|
|
if ( ret == null ) {
|
|
|
|
|
2011-07-25 18:17:59 +00:00
|
|
|
// Try to find the camelCased property
|
|
|
|
ret = thisCache[ jQuery.camelCase( name ) ];
|
2011-07-11 01:42:40 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ret = thisCache;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2009-11-25 17:09:53 +00:00
|
|
|
},
|
|
|
|
|
2011-01-09 21:52:33 +00:00
|
|
|
removeData: function( elem, name, pvt /* Internal Use Only */ ) {
|
2010-09-24 20:24:07 +00:00
|
|
|
if ( !jQuery.acceptData( elem ) ) {
|
2009-12-07 04:00:31 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-09-20 01:16:20 +00:00
|
|
|
var thisCache, i, l,
|
2011-08-05 13:43:58 +00:00
|
|
|
|
|
|
|
// Reference to internal data cache key
|
|
|
|
internalKey = jQuery.expando,
|
|
|
|
|
|
|
|
isNode = elem.nodeType,
|
2011-01-09 21:52:33 +00:00
|
|
|
|
|
|
|
// See jQuery.data for more information
|
|
|
|
cache = isNode ? jQuery.cache : elem,
|
|
|
|
|
|
|
|
// See jQuery.data for more information
|
2011-11-04 20:57:02 +00:00
|
|
|
id = isNode ? elem[ internalKey ] : internalKey;
|
2009-11-25 17:09:53 +00:00
|
|
|
|
2011-01-09 21:52:33 +00:00
|
|
|
// If there is already no cache entry for this object, there is no
|
|
|
|
// purpose in continuing
|
|
|
|
if ( !cache[ id ] ) {
|
|
|
|
return;
|
|
|
|
}
|
2009-11-25 17:09:53 +00:00
|
|
|
|
|
|
|
if ( name ) {
|
2011-08-05 13:43:58 +00:00
|
|
|
|
2011-09-19 20:13:14 +00:00
|
|
|
thisCache = pvt ? cache[ id ] : cache[ id ].data;
|
2011-01-09 21:52:33 +00:00
|
|
|
|
2009-11-25 17:09:53 +00:00
|
|
|
if ( thisCache ) {
|
2011-08-05 13:43:58 +00:00
|
|
|
|
2011-11-06 22:24:44 +00:00
|
|
|
// Support array or space separated string names for data keys
|
|
|
|
if ( !jQuery.isArray( name ) ) {
|
|
|
|
|
|
|
|
// try the string as a key before any manipulation
|
2011-09-20 01:16:20 +00:00
|
|
|
if ( name in thisCache ) {
|
|
|
|
name = [ name ];
|
|
|
|
} else {
|
2011-11-06 22:24:44 +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( " " );
|
|
|
|
}
|
2011-09-20 01:16:20 +00:00
|
|
|
}
|
2011-08-05 13:43:58 +00:00
|
|
|
}
|
|
|
|
|
2011-09-20 01:16:20 +00:00
|
|
|
for ( i = 0, l = name.length; i < l; i++ ) {
|
|
|
|
delete thisCache[ name[i] ];
|
|
|
|
}
|
2009-11-25 17:09:53 +00:00
|
|
|
|
2011-01-09 21:52:33 +00:00
|
|
|
// If there is no data left in the cache, we want to continue
|
|
|
|
// and let the cache object itself get destroyed
|
2011-09-19 20:13:14 +00:00
|
|
|
if ( !( pvt ? isEmptyDataObject : jQuery.isEmptyObject )( thisCache ) ) {
|
2011-01-09 21:52:33 +00:00
|
|
|
return;
|
2009-11-25 17:09:53 +00:00
|
|
|
}
|
|
|
|
}
|
2011-01-09 21:52:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// See jQuery.data for more information
|
2011-09-19 20:13:14 +00:00
|
|
|
if ( !pvt ) {
|
|
|
|
delete cache[ id ].data;
|
2011-01-09 21:52:33 +00:00
|
|
|
|
|
|
|
// Don't destroy the parent cache unless the internal data object
|
|
|
|
// had been the only thing left in it
|
2011-02-14 22:22:23 +00:00
|
|
|
if ( !isEmptyDataObject(cache[ id ]) ) {
|
2011-01-09 21:52:33 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Browsers that fail expando deletion also refuse to delete expandos on
|
|
|
|
// the window, but it will allow it on all other JS objects; other browsers
|
|
|
|
// don't care
|
2011-08-18 14:17:12 +00:00
|
|
|
// Ensure that `cache` is not a window object #10080
|
|
|
|
if ( jQuery.support.deleteExpando || !cache.setInterval ) {
|
2011-01-09 21:52:33 +00:00
|
|
|
delete cache[ id ];
|
2009-11-25 17:09:53 +00:00
|
|
|
} else {
|
2011-01-09 21:52:33 +00:00
|
|
|
cache[ id ] = null;
|
|
|
|
}
|
2010-02-13 11:57:58 +00:00
|
|
|
|
2011-09-19 20:13:14 +00:00
|
|
|
// We destroyed the cache and need to eliminate the expando on the node to avoid
|
2011-01-09 21:52:33 +00:00
|
|
|
// false lookups in the cache for entries that no longer exist
|
2011-09-19 20:13:14 +00:00
|
|
|
if ( isNode ) {
|
2011-01-09 21:52:33 +00:00
|
|
|
// IE does not allow us to delete expando properties from nodes,
|
|
|
|
// nor does it have a removeAttribute function on Document nodes;
|
|
|
|
// we must handle all of these cases
|
|
|
|
if ( jQuery.support.deleteExpando ) {
|
2011-11-04 20:57:02 +00:00
|
|
|
delete elem[ internalKey ];
|
2010-02-13 11:57:58 +00:00
|
|
|
} else if ( elem.removeAttribute ) {
|
2011-11-04 20:57:02 +00:00
|
|
|
elem.removeAttribute( internalKey );
|
2010-09-29 13:46:25 +00:00
|
|
|
} else {
|
2011-11-04 20:57:02 +00:00
|
|
|
elem[ internalKey ] = null;
|
2010-02-27 14:49:58 +00:00
|
|
|
}
|
2009-11-25 17:09:53 +00:00
|
|
|
}
|
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 ) {
|
|
|
|
return jQuery.data( elem, name, data, true );
|
|
|
|
},
|
|
|
|
|
2010-09-24 20:24:07 +00:00
|
|
|
// A method for determining if a DOM node can handle the data expando
|
|
|
|
acceptData: function( elem ) {
|
|
|
|
if ( elem.nodeName ) {
|
2010-10-05 14:32:57 +00:00
|
|
|
var match = jQuery.noData[ elem.nodeName.toLowerCase() ];
|
2010-09-24 20:24:07 +00:00
|
|
|
|
|
|
|
if ( match ) {
|
|
|
|
return !(match === true || elem.getAttribute("classid") !== match);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2009-11-25 17:09:53 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
jQuery.fn.extend({
|
2009-12-22 00:58:13 +00:00
|
|
|
data: function( key, value ) {
|
2011-09-19 20:13:57 +00:00
|
|
|
var parts, attr, name,
|
|
|
|
data = null;
|
2010-10-17 15:42:53 +00:00
|
|
|
|
2010-10-22 03:18:47 +00:00
|
|
|
if ( typeof key === "undefined" ) {
|
2010-10-17 15:42:53 +00:00
|
|
|
if ( this.length ) {
|
|
|
|
data = jQuery.data( this[0] );
|
|
|
|
|
2011-09-19 20:13:57 +00:00
|
|
|
if ( this[0].nodeType === 1 && !jQuery._data( this[0], "parsedAttrs" ) ) {
|
|
|
|
attr = this[0].attributes;
|
2010-12-03 07:19:39 +00:00
|
|
|
for ( var i = 0, l = attr.length; i < l; i++ ) {
|
|
|
|
name = attr[i].name;
|
2010-12-19 21:33:53 +00:00
|
|
|
|
2010-12-03 07:19:39 +00:00
|
|
|
if ( name.indexOf( "data-" ) === 0 ) {
|
2011-04-10 19:17:00 +00:00
|
|
|
name = jQuery.camelCase( name.substring(5) );
|
|
|
|
|
2010-12-03 07:19:39 +00:00
|
|
|
dataAttr( this[0], name, data[ name ] );
|
|
|
|
}
|
2010-10-17 15:42:53 +00:00
|
|
|
}
|
2011-09-19 20:13:57 +00:00
|
|
|
jQuery._data( this[0], "parsedAttrs", true );
|
2010-10-17 15:42:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return data;
|
2009-12-09 21:16:18 +00:00
|
|
|
|
|
|
|
} else if ( typeof key === "object" ) {
|
|
|
|
return this.each(function() {
|
|
|
|
jQuery.data( this, key );
|
|
|
|
});
|
2009-11-25 17:09:53 +00:00
|
|
|
}
|
|
|
|
|
2011-09-19 20:13:57 +00:00
|
|
|
parts = key.split(".");
|
2009-11-25 17:09:53 +00:00
|
|
|
parts[1] = parts[1] ? "." + parts[1] : "";
|
|
|
|
|
|
|
|
if ( value === undefined ) {
|
2010-10-22 03:18:47 +00:00
|
|
|
data = this.triggerHandler("getData" + parts[1] + "!", [parts[0]]);
|
2009-11-25 17:09:53 +00:00
|
|
|
|
2010-09-20 21:47:41 +00:00
|
|
|
// Try to fetch any internally stored data first
|
2009-11-27 19:28:42 +00:00
|
|
|
if ( data === undefined && this.length ) {
|
2009-11-25 17:09:53 +00:00
|
|
|
data = jQuery.data( this[0], key );
|
2010-10-17 15:42:53 +00:00
|
|
|
data = dataAttr( this[0], key, data );
|
2009-11-27 19:28:42 +00:00
|
|
|
}
|
2010-07-27 17:45:32 +00:00
|
|
|
|
2009-11-25 17:09:53 +00:00
|
|
|
return data === undefined && parts[1] ?
|
|
|
|
this.data( parts[0] ) :
|
|
|
|
data;
|
2010-07-27 17:45:32 +00:00
|
|
|
|
2009-11-27 19:28:42 +00:00
|
|
|
} else {
|
2010-07-27 17:45:32 +00:00
|
|
|
return this.each(function() {
|
2011-11-06 22:54:21 +00:00
|
|
|
var self = jQuery( this ),
|
2010-11-09 16:09:07 +00:00
|
|
|
args = [ parts[0], value ];
|
2010-07-27 17:45:32 +00:00
|
|
|
|
2011-11-06 22:54:21 +00:00
|
|
|
self.triggerHandler( "setData" + parts[1] + "!", args );
|
2009-11-25 17:09:53 +00:00
|
|
|
jQuery.data( this, key, value );
|
2011-11-06 22:54:21 +00:00
|
|
|
self.triggerHandler( "changeData" + parts[1] + "!", args );
|
2009-11-25 17:09:53 +00:00
|
|
|
});
|
2009-11-27 19:28:42 +00:00
|
|
|
}
|
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 :
|
|
|
|
data === "false" ? false :
|
|
|
|
data === "null" ? null :
|
2011-10-12 01:04:22 +00:00
|
|
|
jQuery.isNumeric( data ) ? parseFloat( data ) :
|
2010-10-17 15:42:53 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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 ) {
|
|
|
|
for ( var 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;
|
|
|
|
}
|
|
|
|
|
2010-09-08 17:54:33 +00:00
|
|
|
})( jQuery );
|