scratch – Diff between revs 58 and 125

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 58 Rev 125
Line 1... Line 1...
1 define( [ 1 define([
2 "../core", 2 "../core",
3 "../var/rnothtmlwhite", 3 "../var/rnotwhite",
4 "./var/acceptData" 4 "./accepts"
5 ], function( jQuery, rnothtmlwhite, acceptData ) { 5 ], function( jQuery, rnotwhite ) {
6   -  
7 "use strict"; -  
Line 8... Line 6...
8   6  
-   7 function Data() {
-   8 // Support: Android<4,
-   9 // Old WebKit does not have Object.preventExtensions/freeze method,
-   10 // return new empty object instead with no [[set]] accessor
-   11 Object.defineProperty( this.cache = {}, 0, {
-   12 get: function() {
-   13 return {};
-   14 }
-   15 });
9 function Data() { 16  
10 this.expando = jQuery.expando + Data.uid++; 17 this.expando = jQuery.expando + Data.uid++;
Line 11... Line 18...
11 } 18 }
-   19  
Line 12... Line 20...
12   20 Data.uid = 1;
-   21 Data.accepts = jQuery.acceptData;
-   22  
-   23 Data.prototype = {
-   24 key: function( owner ) {
-   25 // We can accept data for non-element nodes in modern browsers,
-   26 // but we should not, see #8335.
-   27 // Always return the key for a frozen object.
Line 13... Line 28...
13 Data.uid = 1; 28 if ( !Data.accepts( owner ) ) {
14   -  
15 Data.prototype = { 29 return 0;
16   30 }
Line 17... Line 31...
17 cache: function( owner ) { 31  
18   32 var descriptor = {},
19 // Check if the owner object already has a cache 33 // Check if the owner object already has a cache key
Line 20... Line 34...
20 var value = owner[ this.expando ]; 34 unlock = owner[ this.expando ];
21   35  
22 // If not, create one 36 // If not, create one
23 if ( !value ) { 37 if ( !unlock ) {
24 value = {}; 38 unlock = Data.uid++;
25   39  
26 // We can accept data for non-element nodes in modern browsers, 40 // Secure it in a non-enumerable, non-writable property
27 // but we should not, see #8335. 41 try {
28 // Always return an empty object. 42 descriptor[ this.expando ] = { value: unlock };
29 if ( acceptData( owner ) ) { -  
30   -  
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; 43 Object.defineProperties( owner, descriptor );
35   -  
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 -  
39 } else { 44  
40 Object.defineProperty( owner, this.expando, { 45 // Support: Android<4
Line -... Line 46...
-   46 // Fallback to a less secure definition
-   47 } catch ( e ) {
-   48 descriptor[ this.expando ] = unlock;
-   49 jQuery.extend( owner, descriptor );
-   50 }
41 value: value, 51 }
42 configurable: true 52  
43 } ); 53 // Ensure the cache object
44 } 54 if ( !this.cache[ unlock ] ) {
-   55 this.cache[ unlock ] = {};
-   56 }
-   57  
-   58 return unlock;
45 } 59 },
Line 46... Line 60...
46 } 60 set: function( owner, data, value ) {
47   -  
48 return value; 61 var prop,
49 }, 62 // There may be an unlock assigned to this node,
Line 50... Line 63...
50 set: function( owner, data, value ) { 63 // if there is no entry for this "owner", create one inline
51 var prop, 64 // and set the unlock as though an owner entry had always existed
52 cache = this.cache( owner ); -  
-   65 unlock = this.key( owner ),
-   66 cache = this.cache[ unlock ];
-   67  
53   68 // Handle: [ owner, key, value ] args
-   69 if ( typeof data === "string" ) {
54 // Handle: [ owner, key, value ] args 70 cache[ data ] = value;
55 // Always use camelCase key (gh-2257) 71  
-   72 // Handle: [ owner, { properties } ] args
56 if ( typeof data === "string" ) { 73 } else {
57 cache[ jQuery.camelCase( data ) ] = value; 74 // Fresh assignments by object are shallow copied
58   75 if ( jQuery.isEmptyObject( cache ) ) {
59 // Handle: [ owner, { properties } ] args 76 jQuery.extend( this.cache[ unlock ], data );
60 } else { 77 // Otherwise, copy the properties one-by-one to the cache object
-   78 } else {
-   79 for ( prop in data ) {
61   80 cache[ prop ] = data[ prop ];
-   81 }
62 // Copy the properties one-by-one to the cache object 82 }
Line 63... Line 83...
63 for ( prop in data ) { 83 }
64 cache[ jQuery.camelCase( prop ) ] = data[ prop ]; 84 return cache;
65 } 85 },
66 } 86 get: function( owner, key ) {
67 return cache; 87 // Either a valid cache is found, or will be created.
68 }, 88 // New caches will be created and the unlock returned,
69 get: function( owner, key ) { 89 // allowing direct access to the newly created
70 return key === undefined ? 90 // empty data object. A valid owner object must be provided.
71 this.cache( owner ) : 91 var cache = this.cache[ this.key( owner ) ];
72   92  
Line 85... Line 105...
85 // 105 //
86 // 1. The entire cache object 106 // 1. The entire cache object
87 // 2. The data stored at the key 107 // 2. The data stored at the key
88 // 108 //
89 if ( key === undefined || 109 if ( key === undefined ||
90 ( ( key && typeof key === "string" ) && value === undefined ) ) { 110 ((key && typeof key === "string") && value === undefined) ) {
-   111  
-   112 stored = this.get( owner, key );
Line -... Line 113...
-   113  
91   114 return stored !== undefined ?
92 return this.get( owner, key ); 115 stored : this.get( owner, jQuery.camelCase(key) );
Line 93... Line 116...
93 } 116 }
94   117  
95 // When the key is not a string, or both a key and value 118 // [*]When the key is not a string, or both a key and value
96 // are specified, set or extend (existing objects) with either: 119 // are specified, set or extend (existing objects) with either:
97 // 120 //
98 // 1. An object of properties 121 // 1. An object of properties
Line 103... Line 126...
103 // Since the "set" path can have two possible entry points 126 // Since the "set" path can have two possible entry points
104 // return the expected data based on which path was taken[*] 127 // return the expected data based on which path was taken[*]
105 return value !== undefined ? value : key; 128 return value !== undefined ? value : key;
106 }, 129 },
107 remove: function( owner, key ) { 130 remove: function( owner, key ) {
108 var i, 131 var i, name, camel,
-   132 unlock = this.key( owner ),
109 cache = owner[ this.expando ]; 133 cache = this.cache[ unlock ];
Line 110... Line 134...
110   134  
111 if ( cache === undefined ) { -  
112 return; -  
113 } -  
114   135 if ( key === undefined ) {
Line -... Line 136...
-   136 this.cache[ unlock ] = {};
115 if ( key !== undefined ) { 137  
116   138 } else {
117 // Support array or space separated string of keys -  
118 if ( jQuery.isArray( key ) ) { 139 // Support array or space separated string of keys
-   140 if ( jQuery.isArray( key ) ) {
-   141 // If "name" is an array of keys...
-   142 // When data is initially created, via ("key", "val") signature,
119   143 // keys will be converted to camelCase.
-   144 // Since there is no way to tell _how_ a key was added, remove
120 // If key is an array of keys... 145 // both plain key and camelCase key. #12786
121 // We always set camelCase keys, so remove that. 146 // This will only penalize the array argument path.
122 key = key.map( jQuery.camelCase ); 147 name = key.concat( key.map( jQuery.camelCase ) );
-   148 } else {
-   149 camel = jQuery.camelCase( key );
-   150 // Try the string as a key before any manipulation
123 } else { 151 if ( key in cache ) {
124 key = jQuery.camelCase( key ); 152 name = [ key, camel ];
125   153 } else {
126 // If a key with the spaces exists, use it. 154 // If a key with the spaces exists, use it.
127 // Otherwise, create an array by matching non-whitespace 155 // Otherwise, create an array by matching non-whitespace
128 key = key in cache ? 156 name = camel;
-   157 name = name in cache ?
129 [ key ] : 158 [ name ] : ( name.match( rnotwhite ) || [] );
Line 130... Line 159...
130 ( key.match( rnothtmlwhite ) || [] ); 159 }
131 } -  
132   160 }
133 i = key.length; 161  
134   -  
135 while ( i-- ) { -  
136 delete cache[ key[ i ] ]; -  
137 } -  
138 } -  
139   -  
140 // Remove the expando if there's no more data -  
141 if ( key === undefined || jQuery.isEmptyObject( cache ) ) { -  
142   -  
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; 162 i = name.length;
149 } else { 163 while ( i-- ) {
150 delete owner[ this.expando ]; 164 delete cache[ name[ i ] ];
151 } 165 }
-   166 }
152 } 167 },
-   168 hasData: function( owner ) {
-   169 return !jQuery.isEmptyObject(
-   170 this.cache[ owner[ this.expando ] ] || {}
-   171 );
153 }, 172 },
-   173 discard: function( owner ) {
154 hasData: function( owner ) { 174 if ( owner[ this.expando ] ) {
155 var cache = owner[ this.expando ]; 175 delete this.cache[ owner[ this.expando ] ];
Line 156... Line 176...
156 return cache !== undefined && !jQuery.isEmptyObject( cache ); 176 }
157 } 177 }