a1a3bc73
Luigi Serra
graphs updates
|
1
|
define( [
|
74249687
Luigi Serra
Cross browser con...
|
2
3
|
"../core",
"../var/rnotwhite",
|
a1a3bc73
Luigi Serra
graphs updates
|
4
5
|
"./var/acceptData"
], function( jQuery, rnotwhite, acceptData ) {
|
74249687
Luigi Serra
Cross browser con...
|
6
7
|
function Data() {
|
74249687
Luigi Serra
Cross browser con...
|
8
9
10
11
|
this.expando = jQuery.expando + Data.uid++;
}
Data.uid = 1;
|
74249687
Luigi Serra
Cross browser con...
|
12
13
|
Data.prototype = {
|
a1a3bc73
Luigi Serra
graphs updates
|
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
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 ) {
|
74249687
Luigi Serra
Cross browser con...
|
37
38
|
// We can accept data for non-element nodes in modern browsers,
// but we should not, see #8335.
|
a1a3bc73
Luigi Serra
graphs updates
|
39
40
41
|
// Always return an empty object.
if ( !acceptData( owner ) ) {
return {};
|
74249687
Luigi Serra
Cross browser con...
|
42
43
|
}
|
a1a3bc73
Luigi Serra
graphs updates
|
44
45
|
// Check if the owner object already has a cache
var value = owner[ this.expando ];
|
74249687
Luigi Serra
Cross browser con...
|
46
47
|
// If not, create one
|
a1a3bc73
Luigi Serra
graphs updates
|
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
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
} );
}
|
74249687
Luigi Serra
Cross browser con...
|
70
71
72
|
}
}
|
a1a3bc73
Luigi Serra
graphs updates
|
73
|
return value;
|
74249687
Luigi Serra
Cross browser con...
|
74
75
76
|
},
set: function( owner, data, value ) {
var prop,
|
a1a3bc73
Luigi Serra
graphs updates
|
77
|
cache = this.cache( owner );
|
74249687
Luigi Serra
Cross browser con...
|
78
79
80
81
82
83
84
|
// Handle: [ owner, key, value ] args
if ( typeof data === "string" ) {
cache[ data ] = value;
// Handle: [ owner, { properties } ] args
} else {
|
a1a3bc73
Luigi Serra
graphs updates
|
85
86
87
88
|
// Copy the properties one-by-one to the cache object
for ( prop in data ) {
cache[ prop ] = data[ prop ];
|
74249687
Luigi Serra
Cross browser con...
|
89
90
91
92
93
|
}
}
return cache;
},
get: function( owner, key ) {
|
74249687
Luigi Serra
Cross browser con...
|
94
|
return key === undefined ?
|
a1a3bc73
Luigi Serra
graphs updates
|
95
96
|
this.cache( owner ) :
owner[ this.expando ] && owner[ this.expando ][ key ];
|
74249687
Luigi Serra
Cross browser con...
|
97
98
99
|
},
access: function( owner, key, value ) {
var stored;
|
a1a3bc73
Luigi Serra
graphs updates
|
100
|
|
74249687
Luigi Serra
Cross browser con...
|
101
102
103
104
105
106
107
108
109
110
111
112
|
// In cases where either:
//
// 1. No key was specified
// 2. A string key was specified, but no value provided
//
// Take the "read" path and allow the get method to determine
// which value to return, respectively either:
//
// 1. The entire cache object
// 2. The data stored at the key
//
if ( key === undefined ||
|
a1a3bc73
Luigi Serra
graphs updates
|
113
|
( ( key && typeof key === "string" ) && value === undefined ) ) {
|
74249687
Luigi Serra
Cross browser con...
|
114
115
116
117
|
stored = this.get( owner, key );
return stored !== undefined ?
|
a1a3bc73
Luigi Serra
graphs updates
|
118
|
stored : this.get( owner, jQuery.camelCase( key ) );
|
74249687
Luigi Serra
Cross browser con...
|
119
120
|
}
|
a1a3bc73
Luigi Serra
graphs updates
|
121
|
// When the key is not a string, or both a key and value
|
74249687
Luigi Serra
Cross browser con...
|
122
123
124
125
126
127
128
129
130
131
132
133
134
|
// are specified, set or extend (existing objects) with either:
//
// 1. An object of properties
// 2. A key and value
//
this.set( owner, key, value );
// Since the "set" path can have two possible entry points
// return the expected data based on which path was taken[*]
return value !== undefined ? value : key;
},
remove: function( owner, key ) {
var i, name, camel,
|
a1a3bc73
Luigi Serra
graphs updates
|
135
136
137
138
139
|
cache = owner[ this.expando ];
if ( cache === undefined ) {
return;
}
|
74249687
Luigi Serra
Cross browser con...
|
140
141
|
if ( key === undefined ) {
|
a1a3bc73
Luigi Serra
graphs updates
|
142
|
this.register( owner );
|
74249687
Luigi Serra
Cross browser con...
|
143
144
|
} else {
|
a1a3bc73
Luigi Serra
graphs updates
|
145
|
|
74249687
Luigi Serra
Cross browser con...
|
146
147
|
// Support array or space separated string of keys
if ( jQuery.isArray( key ) ) {
|
a1a3bc73
Luigi Serra
graphs updates
|
148
|
|
74249687
Luigi Serra
Cross browser con...
|
149
150
151
152
153
154
155
156
157
|
// If "name" is an array of keys...
// When data is initially created, via ("key", "val") signature,
// keys will be converted to camelCase.
// Since there is no way to tell _how_ a key was added, remove
// both plain key and camelCase key. #12786
// This will only penalize the array argument path.
name = key.concat( key.map( jQuery.camelCase ) );
} else {
camel = jQuery.camelCase( key );
|
a1a3bc73
Luigi Serra
graphs updates
|
158
|
|
74249687
Luigi Serra
Cross browser con...
|
159
160
161
162
|
// Try the string as a key before any manipulation
if ( key in cache ) {
name = [ key, camel ];
} else {
|
a1a3bc73
Luigi Serra
graphs updates
|
163
|
|
74249687
Luigi Serra
Cross browser con...
|
164
165
166
167
168
169
170
171
172
|
// If a key with the spaces exists, use it.
// Otherwise, create an array by matching non-whitespace
name = camel;
name = name in cache ?
[ name ] : ( name.match( rnotwhite ) || [] );
}
}
i = name.length;
|
a1a3bc73
Luigi Serra
graphs updates
|
173
|
|
74249687
Luigi Serra
Cross browser con...
|
174
175
176
177
|
while ( i-- ) {
delete cache[ name[ i ] ];
}
}
|
a1a3bc73
Luigi Serra
graphs updates
|
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
// 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 ];
}
}
|
74249687
Luigi Serra
Cross browser con...
|
192
193
|
},
hasData: function( owner ) {
|
a1a3bc73
Luigi Serra
graphs updates
|
194
195
|
var cache = owner[ this.expando ];
return cache !== undefined && !jQuery.isEmptyObject( cache );
|
74249687
Luigi Serra
Cross browser con...
|
196
197
198
199
|
}
};
return Data;
|
a1a3bc73
Luigi Serra
graphs updates
|
200
|
} );
|