5 ], function( jQuery, rnotwhite, acceptData ) {
8 this.expando = jQuery.expando + Data.uid++;
15 register: function( owner ) {
18 // If it is a node unlikely to be stringify-ed or looped over
19 // use plain assignment
20 if ( owner.nodeType ) {
21 owner[ this.expando ] = value;
23 // Otherwise secure it in a non-enumerable, non-writable property
24 // configurability must be true to allow the property to be
25 // deleted with the delete operator
27 Object.defineProperty( owner, this.expando, {
33 return owner[ this.expando ];
35 cache: function( owner ) {
37 // We can accept data for non-element nodes in modern browsers,
38 // but we should not, see #8335.
39 // Always return an empty object.
40 if ( !acceptData( owner ) ) {
44 // Check if the owner object already has a cache
45 var cache = owner[ this.expando ];
52 // If not, register one
53 return this.register( owner );
55 set: function( owner, data, value ) {
57 cache = this.cache( owner );
59 // Handle: [ owner, key, value ] args
60 // Always use camelCase key (gh-2257)
61 if ( typeof data === "string" ) {
62 cache[ jQuery.camelCase( data ) ] = value;
64 // Handle: [ owner, { properties } ] args
67 // Copy the properties one-by-one to the cache object
68 for ( prop in data ) {
69 cache[ jQuery.camelCase( prop ) ] = data[ prop ];
74 get: function( owner, key ) {
75 var cache = this.cache( owner );
77 return key === undefined ?
80 // Always use camelCase key (gh-2257)
81 cache[ jQuery.camelCase( key ) ];
83 access: function( owner, key, value ) {
85 // In cases where either:
87 // 1. No key was specified
88 // 2. A string key was specified, but no value provided
90 // Take the "read" path and allow the get method to determine
91 // which value to return, respectively either:
93 // 1. The entire cache object
94 // 2. The data stored at the key
96 if ( key === undefined ||
97 ( ( key && typeof key === "string" ) && value === undefined ) ) {
99 return this.get( owner, key );
102 // When the key is not a string, or both a key and value
103 // are specified, set or extend (existing objects) with either:
105 // 1. An object of properties
106 // 2. A key and value
108 this.set( owner, key, value );
110 // Since the "set" path can have two possible entry points
111 // return the expected data based on which path was taken[*]
112 return value !== undefined ? value : key;
114 remove: function( owner, key ) {
116 cache = owner[ this.expando ];
118 if ( cache === undefined ) {
122 if ( key !== undefined ) {
124 // Support array or space separated string of keys
125 if ( jQuery.isArray( key ) ) {
127 // If key is an array of keys...
128 // We always set camelCase keys, so remove that.
129 key = key.map( jQuery.camelCase );
131 key = jQuery.camelCase( key );
133 // If a key with the spaces exists, use it.
134 // Otherwise, create an array by matching non-whitespace
137 ( key.match( rnotwhite ) || [] );
143 delete cache[ key[ i ] ];
147 // Remove the expando if there's no more data
148 if ( key === undefined || jQuery.isEmptyObject( cache ) ) {
149 delete owner[ this.expando ];
152 hasData: function( owner ) {
153 var cache = owner[ this.expando ];
154 return cache !== undefined && !jQuery.isEmptyObject( cache );