2010-09-08 17:54:33 +00:00
|
|
|
(function( jQuery ) {
|
|
|
|
|
2011-04-10 19:17:00 +00:00
|
|
|
var rbrace = /^(?:\{.*\}|\[.*\])$/,
|
|
|
|
rmultiDash = /([a-z])([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 ];
|
2010-12-22 21:03:01 +00:00
|
|
|
|
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-07-11 01:42:40 +00:00
|
|
|
var thisCache, ret,
|
|
|
|
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
|
|
|
|
id = isNode ? elem[ jQuery.expando ] : elem[ jQuery.expando ] && jQuery.expando;
|
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-08-17 21:18:58 +00:00
|
|
|
if ( (!id || (pvt && id && (cache[ id ] && !cache[ id ][ internalKey ]))) && 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 ) {
|
|
|
|
elem[ jQuery.expando ] = id = ++jQuery.uuid;
|
|
|
|
} else {
|
|
|
|
id = jQuery.expando;
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
|
|
|
// TODO: This is a hack for 1.5 ONLY. Avoids exposing jQuery
|
|
|
|
// metadata on plain JS objects when the object 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 ) {
|
|
|
|
cache[ id ][ internalKey ] = jQuery.extend(cache[ id ][ internalKey ], name);
|
|
|
|
} else {
|
2010-09-22 15:52:32 +00:00
|
|
|
cache[ id ] = jQuery.extend(cache[ id ], name);
|
2011-01-09 21:52:33 +00:00
|
|
|
}
|
|
|
|
}
|
2010-09-22 15:52:32 +00:00
|
|
|
|
2011-01-09 21:52:33 +00:00
|
|
|
thisCache = cache[ id ];
|
|
|
|
|
|
|
|
// Internal jQuery data is stored in a separate object inside the object's data
|
|
|
|
// cache in order to avoid key collisions between internal data and user-defined
|
|
|
|
// data
|
|
|
|
if ( pvt ) {
|
|
|
|
if ( !thisCache[ internalKey ] ) {
|
|
|
|
thisCache[ internalKey ] = {};
|
2010-07-20 21:53:36 +00:00
|
|
|
}
|
2010-01-28 19:12:44 +00:00
|
|
|
|
2011-01-09 21:52:33 +00:00
|
|
|
thisCache = thisCache[ internalKey ];
|
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-01-17 21:22:49 +00:00
|
|
|
// TODO: This is a hack for 1.5 ONLY. It will be removed in 1.6. Users should
|
|
|
|
// not attempt to inspect the internal events object using jQuery.data, as this
|
|
|
|
// internal data object is undocumented and subject to change.
|
|
|
|
if ( name === "events" && !thisCache[name] ) {
|
|
|
|
return thisCache[ internalKey ] && thisCache[ internalKey ].events;
|
|
|
|
}
|
|
|
|
|
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-08-05 13:43:58 +00:00
|
|
|
var thisCache,
|
|
|
|
|
|
|
|
// 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
|
|
|
|
id = isNode ? elem[ jQuery.expando ] : jQuery.expando;
|
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
|
|
|
|
|
|
|
thisCache = pvt ? cache[ id ][ internalKey ] : cache[ id ];
|
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
|
|
|
|
|
|
|
// Support interoperable removal of hyphenated or camelcased keys
|
|
|
|
if ( !thisCache[ name ] ) {
|
|
|
|
name = jQuery.camelCase( name );
|
|
|
|
}
|
|
|
|
|
2009-11-25 17:09:53 +00:00
|
|
|
delete thisCache[ name ];
|
|
|
|
|
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-02-14 22:22:23 +00:00
|
|
|
if ( !isEmptyDataObject(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
|
|
|
|
if ( pvt ) {
|
|
|
|
delete cache[ id ][ internalKey ];
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var internalCache = cache[ id ][ internalKey ];
|
2009-11-25 17:09:53 +00:00
|
|
|
|
2011-01-09 21:52:33 +00:00
|
|
|
// 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-01-09 21:52:33 +00:00
|
|
|
// We destroyed the entire user cache at once because it's faster than
|
|
|
|
// iterating through each key, but we need to continue to persist internal
|
|
|
|
// data if it existed
|
|
|
|
if ( internalCache ) {
|
|
|
|
cache[ id ] = {};
|
2011-02-16 03:41:08 +00:00
|
|
|
// TODO: This is a hack for 1.5 ONLY. Avoids exposing jQuery
|
|
|
|
// metadata on plain JS objects when the object is serialized using
|
|
|
|
// JSON.stringify
|
|
|
|
if ( !isNode ) {
|
|
|
|
cache[ id ].toJSON = jQuery.noop;
|
|
|
|
}
|
|
|
|
|
2011-01-09 21:52:33 +00:00
|
|
|
cache[ id ][ internalKey ] = internalCache;
|
|
|
|
|
|
|
|
// Otherwise, we need to eliminate the expando on the node to avoid
|
|
|
|
// false lookups in the cache for entries that no longer exist
|
|
|
|
} else if ( isNode ) {
|
|
|
|
// 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 ) {
|
|
|
|
delete elem[ jQuery.expando ];
|
2010-02-13 11:57:58 +00:00
|
|
|
} else if ( elem.removeAttribute ) {
|
|
|
|
elem.removeAttribute( jQuery.expando );
|
2010-09-29 13:46:25 +00:00
|
|
|
} else {
|
2011-01-09 21:52:33 +00:00
|
|
|
elem[ jQuery.expando ] = 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 ) {
|
2010-10-22 03:18:47 +00:00
|
|
|
var 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] );
|
|
|
|
|
2010-12-03 07:19:39 +00:00
|
|
|
if ( this[0].nodeType === 1 ) {
|
2011-04-10 19:17:00 +00:00
|
|
|
var attr = this[0].attributes, name;
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
var parts = key.split(".");
|
|
|
|
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() {
|
2010-11-09 16:09:07 +00:00
|
|
|
var $this = jQuery( this ),
|
|
|
|
args = [ parts[0], value ];
|
2010-07-27 17:45:32 +00:00
|
|
|
|
|
|
|
$this.triggerHandler( "setData" + parts[1] + "!", args );
|
2009-11-25 17:09:53 +00:00
|
|
|
jQuery.data( this, key, value );
|
2010-07-27 17:45:32 +00:00
|
|
|
$this.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-05-06 18:54:47 +00:00
|
|
|
var name = "data-" + key.replace( rmultiDash, "$1-$2" ).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 :
|
|
|
|
!jQuery.isNaN( data ) ? parseFloat( 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;
|
|
|
|
}
|
|
|
|
|
2011-02-14 22:22:23 +00:00
|
|
|
// TODO: This is a hack for 1.5 ONLY to allow objects with a single toJSON
|
|
|
|
// property to be considered empty objects; this property always exists in
|
|
|
|
// order to make sure JSON.stringify does not expose internal metadata
|
|
|
|
function isEmptyDataObject( obj ) {
|
|
|
|
for ( var name in obj ) {
|
|
|
|
if ( name !== "toJSON" ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-09-08 17:54:33 +00:00
|
|
|
})( jQuery );
|