Blame view

app/bower_components/jquery/src/attributes/val.js 4.09 KB
87c93a029   Dang YoungWorld   add modal
1
  define( [
f986e111b   TRUONG   add libs
2
  	"../core",
87c93a029   Dang YoungWorld   add modal
3
  	"../core/stripAndCollapse",
f986e111b   TRUONG   add libs
4
5
  	"./support",
  	"../core/init"
87c93a029   Dang YoungWorld   add modal
6
7
8
  ], function( jQuery, stripAndCollapse, support ) {
  
  "use strict";
f986e111b   TRUONG   add libs
9
10
  
  var rreturn = /\r/g;
87c93a029   Dang YoungWorld   add modal
11
  jQuery.fn.extend( {
f986e111b   TRUONG   add libs
12
13
  	val: function( value ) {
  		var hooks, ret, isFunction,
87c93a029   Dang YoungWorld   add modal
14
  			elem = this[ 0 ];
f986e111b   TRUONG   add libs
15
16
17
  
  		if ( !arguments.length ) {
  			if ( elem ) {
87c93a029   Dang YoungWorld   add modal
18
19
  				hooks = jQuery.valHooks[ elem.type ] ||
  					jQuery.valHooks[ elem.nodeName.toLowerCase() ];
f986e111b   TRUONG   add libs
20

87c93a029   Dang YoungWorld   add modal
21
22
23
24
  				if ( hooks &&
  					"get" in hooks &&
  					( ret = hooks.get( elem, "value" ) ) !== undefined
  				) {
f986e111b   TRUONG   add libs
25
26
27
28
  					return ret;
  				}
  
  				ret = elem.value;
87c93a029   Dang YoungWorld   add modal
29
30
31
32
33
34
35
  				// Handle most common string cases
  				if ( typeof ret === "string" ) {
  					return ret.replace( rreturn, "" );
  				}
  
  				// Handle cases where value is null/undef or number
  				return ret == null ? "" : ret;
f986e111b   TRUONG   add libs
36
37
38
39
40
41
  			}
  
  			return;
  		}
  
  		isFunction = jQuery.isFunction( value );
87c93a029   Dang YoungWorld   add modal
42
  		return this.each( function( i ) {
f986e111b   TRUONG   add libs
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
  			var val;
  
  			if ( this.nodeType !== 1 ) {
  				return;
  			}
  
  			if ( isFunction ) {
  				val = value.call( this, i, jQuery( this ).val() );
  			} else {
  				val = value;
  			}
  
  			// Treat null/undefined as ""; convert numbers to string
  			if ( val == null ) {
  				val = "";
87c93a029   Dang YoungWorld   add modal
58

f986e111b   TRUONG   add libs
59
60
  			} else if ( typeof val === "number" ) {
  				val += "";
87c93a029   Dang YoungWorld   add modal
61

f986e111b   TRUONG   add libs
62
63
64
  			} else if ( jQuery.isArray( val ) ) {
  				val = jQuery.map( val, function( value ) {
  					return value == null ? "" : value + "";
87c93a029   Dang YoungWorld   add modal
65
  				} );
f986e111b   TRUONG   add libs
66
67
68
69
70
  			}
  
  			hooks = jQuery.valHooks[ this.type ] || jQuery.valHooks[ this.nodeName.toLowerCase() ];
  
  			// If set returns undefined, fall back to normal setting
87c93a029   Dang YoungWorld   add modal
71
  			if ( !hooks || !( "set" in hooks ) || hooks.set( this, val, "value" ) === undefined ) {
f986e111b   TRUONG   add libs
72
73
  				this.value = val;
  			}
87c93a029   Dang YoungWorld   add modal
74
  		} );
f986e111b   TRUONG   add libs
75
  	}
87c93a029   Dang YoungWorld   add modal
76
  } );
f986e111b   TRUONG   add libs
77

87c93a029   Dang YoungWorld   add modal
78
  jQuery.extend( {
f986e111b   TRUONG   add libs
79
80
81
  	valHooks: {
  		option: {
  			get: function( elem ) {
87c93a029   Dang YoungWorld   add modal
82

f986e111b   TRUONG   add libs
83
84
85
  				var val = jQuery.find.attr( elem, "value" );
  				return val != null ?
  					val :
87c93a029   Dang YoungWorld   add modal
86
87
  
  					// Support: IE <=10 - 11 only
f986e111b   TRUONG   add libs
88
  					// option.text throws exceptions (#14686, #14858)
87c93a029   Dang YoungWorld   add modal
89
90
91
  					// Strip and collapse whitespace
  					// https://html.spec.whatwg.org/#strip-and-collapse-whitespace
  					stripAndCollapse( jQuery.text( elem ) );
f986e111b   TRUONG   add libs
92
93
94
95
  			}
  		},
  		select: {
  			get: function( elem ) {
87c93a029   Dang YoungWorld   add modal
96
  				var value, option, i,
f986e111b   TRUONG   add libs
97
98
  					options = elem.options,
  					index = elem.selectedIndex,
87c93a029   Dang YoungWorld   add modal
99
  					one = elem.type === "select-one",
f986e111b   TRUONG   add libs
100
  					values = one ? null : [],
87c93a029   Dang YoungWorld   add modal
101
102
103
104
105
106
107
108
  					max = one ? index + 1 : options.length;
  
  				if ( index < 0 ) {
  					i = max;
  
  				} else {
  					i = one ? index : 0;
  				}
f986e111b   TRUONG   add libs
109
110
111
112
  
  				// Loop through all the selected options
  				for ( ; i < max; i++ ) {
  					option = options[ i ];
87c93a029   Dang YoungWorld   add modal
113
114
  					// Support: IE <=9 only
  					// IE8-9 doesn't update selected after form reset (#2551)
f986e111b   TRUONG   add libs
115
  					if ( ( option.selected || i === index ) &&
87c93a029   Dang YoungWorld   add modal
116

f986e111b   TRUONG   add libs
117
  							// Don't return options that are disabled or in a disabled optgroup
87c93a029   Dang YoungWorld   add modal
118
119
120
  							!option.disabled &&
  							( !option.parentNode.disabled ||
  								!jQuery.nodeName( option.parentNode, "optgroup" ) ) ) {
f986e111b   TRUONG   add libs
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
  
  						// Get the specific value for the option
  						value = jQuery( option ).val();
  
  						// We don't need an array for one selects
  						if ( one ) {
  							return value;
  						}
  
  						// Multi-Selects return an array
  						values.push( value );
  					}
  				}
  
  				return values;
  			},
  
  			set: function( elem, value ) {
  				var optionSet, option,
  					options = elem.options,
  					values = jQuery.makeArray( value ),
  					i = options.length;
  
  				while ( i-- ) {
  					option = options[ i ];
87c93a029   Dang YoungWorld   add modal
146
  					/* eslint-disable no-cond-assign */
f986e111b   TRUONG   add libs
147

87c93a029   Dang YoungWorld   add modal
148
149
150
151
  					if ( option.selected =
  						jQuery.inArray( jQuery.valHooks.option.get( option ), values ) > -1
  					) {
  						optionSet = true;
f986e111b   TRUONG   add libs
152
  					}
87c93a029   Dang YoungWorld   add modal
153
154
  
  					/* eslint-enable no-cond-assign */
f986e111b   TRUONG   add libs
155
156
157
158
159
160
  				}
  
  				// Force browsers to behave consistently when non-matching value is set
  				if ( !optionSet ) {
  					elem.selectedIndex = -1;
  				}
87c93a029   Dang YoungWorld   add modal
161
  				return values;
f986e111b   TRUONG   add libs
162
163
164
  			}
  		}
  	}
87c93a029   Dang YoungWorld   add modal
165
  } );
f986e111b   TRUONG   add libs
166
167
  
  // Radios and checkboxes getter/setter
87c93a029   Dang YoungWorld   add modal
168
  jQuery.each( [ "radio", "checkbox" ], function() {
f986e111b   TRUONG   add libs
169
170
171
  	jQuery.valHooks[ this ] = {
  		set: function( elem, value ) {
  			if ( jQuery.isArray( value ) ) {
87c93a029   Dang YoungWorld   add modal
172
  				return ( elem.checked = jQuery.inArray( jQuery( elem ).val(), value ) > -1 );
f986e111b   TRUONG   add libs
173
174
175
176
177
  			}
  		}
  	};
  	if ( !support.checkOn ) {
  		jQuery.valHooks[ this ].get = function( elem ) {
87c93a029   Dang YoungWorld   add modal
178
  			return elem.getAttribute( "value" ) === null ? "on" : elem.value;
f986e111b   TRUONG   add libs
179
180
  		};
  	}
87c93a029   Dang YoungWorld   add modal
181
  } );
f986e111b   TRUONG   add libs
182

87c93a029   Dang YoungWorld   add modal
183
  } );