3 "../var/rnothtmlwhite",
5 ], function( jQuery, rnothtmlwhite, acceptData ) {
10 this.expando = jQuery.expando + Data.uid++;
17 cache: function( owner ) {
19 // Check if the owner object already has a cache
20 var value = owner[ this.expando ];
26 // We can accept data for non-element nodes in modern browsers,
27 // but we should not, see #8335.
28 // Always return an empty object.
29 if ( acceptData( owner ) ) {
31 // If it is a node unlikely to be stringify-ed or looped over
32 // use plain assignment
33 if ( owner.nodeType ) {
34 owner[ this.expando ] = value;
36 // Otherwise secure it in a non-enumerable property
37 // configurable must be true to allow the property to be
38 // deleted when data is removed
40 Object.defineProperty( owner, this.expando, {
50 set: function( owner, data, value ) {
52 cache = this.cache( owner );
54 // Handle: [ owner, key, value ] args
55 // Always use camelCase key (gh-2257)
56 if ( typeof data === "string" ) {
57 cache[ jQuery.camelCase( data ) ] = value;
59 // Handle: [ owner, { properties } ] args
62 // Copy the properties one-by-one to the cache object
63 for ( prop in data ) {
64 cache[ jQuery.camelCase( prop ) ] = data[ prop ];
69 get: function( owner, key ) {
70 return key === undefined ?
73 // Always use camelCase key (gh-2257)
74 owner[ this.expando ] && owner[ this.expando ][ jQuery.camelCase( key ) ];
76 access: function( owner, key, value ) {
78 // In cases where either:
80 // 1. No key was specified
81 // 2. A string key was specified, but no value provided
83 // Take the "read" path and allow the get method to determine
84 // which value to return, respectively either:
86 // 1. The entire cache object
87 // 2. The data stored at the key
89 if ( key === undefined ||
90 ( ( key && typeof key === "string" ) && value === undefined ) ) {
92 return this.get( owner, key );
95 // When the key is not a string, or both a key and value
96 // are specified, set or extend (existing objects) with either:
98 // 1. An object of properties
101 this.set( owner, key, value );
103 // Since the "set" path can have two possible entry points
104 // return the expected data based on which path was taken[*]
105 return value !== undefined ? value : key;
107 remove: function( owner, key ) {
109 cache = owner[ this.expando ];
111 if ( cache === undefined ) {
115 if ( key !== undefined ) {
117 // Support array or space separated string of keys
118 if ( Array.isArray( key ) ) {
120 // If key is an array of keys...
121 // We always set camelCase keys, so remove that.
122 key = key.map( jQuery.camelCase );
124 key = jQuery.camelCase( key );
126 // If a key with the spaces exists, use it.
127 // Otherwise, create an array by matching non-whitespace
130 ( key.match( rnothtmlwhite ) || [] );
136 delete cache[ key[ i ] ];
140 // Remove the expando if there's no more data
141 if ( key === undefined || jQuery.isEmptyObject( cache ) ) {
143 // Support: Chrome <=35 - 45
144 // Webkit & Blink performance suffers when deleting properties
145 // from DOM nodes, so set to undefined instead
146 // https://bugs.chromium.org/p/chromium/issues/detail?id=378607 (bug restricted)
147 if ( owner.nodeType ) {
148 owner[ this.expando ] = undefined;
150 delete owner[ this.expando ];
154 hasData: function( owner ) {
155 var cache = owner[ this.expando ];
156 return cache !== undefined && !jQuery.isEmptyObject( cache );