summaryrefslogtreecommitdiffstats
path: root/js/vendor/jquery/src/data/Data.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/vendor/jquery/src/data/Data.js')
-rw-r--r--js/vendor/jquery/src/data/Data.js167
1 files changed, 93 insertions, 74 deletions
diff --git a/js/vendor/jquery/src/data/Data.js b/js/vendor/jquery/src/data/Data.js
index 85afd64f5..0e29c1fc6 100644
--- a/js/vendor/jquery/src/data/Data.js
+++ b/js/vendor/jquery/src/data/Data.js
@@ -1,69 +1,80 @@
-define([
+define( [
"../core",
"../var/rnotwhite",
- "./accepts"
-], function( jQuery, rnotwhite ) {
+ "./var/acceptData"
+], function( jQuery, rnotwhite, acceptData ) {
function Data() {
- // Support: Android<4,
- // Old WebKit does not have Object.preventExtensions/freeze method,
- // return new empty object instead with no [[set]] accessor
- Object.defineProperty( this.cache = {}, 0, {
- get: function() {
- return {};
- }
- });
-
this.expando = jQuery.expando + Data.uid++;
}
Data.uid = 1;
-Data.accepts = jQuery.acceptData;
Data.prototype = {
- key: function( owner ) {
+
+ register: function( owner, initial ) {
+ var value = initial || {};
+
+ // If it is a node unlikely to be stringify-ed or looped over
+ // use plain assignment
+ if ( owner.nodeType ) {
+ owner[ this.expando ] = value;
+
+ // Otherwise secure it in a non-enumerable, non-writable property
+ // configurability must be true to allow the property to be
+ // deleted with the delete operator
+ } else {
+ Object.defineProperty( owner, this.expando, {
+ value: value,
+ writable: true,
+ configurable: true
+ } );
+ }
+ return owner[ this.expando ];
+ },
+ cache: function( owner ) {
+
// We can accept data for non-element nodes in modern browsers,
// but we should not, see #8335.
- // Always return the key for a frozen object.
- if ( !Data.accepts( owner ) ) {
- return 0;
+ // Always return an empty object.
+ if ( !acceptData( owner ) ) {
+ return {};
}
- var descriptor = {},
- // Check if the owner object already has a cache key
- unlock = owner[ this.expando ];
+ // Check if the owner object already has a cache
+ var value = owner[ this.expando ];
// If not, create one
- if ( !unlock ) {
- unlock = Data.uid++;
-
- // Secure it in a non-enumerable, non-writable property
- try {
- descriptor[ this.expando ] = { value: unlock };
- Object.defineProperties( owner, descriptor );
-
- // Support: Android<4
- // Fallback to a less secure definition
- } catch ( e ) {
- descriptor[ this.expando ] = unlock;
- jQuery.extend( owner, descriptor );
+ if ( !value ) {
+ value = {};
+
+ // We can accept data for non-element nodes in modern browsers,
+ // but we should not, see #8335.
+ // Always return an empty object.
+ if ( acceptData( owner ) ) {
+
+ // If it is a node unlikely to be stringify-ed or looped over
+ // use plain assignment
+ if ( owner.nodeType ) {
+ owner[ this.expando ] = value;
+
+ // Otherwise secure it in a non-enumerable property
+ // configurable must be true to allow the property to be
+ // deleted when data is removed
+ } else {
+ Object.defineProperty( owner, this.expando, {
+ value: value,
+ configurable: true
+ } );
+ }
}
}
- // Ensure the cache object
- if ( !this.cache[ unlock ] ) {
- this.cache[ unlock ] = {};
- }
-
- return unlock;
+ return value;
},
set: function( owner, data, value ) {
var prop,
- // There may be an unlock assigned to this node,
- // if there is no entry for this "owner", create one inline
- // and set the unlock as though an owner entry had always existed
- unlock = this.key( owner ),
- cache = this.cache[ unlock ];
+ cache = this.cache( owner );
// Handle: [ owner, key, value ] args
if ( typeof data === "string" ) {
@@ -71,30 +82,22 @@ Data.prototype = {
// Handle: [ owner, { properties } ] args
} else {
- // Fresh assignments by object are shallow copied
- if ( jQuery.isEmptyObject( cache ) ) {
- jQuery.extend( this.cache[ unlock ], data );
- // Otherwise, copy the properties one-by-one to the cache object
- } else {
- for ( prop in data ) {
- cache[ prop ] = data[ prop ];
- }
+
+ // Copy the properties one-by-one to the cache object
+ for ( prop in data ) {
+ cache[ prop ] = data[ prop ];
}
}
return cache;
},
get: function( owner, key ) {
- // Either a valid cache is found, or will be created.
- // New caches will be created and the unlock returned,
- // allowing direct access to the newly created
- // empty data object. A valid owner object must be provided.
- var cache = this.cache[ this.key( owner ) ];
-
return key === undefined ?
- cache : cache[ key ];
+ this.cache( owner ) :
+ owner[ this.expando ] && owner[ this.expando ][ key ];
},
access: function( owner, key, value ) {
var stored;
+
// In cases where either:
//
// 1. No key was specified
@@ -107,15 +110,15 @@ Data.prototype = {
// 2. The data stored at the key
//
if ( key === undefined ||
- ((key && typeof key === "string") && value === undefined) ) {
+ ( ( key && typeof key === "string" ) && value === undefined ) ) {
stored = this.get( owner, key );
return stored !== undefined ?
- stored : this.get( owner, jQuery.camelCase(key) );
+ stored : this.get( owner, jQuery.camelCase( key ) );
}
- // [*]When the key is not a string, or both a key and value
+ // When the key is not a string, or both a key and value
// are specified, set or extend (existing objects) with either:
//
// 1. An object of properties
@@ -129,15 +132,20 @@ Data.prototype = {
},
remove: function( owner, key ) {
var i, name, camel,
- unlock = this.key( owner ),
- cache = this.cache[ unlock ];
+ cache = owner[ this.expando ];
+
+ if ( cache === undefined ) {
+ return;
+ }
if ( key === undefined ) {
- this.cache[ unlock ] = {};
+ this.register( owner );
} else {
+
// Support array or space separated string of keys
if ( jQuery.isArray( key ) ) {
+
// If "name" is an array of keys...
// When data is initially created, via ("key", "val") signature,
// keys will be converted to camelCase.
@@ -147,10 +155,12 @@ Data.prototype = {
name = key.concat( key.map( jQuery.camelCase ) );
} else {
camel = jQuery.camelCase( key );
+
// Try the string as a key before any manipulation
if ( key in cache ) {
name = [ key, camel ];
} else {
+
// If a key with the spaces exists, use it.
// Otherwise, create an array by matching non-whitespace
name = camel;
@@ -160,22 +170,31 @@ Data.prototype = {
}
i = name.length;
+
while ( i-- ) {
delete cache[ name[ i ] ];
}
}
+
+ // Remove the expando if there's no more data
+ if ( key === undefined || jQuery.isEmptyObject( cache ) ) {
+
+ // Support: Chrome <= 35-45+
+ // Webkit & Blink performance suffers when deleting properties
+ // from DOM nodes, so set to undefined instead
+ // https://code.google.com/p/chromium/issues/detail?id=378607
+ if ( owner.nodeType ) {
+ owner[ this.expando ] = undefined;
+ } else {
+ delete owner[ this.expando ];
+ }
+ }
},
hasData: function( owner ) {
- return !jQuery.isEmptyObject(
- this.cache[ owner[ this.expando ] ] || {}
- );
- },
- discard: function( owner ) {
- if ( owner[ this.expando ] ) {
- delete this.cache[ owner[ this.expando ] ];
- }
+ var cache = owner[ this.expando ];
+ return cache !== undefined && !jQuery.isEmptyObject( cache );
}
};
return Data;
-});
+} );