comparison default/node_modules/shoestring/src/data/data.js @ 0:1d038bc9b3d2 default tip

Up:default
author Liny <dev@neowd.com>
date Sat, 31 May 2025 09:21:51 +0800
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:1d038bc9b3d2
1 //>>excludeStart("exclude", pragmas.exclude);
2 define([
3 "shoestring",
4 "dom/is" // note this dependency is only used for a dev error
5 ], function(){
6 //>>excludeEnd("exclude");
7
8 /**
9 * Get data attached to the first element or set data values on all elements in the current set.
10 *
11 * @param {string} name The data attribute name.
12 * @param {any} value The value assigned to the data attribute.
13 * @return {any|shoestring}
14 * @this shoestring
15 */
16 shoestring.fn.data = function( name, value ){
17 if( name !== undefined ){
18 if( value !== undefined ){
19 return this.each(function(){
20 if( !this.shoestringData ){
21 this.shoestringData = {};
22 }
23
24 this.shoestringData[ name ] = value;
25 });
26 }
27 else {
28 if( this[ 0 ] ) {
29 if( this[ 0 ].shoestringData ) {
30 return this[ 0 ].shoestringData[ name ];
31 }
32 //>>includeStart("development", pragmas.development);
33 if( shoestring( this[ 0 ] ).is( "[data-" + name + "]" ) ){
34 shoestring.error( 'data-attr-alias' );
35 }
36 //>>includeEnd("development");
37 }
38 }
39 }
40 else {
41 return this[ 0 ] ? this[ 0 ].shoestringData || {} : undefined;
42 }
43 };
44 //>>excludeStart("exclude", pragmas.exclude);
45 });
46 //>>excludeEnd("exclude");