/src/main/webapp/bower_components/jquery/src/data.js

https://gitlab.com/nicolas1729/cactus · JavaScript · 295 lines · 206 code · 41 blank · 48 comment · 25 complexity · 67c0135d3a97cb20aa30ba2bd27d74ef MD5 · raw file

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