mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
No ticket: keep jquery.min.js.gz under 32K
This commit is contained in:
parent
03ab9b9f90
commit
941d2e055b
52
src/data.js
52
src/data.js
@ -6,9 +6,8 @@ function internalData( elem, name, data, pvt /* Internal Use Only */ ){
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var thisCache, ret,
|
var ret, thisCache,
|
||||||
internalKey = jQuery.expando,
|
internalKey = jQuery.expando,
|
||||||
getByName = typeof name === "string",
|
|
||||||
|
|
||||||
// We have to handle DOM nodes and JS objects differently because IE6-7
|
// We have to handle DOM nodes and JS objects differently because IE6-7
|
||||||
// can't GC object references properly across the DOM-JS boundary
|
// can't GC object references properly across the DOM-JS boundary
|
||||||
@ -24,7 +23,7 @@ function internalData( elem, name, data, pvt /* Internal Use Only */ ){
|
|||||||
|
|
||||||
// Avoid doing any more work than we need to when trying to get data on an
|
// Avoid doing any more work than we need to when trying to get data on an
|
||||||
// object that has no data at all
|
// object that has no data at all
|
||||||
if ( (!id || !cache[id] || (!pvt && !cache[id].data)) && getByName && data === undefined ) {
|
if ( (!id || !cache[id] || (!pvt && !cache[id].data)) && data === undefined && typeof name === "string" ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,20 +31,16 @@ function internalData( elem, name, data, pvt /* Internal Use Only */ ){
|
|||||||
// Only DOM nodes need a new unique ID for each element since their data
|
// Only DOM nodes need a new unique ID for each element since their data
|
||||||
// ends up in the global cache
|
// ends up in the global cache
|
||||||
if ( isNode ) {
|
if ( isNode ) {
|
||||||
elem[ internalKey ] = id = core_deletedIds.pop() || jQuery.guid++;
|
id = elem[ internalKey ] = core_deletedIds.pop() || jQuery.guid++;
|
||||||
} else {
|
} else {
|
||||||
id = internalKey;
|
id = internalKey;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !cache[ id ] ) {
|
if ( !cache[ id ] ) {
|
||||||
cache[ id ] = {};
|
// Avoid exposing jQuery metadata on plain JS objects when the object
|
||||||
|
|
||||||
// Avoids exposing jQuery metadata on plain JS objects when the object
|
|
||||||
// is serialized using JSON.stringify
|
// is serialized using JSON.stringify
|
||||||
if ( !isNode ) {
|
cache[ id ] = isNode ? {} : { toJSON: jQuery.noop };
|
||||||
cache[ id ].toJSON = jQuery.noop;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// An object can be passed to jQuery.data instead of a key/value pair; this gets
|
// An object can be passed to jQuery.data instead of a key/value pair; this gets
|
||||||
@ -77,7 +72,7 @@ function internalData( elem, name, data, pvt /* Internal Use Only */ ){
|
|||||||
|
|
||||||
// Check for both converted-to-camel and non-converted data property names
|
// Check for both converted-to-camel and non-converted data property names
|
||||||
// If a data property was specified
|
// If a data property was specified
|
||||||
if ( getByName ) {
|
if ( typeof name === "string" ) {
|
||||||
|
|
||||||
// First Try to find as-is property data
|
// First Try to find as-is property data
|
||||||
ret = thisCache[ name ];
|
ret = thisCache[ name ];
|
||||||
@ -100,7 +95,7 @@ function internalRemoveData( elem, name, pvt ) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var i, l, thisCache,
|
var thisCache, i,
|
||||||
isNode = elem.nodeType,
|
isNode = elem.nodeType,
|
||||||
|
|
||||||
// See jQuery.data for more information
|
// See jQuery.data for more information
|
||||||
@ -145,13 +140,14 @@ function internalRemoveData( elem, name, pvt ) {
|
|||||||
name = name.concat( jQuery.map( name, jQuery.camelCase ) );
|
name = name.concat( jQuery.map( name, jQuery.camelCase ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( i = 0, l = name.length; i < l; i++ ) {
|
i = name.length;
|
||||||
|
while ( i-- ) {
|
||||||
delete thisCache[ name[i] ];
|
delete thisCache[ name[i] ];
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there is no data left in the cache, we want to continue
|
// If there is no data left in the cache, we want to continue
|
||||||
// and let the cache object itself get destroyed
|
// and let the cache object itself get destroyed
|
||||||
if ( !( pvt ? isEmptyDataObject : jQuery.isEmptyObject )( thisCache ) ) {
|
if ( pvt ? !isEmptyDataObject(thisCache) : !jQuery.isEmptyObject(thisCache) ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -192,10 +188,10 @@ jQuery.extend({
|
|||||||
// The following elements throw uncatchable exceptions if you
|
// The following elements throw uncatchable exceptions if you
|
||||||
// attempt to add expando properties to them.
|
// attempt to add expando properties to them.
|
||||||
noData: {
|
noData: {
|
||||||
|
"applet": true,
|
||||||
"embed": true,
|
"embed": true,
|
||||||
// Ban all objects except for Flash (which handle expandos)
|
// Ban all objects except for Flash (which handle expandos)
|
||||||
"object": "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",
|
"object": "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
|
||||||
"applet": true
|
|
||||||
},
|
},
|
||||||
|
|
||||||
hasData: function( elem ) {
|
hasData: function( elem ) {
|
||||||
@ -237,9 +233,12 @@ jQuery.extend({
|
|||||||
jQuery.fn.extend({
|
jQuery.fn.extend({
|
||||||
data: function( key, value ) {
|
data: function( key, value ) {
|
||||||
var attrs, name,
|
var attrs, name,
|
||||||
elem = this[0],
|
data = null,
|
||||||
i = 0,
|
i = 0,
|
||||||
data = null;
|
elem = this[0];
|
||||||
|
|
||||||
|
// Special expections of .data basically thwart jQuery.access,
|
||||||
|
// so implement the relevant behavior ourselves
|
||||||
|
|
||||||
// Gets all values
|
// Gets all values
|
||||||
if ( key === undefined ) {
|
if ( key === undefined ) {
|
||||||
@ -251,7 +250,7 @@ jQuery.fn.extend({
|
|||||||
for ( ; i < attrs.length; i++ ) {
|
for ( ; i < attrs.length; i++ ) {
|
||||||
name = attrs[i].name;
|
name = attrs[i].name;
|
||||||
|
|
||||||
if ( !name.indexOf( "data-" ) ) {
|
if ( name.indexOf("data-") === 0 ) {
|
||||||
name = jQuery.camelCase( name.slice(5) );
|
name = jQuery.camelCase( name.slice(5) );
|
||||||
|
|
||||||
dataAttr( elem, name, data[ name ] );
|
dataAttr( elem, name, data[ name ] );
|
||||||
@ -271,17 +270,16 @@ jQuery.fn.extend({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return jQuery.access( this, function( value ) {
|
return arguments.length > 1 ?
|
||||||
|
|
||||||
if ( value === undefined ) {
|
|
||||||
// Try to fetch any internally stored data first
|
|
||||||
return elem ? dataAttr( elem, key, jQuery.data( elem, key ) ) : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Sets one value
|
||||||
this.each(function() {
|
this.each(function() {
|
||||||
jQuery.data( this, key, value );
|
jQuery.data( this, key, value );
|
||||||
});
|
}) :
|
||||||
}, null, value, arguments.length > 1, null, true );
|
|
||||||
|
// Gets one value
|
||||||
|
// Try to fetch any internally stored data first
|
||||||
|
elem ? dataAttr( elem, key, jQuery.data( elem, key ) ) : null;
|
||||||
},
|
},
|
||||||
|
|
||||||
removeData: function( key ) {
|
removeData: function( key ) {
|
||||||
|
Loading…
Reference in New Issue
Block a user