| 1 | define( [
|
| 2 | "../core",
|
| 3 | "../core/camelCase",
|
| 4 | "../var/rnothtmlwhite",
|
| 5 | "./var/acceptData"
|
| 6 | ], function( jQuery, camelCase, rnothtmlwhite, acceptData ) {
|
| 7 |
|
| 8 | "use strict";
|
| 9 |
|
| 10 | function Data() {
|
| 11 | this.expando = jQuery.expando + Data.uid++;
|
| 12 | }
|
| 13 |
|
| 14 | Data.uid = 1;
|
| 15 |
|
| 16 | Data.prototype = {
|
| 17 |
|
| 18 | cache: function( owner ) {
|
| 19 |
|
| 20 |
|
| 21 | var value = owner[ this.expando ];
|
| 22 |
|
| 23 |
|
| 24 | if ( !value ) {
|
| 25 | value = {};
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 | if ( acceptData( owner ) ) {
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 | if ( owner.nodeType ) {
|
| 35 | owner[ this.expando ] = value;
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 | } else {
|
| 41 | Object.defineProperty( owner, this.expando, {
|
| 42 | value: value,
|
| 43 | configurable: true
|
| 44 | } );
|
| 45 | }
|
| 46 | }
|
| 47 | }
|
| 48 |
|
| 49 | return value;
|
| 50 | },
|
| 51 | set: function( owner, data, value ) {
|
| 52 | var prop,
|
| 53 | cache = this.cache( owner );
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 | if ( typeof data === "string" ) {
|
| 58 | cache[ camelCase( data ) ] = value;
|
| 59 |
|
| 60 |
|
| 61 | } else {
|
| 62 |
|
| 63 |
|
| 64 | for ( prop in data ) {
|
| 65 | cache[ camelCase( prop ) ] = data[ prop ];
|
| 66 | }
|
| 67 | }
|
| 68 | return cache;
|
| 69 | },
|
| 70 | get: function( owner, key ) {
|
| 71 | return key === undefined ?
|
| 72 | this.cache( owner ) :
|
| 73 |
|
| 74 |
|
| 75 | owner[ this.expando ] && owner[ this.expando ][ camelCase( key ) ];
|
| 76 | },
|
| 77 | access: function( owner, key, value ) {
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 | if ( key === undefined ||
|
| 91 | ( ( key && typeof key === "string" ) && value === undefined ) ) {
|
| 92 |
|
| 93 | return this.get( owner, key );
|
| 94 | }
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 | this.set( owner, key, value );
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 | return value !== undefined ? value : key;
|
| 107 | },
|
| 108 | remove: function( owner, key ) {
|
| 109 | var i,
|
| 110 | cache = owner[ this.expando ];
|
| 111 |
|
| 112 | if ( cache === undefined ) {
|
| 113 | return;
|
| 114 | }
|
| 115 |
|
| 116 | if ( key !== undefined ) {
|
| 117 |
|
| 118 |
|
| 119 | if ( Array.isArray( key ) ) {
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 | key = key.map( camelCase );
|
| 124 | } else {
|
| 125 | key = camelCase( key );
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 | key = key in cache ?
|
| 130 | [ key ] :
|
| 131 | ( key.match( rnothtmlwhite ) || [] );
|
| 132 | }
|
| 133 |
|
| 134 | i = key.length;
|
| 135 |
|
| 136 | while ( i-- ) {
|
| 137 | delete cache[ key[ i ] ];
|
| 138 | }
|
| 139 | }
|
| 140 |
|
| 141 |
|
| 142 | if ( key === undefined || jQuery.isEmptyObject( cache ) ) {
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 | if ( owner.nodeType ) {
|
| 149 | owner[ this.expando ] = undefined;
|
| 150 | } else {
|
| 151 | delete owner[ this.expando ];
|
| 152 | }
|
| 153 | }
|
| 154 | },
|
| 155 | hasData: function( owner ) {
|
| 156 | var cache = owner[ this.expando ];
|
| 157 | return cache !== undefined && !jQuery.isEmptyObject( cache );
|
| 158 | }
|
| 159 | };
|
| 160 |
|
| 161 | return Data;
|
| 162 | } );
|