| 17 | function data ( this: Cash, name: string, value: any ): Cash; |
| 18 | function data ( this: Cash, name: Record<string, any> ): Cash; |
| 19 | function data ( this: Cash, name?: string | Record<string, any>, value?: any ) { |
| 20 | |
| 21 | if ( !name ) { |
| 22 | |
| 23 | if ( !this[0] ) return; |
| 24 | |
| 25 | const datas: { [data: string]: any } = {}; |
| 26 | |
| 27 | for ( const key in this[0].dataset ) { |
| 28 | |
| 29 | datas[key] = getData ( this[0], key ); |
| 30 | |
| 31 | } |
| 32 | |
| 33 | return datas; |
| 34 | |
| 35 | } |
| 36 | |
| 37 | if ( isString ( name ) ) { |
| 38 | |
| 39 | if ( arguments.length < 2 ) return this[0] && getData ( this[0], name ); |
| 40 | |
| 41 | if ( isUndefined ( value ) ) return this; |
| 42 | |
| 43 | return this.each ( ( i, ele ) => { setData ( ele, name, value ) } ); |
| 44 | |
| 45 | } |
| 46 | |
| 47 | for ( const key in name ) { |
| 48 | |
| 49 | this.data ( key, name[key] ); |
| 50 | |
| 51 | } |
| 52 | |
| 53 | return this; |
| 54 | |
| 55 | } |
| 56 | |
| 57 | fn.data = data; |