Blame view

app/bower_components/jquery/src/data.js 4.2 KB
87c93a029   Dang YoungWorld   add modal
1
  define( [
f986e111b   TRUONG   add libs
2
  	"./core",
87c93a029   Dang YoungWorld   add modal
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
  	"./core/access",
  	"./data/var/dataPriv",
  	"./data/var/dataUser"
  ], function( jQuery, access, dataPriv, dataUser ) {
  
  "use strict";
  
  //	Implementation Summary
  //
  //	1. Enforce API surface and semantic compatibility with 1.9.x branch
  //	2. Improve the module's maintainability by reducing the storage
  //		paths to a single mechanism.
  //	3. Use the same single mechanism to support "private" and "user" data.
  //	4. _Never_ expose "private" data to user code (TODO: Drop _data, _removeData)
  //	5. Avoid exposing implementation details on user objects (eg. expando properties)
  //	6. Provide a clear path for implementation upgrade to WeakMap in 2014
f986e111b   TRUONG   add libs
19
20
  
  var rbrace = /^(?:\{[\w\W]*\}|\[[\w\W]*\])$/,
87c93a029   Dang YoungWorld   add modal
21
  	rmultiDash = /[A-Z]/g;
f986e111b   TRUONG   add libs
22

87c93a029   Dang YoungWorld   add modal
23
24
25
  function getData( data ) {
  	if ( data === "true" ) {
  		return true;
f986e111b   TRUONG   add libs
26
  	}
87c93a029   Dang YoungWorld   add modal
27
28
  	if ( data === "false" ) {
  		return false;
f986e111b   TRUONG   add libs
29
  	}
87c93a029   Dang YoungWorld   add modal
30
31
  	if ( data === "null" ) {
  		return null;
f986e111b   TRUONG   add libs
32
  	}
87c93a029   Dang YoungWorld   add modal
33
34
35
  	// Only convert to a number if it doesn't change the string
  	if ( data === +data + "" ) {
  		return +data;
f986e111b   TRUONG   add libs
36
  	}
87c93a029   Dang YoungWorld   add modal
37
38
  	if ( rbrace.test( data ) ) {
  		return JSON.parse( data );
f986e111b   TRUONG   add libs
39
  	}
87c93a029   Dang YoungWorld   add modal
40
  	return data;
f986e111b   TRUONG   add libs
41
  }
87c93a029   Dang YoungWorld   add modal
42
43
  function dataAttr( elem, key, data ) {
  	var name;
f986e111b   TRUONG   add libs
44

87c93a029   Dang YoungWorld   add modal
45
46
47
48
49
  	// If nothing was found internally, try to fetch any
  	// data from the HTML5 data-* attribute
  	if ( data === undefined && elem.nodeType === 1 ) {
  		name = "data-" + key.replace( rmultiDash, "-$&" ).toLowerCase();
  		data = elem.getAttribute( name );
f986e111b   TRUONG   add libs
50

87c93a029   Dang YoungWorld   add modal
51
52
53
54
  		if ( typeof data === "string" ) {
  			try {
  				data = getData( data );
  			} catch ( e ) {}
f986e111b   TRUONG   add libs
55

87c93a029   Dang YoungWorld   add modal
56
57
58
59
  			// Make sure we set the data so it isn't changed later
  			dataUser.set( elem, key, data );
  		} else {
  			data = undefined;
f986e111b   TRUONG   add libs
60
61
  		}
  	}
87c93a029   Dang YoungWorld   add modal
62
  	return data;
f986e111b   TRUONG   add libs
63
  }
87c93a029   Dang YoungWorld   add modal
64
  jQuery.extend( {
f986e111b   TRUONG   add libs
65
  	hasData: function( elem ) {
87c93a029   Dang YoungWorld   add modal
66
  		return dataUser.hasData( elem ) || dataPriv.hasData( elem );
f986e111b   TRUONG   add libs
67
68
69
  	},
  
  	data: function( elem, name, data ) {
87c93a029   Dang YoungWorld   add modal
70
  		return dataUser.access( elem, name, data );
f986e111b   TRUONG   add libs
71
72
73
  	},
  
  	removeData: function( elem, name ) {
87c93a029   Dang YoungWorld   add modal
74
  		dataUser.remove( elem, name );
f986e111b   TRUONG   add libs
75
  	},
87c93a029   Dang YoungWorld   add modal
76
77
  	// TODO: Now that all calls to _data and _removeData have been replaced
  	// with direct calls to dataPriv methods, these can be deprecated.
f986e111b   TRUONG   add libs
78
  	_data: function( elem, name, data ) {
87c93a029   Dang YoungWorld   add modal
79
  		return dataPriv.access( elem, name, data );
f986e111b   TRUONG   add libs
80
81
82
  	},
  
  	_removeData: function( elem, name ) {
87c93a029   Dang YoungWorld   add modal
83
  		dataPriv.remove( elem, name );
f986e111b   TRUONG   add libs
84
  	}
87c93a029   Dang YoungWorld   add modal
85
  } );
f986e111b   TRUONG   add libs
86

87c93a029   Dang YoungWorld   add modal
87
  jQuery.fn.extend( {
f986e111b   TRUONG   add libs
88
89
  	data: function( key, value ) {
  		var i, name, data,
87c93a029   Dang YoungWorld   add modal
90
  			elem = this[ 0 ],
f986e111b   TRUONG   add libs
91
  			attrs = elem && elem.attributes;
f986e111b   TRUONG   add libs
92
93
94
  		// Gets all values
  		if ( key === undefined ) {
  			if ( this.length ) {
87c93a029   Dang YoungWorld   add modal
95
  				data = dataUser.get( elem );
f986e111b   TRUONG   add libs
96

87c93a029   Dang YoungWorld   add modal
97
  				if ( elem.nodeType === 1 && !dataPriv.get( elem, "hasDataAttrs" ) ) {
f986e111b   TRUONG   add libs
98
99
  					i = attrs.length;
  					while ( i-- ) {
87c93a029   Dang YoungWorld   add modal
100
  						// Support: IE 11 only
f986e111b   TRUONG   add libs
101
102
103
104
  						// The attrs elements can be null (#14894)
  						if ( attrs[ i ] ) {
  							name = attrs[ i ].name;
  							if ( name.indexOf( "data-" ) === 0 ) {
87c93a029   Dang YoungWorld   add modal
105
  								name = jQuery.camelCase( name.slice( 5 ) );
f986e111b   TRUONG   add libs
106
107
108
109
  								dataAttr( elem, name, data[ name ] );
  							}
  						}
  					}
87c93a029   Dang YoungWorld   add modal
110
  					dataPriv.set( elem, "hasDataAttrs", true );
f986e111b   TRUONG   add libs
111
112
113
114
115
116
117
118
  				}
  			}
  
  			return data;
  		}
  
  		// Sets multiple values
  		if ( typeof key === "object" ) {
87c93a029   Dang YoungWorld   add modal
119
120
121
  			return this.each( function() {
  				dataUser.set( this, key );
  			} );
f986e111b   TRUONG   add libs
122
  		}
87c93a029   Dang YoungWorld   add modal
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
  		return access( this, function( value ) {
  			var data;
  
  			// The calling jQuery object (element matches) is not empty
  			// (and therefore has an element appears at this[ 0 ]) and the
  			// `value` parameter was not undefined. An empty jQuery object
  			// will result in `undefined` for elem = this[ 0 ] which will
  			// throw an exception if an attempt to read a data cache is made.
  			if ( elem && value === undefined ) {
  
  				// Attempt to get data from the cache
  				// The key will always be camelCased in Data
  				data = dataUser.get( elem, key );
  				if ( data !== undefined ) {
  					return data;
  				}
  
  				// Attempt to "discover" the data in
  				// HTML5 custom data-* attrs
  				data = dataAttr( elem, key );
  				if ( data !== undefined ) {
  					return data;
  				}
  
  				// We tried really hard, but the data doesn't exist.
  				return;
  			}
f986e111b   TRUONG   add libs
150

87c93a029   Dang YoungWorld   add modal
151
152
  			// Set the data...
  			this.each( function() {
f986e111b   TRUONG   add libs
153

87c93a029   Dang YoungWorld   add modal
154
155
156
157
  				// We always store the camelCased key
  				dataUser.set( this, key, value );
  			} );
  		}, null, value, arguments.length > 1, null, true );
f986e111b   TRUONG   add libs
158
159
160
  	},
  
  	removeData: function( key ) {
87c93a029   Dang YoungWorld   add modal
161
162
163
  		return this.each( function() {
  			dataUser.remove( this, key );
  		} );
f986e111b   TRUONG   add libs
164
  	}
87c93a029   Dang YoungWorld   add modal
165
  } );
f986e111b   TRUONG   add libs
166
167
  
  return jQuery;
87c93a029   Dang YoungWorld   add modal
168
  } );