nexus site path corrected
[portal.git] / ecomp-portal-FE / client / bower_components / jquery / src / data.js
1 define( [
2         "./core",
3         "./core/access",
4         "./data/var/dataPriv",
5         "./data/var/dataUser"
6 ], function( jQuery, access, dataPriv, dataUser ) {
7
8 //      Implementation Summary
9 //
10 //      1. Enforce API surface and semantic compatibility with 1.9.x branch
11 //      2. Improve the module's maintainability by reducing the storage
12 //              paths to a single mechanism.
13 //      3. Use the same single mechanism to support "private" and "user" data.
14 //      4. _Never_ expose "private" data to user code (TODO: Drop _data, _removeData)
15 //      5. Avoid exposing implementation details on user objects (eg. expando properties)
16 //      6. Provide a clear path for implementation upgrade to WeakMap in 2014
17
18 var rbrace = /^(?:\{[\w\W]*\}|\[[\w\W]*\])$/,
19         rmultiDash = /[A-Z]/g;
20
21 function dataAttr( elem, key, data ) {
22         var name;
23
24         // If nothing was found internally, try to fetch any
25         // data from the HTML5 data-* attribute
26         if ( data === undefined && elem.nodeType === 1 ) {
27                 name = "data-" + key.replace( rmultiDash, "-$&" ).toLowerCase();
28                 data = elem.getAttribute( name );
29
30                 if ( typeof data === "string" ) {
31                         try {
32                                 data = data === "true" ? true :
33                                         data === "false" ? false :
34                                         data === "null" ? null :
35
36                                         // Only convert to a number if it doesn't change the string
37                                         +data + "" === data ? +data :
38                                         rbrace.test( data ) ? jQuery.parseJSON( data ) :
39                                         data;
40                         } catch ( e ) {}
41
42                         // Make sure we set the data so it isn't changed later
43                         dataUser.set( elem, key, data );
44                 } else {
45                         data = undefined;
46                 }
47         }
48         return data;
49 }
50
51 jQuery.extend( {
52         hasData: function( elem ) {
53                 return dataUser.hasData( elem ) || dataPriv.hasData( elem );
54         },
55
56         data: function( elem, name, data ) {
57                 return dataUser.access( elem, name, data );
58         },
59
60         removeData: function( elem, name ) {
61                 dataUser.remove( elem, name );
62         },
63
64         // TODO: Now that all calls to _data and _removeData have been replaced
65         // with direct calls to dataPriv methods, these can be deprecated.
66         _data: function( elem, name, data ) {
67                 return dataPriv.access( elem, name, data );
68         },
69
70         _removeData: function( elem, name ) {
71                 dataPriv.remove( elem, name );
72         }
73 } );
74
75 jQuery.fn.extend( {
76         data: function( key, value ) {
77                 var i, name, data,
78                         elem = this[ 0 ],
79                         attrs = elem && elem.attributes;
80
81                 // Gets all values
82                 if ( key === undefined ) {
83                         if ( this.length ) {
84                                 data = dataUser.get( elem );
85
86                                 if ( elem.nodeType === 1 && !dataPriv.get( elem, "hasDataAttrs" ) ) {
87                                         i = attrs.length;
88                                         while ( i-- ) {
89
90                                                 // Support: IE11+
91                                                 // The attrs elements can be null (#14894)
92                                                 if ( attrs[ i ] ) {
93                                                         name = attrs[ i ].name;
94                                                         if ( name.indexOf( "data-" ) === 0 ) {
95                                                                 name = jQuery.camelCase( name.slice( 5 ) );
96                                                                 dataAttr( elem, name, data[ name ] );
97                                                         }
98                                                 }
99                                         }
100                                         dataPriv.set( elem, "hasDataAttrs", true );
101                                 }
102                         }
103
104                         return data;
105                 }
106
107                 // Sets multiple values
108                 if ( typeof key === "object" ) {
109                         return this.each( function() {
110                                 dataUser.set( this, key );
111                         } );
112                 }
113
114                 return access( this, function( value ) {
115                         var data, camelKey;
116
117                         // The calling jQuery object (element matches) is not empty
118                         // (and therefore has an element appears at this[ 0 ]) and the
119                         // `value` parameter was not undefined. An empty jQuery object
120                         // will result in `undefined` for elem = this[ 0 ] which will
121                         // throw an exception if an attempt to read a data cache is made.
122                         if ( elem && value === undefined ) {
123
124                                 // Attempt to get data from the cache
125                                 // with the key as-is
126                                 data = dataUser.get( elem, key ) ||
127
128                                         // Try to find dashed key if it exists (gh-2779)
129                                         // This is for 2.2.x only
130                                         dataUser.get( elem, key.replace( rmultiDash, "-$&" ).toLowerCase() );
131
132                                 if ( data !== undefined ) {
133                                         return data;
134                                 }
135
136                                 camelKey = jQuery.camelCase( key );
137
138                                 // Attempt to get data from the cache
139                                 // with the key camelized
140                                 data = dataUser.get( elem, camelKey );
141                                 if ( data !== undefined ) {
142                                         return data;
143                                 }
144
145                                 // Attempt to "discover" the data in
146                                 // HTML5 custom data-* attrs
147                                 data = dataAttr( elem, camelKey, undefined );
148                                 if ( data !== undefined ) {
149                                         return data;
150                                 }
151
152                                 // We tried really hard, but the data doesn't exist.
153                                 return;
154                         }
155
156                         // Set the data...
157                         camelKey = jQuery.camelCase( key );
158                         this.each( function() {
159
160                                 // First, attempt to store a copy or reference of any
161                                 // data that might've been store with a camelCased key.
162                                 var data = dataUser.get( this, camelKey );
163
164                                 // For HTML5 data-* attribute interop, we have to
165                                 // store property names with dashes in a camelCase form.
166                                 // This might not apply to all properties...*
167                                 dataUser.set( this, camelKey, value );
168
169                                 // *... In the case of properties that might _actually_
170                                 // have dashes, we need to also store a copy of that
171                                 // unchanged property.
172                                 if ( key.indexOf( "-" ) > -1 && data !== undefined ) {
173                                         dataUser.set( this, key, value );
174                                 }
175                         } );
176                 }, null, value, arguments.length > 1, null, true );
177         },
178
179         removeData: function( key ) {
180                 return this.each( function() {
181                         dataUser.remove( this, key );
182                 } );
183         }
184 } );
185
186 return jQuery;
187 } );