a1a3bc73
Luigi Serra
graphs updates
|
1
|
define( [
|
74249687
Luigi Serra
Cross browser con...
|
2
3
4
5
6
7
8
|
"../core",
"./support",
"../core/init"
], function( jQuery, support ) {
var rreturn = /\r/g;
|
a1a3bc73
Luigi Serra
graphs updates
|
9
|
jQuery.fn.extend( {
|
74249687
Luigi Serra
Cross browser con...
|
10
11
|
val: function( value ) {
var hooks, ret, isFunction,
|
a1a3bc73
Luigi Serra
graphs updates
|
12
|
elem = this[ 0 ];
|
74249687
Luigi Serra
Cross browser con...
|
13
14
15
|
if ( !arguments.length ) {
if ( elem ) {
|
a1a3bc73
Luigi Serra
graphs updates
|
16
17
|
hooks = jQuery.valHooks[ elem.type ] ||
jQuery.valHooks[ elem.nodeName.toLowerCase() ];
|
74249687
Luigi Serra
Cross browser con...
|
18
|
|
a1a3bc73
Luigi Serra
graphs updates
|
19
20
21
22
|
if ( hooks &&
"get" in hooks &&
( ret = hooks.get( elem, "value" ) ) !== undefined
) {
|
74249687
Luigi Serra
Cross browser con...
|
23
24
25
26
27
28
|
return ret;
}
ret = elem.value;
return typeof ret === "string" ?
|
a1a3bc73
Luigi Serra
graphs updates
|
29
|
|
74249687
Luigi Serra
Cross browser con...
|
30
|
// Handle most common string cases
|
a1a3bc73
Luigi Serra
graphs updates
|
31
32
|
ret.replace( rreturn, "" ) :
|
74249687
Luigi Serra
Cross browser con...
|
33
34
35
36
37
38
39
40
41
|
// Handle cases where value is null/undef or number
ret == null ? "" : ret;
}
return;
}
isFunction = jQuery.isFunction( value );
|
a1a3bc73
Luigi Serra
graphs updates
|
42
|
return this.each( function( i ) {
|
74249687
Luigi Serra
Cross browser con...
|
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
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 = "";
} else if ( typeof val === "number" ) {
val += "";
} else if ( jQuery.isArray( val ) ) {
val = jQuery.map( val, function( value ) {
return value == null ? "" : value + "";
|
a1a3bc73
Luigi Serra
graphs updates
|
65
|
} );
|
74249687
Luigi Serra
Cross browser con...
|
66
67
68
69
70
|
}
hooks = jQuery.valHooks[ this.type ] || jQuery.valHooks[ this.nodeName.toLowerCase() ];
// If set returns undefined, fall back to normal setting
|
a1a3bc73
Luigi Serra
graphs updates
|
71
|
if ( !hooks || !( "set" in hooks ) || hooks.set( this, val, "value" ) === undefined ) {
|
74249687
Luigi Serra
Cross browser con...
|
72
73
|
this.value = val;
}
|
a1a3bc73
Luigi Serra
graphs updates
|
74
|
} );
|
74249687
Luigi Serra
Cross browser con...
|
75
|
}
|
a1a3bc73
Luigi Serra
graphs updates
|
76
|
} );
|
74249687
Luigi Serra
Cross browser con...
|
77
|
|
a1a3bc73
Luigi Serra
graphs updates
|
78
|
jQuery.extend( {
|
74249687
Luigi Serra
Cross browser con...
|
79
80
81
|
valHooks: {
option: {
get: function( elem ) {
|
a1a3bc73
Luigi Serra
graphs updates
|
82
83
84
85
|
// Support: IE<11
// option.value not trimmed (#14858)
return jQuery.trim( elem.value );
|
74249687
Luigi Serra
Cross browser con...
|
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
}
},
select: {
get: function( elem ) {
var value, option,
options = elem.options,
index = elem.selectedIndex,
one = elem.type === "select-one" || index < 0,
values = one ? null : [],
max = one ? index + 1 : options.length,
i = index < 0 ?
max :
one ? index : 0;
// Loop through all the selected options
for ( ; i < max; i++ ) {
option = options[ i ];
|
a1a3bc73
Luigi Serra
graphs updates
|
104
|
// IE8-9 doesn't update selected after form reset (#2551)
|
74249687
Luigi Serra
Cross browser con...
|
105
|
if ( ( option.selected || i === index ) &&
|
a1a3bc73
Luigi Serra
graphs updates
|
106
|
|
74249687
Luigi Serra
Cross browser con...
|
107
|
// Don't return options that are disabled or in a disabled optgroup
|
a1a3bc73
Luigi Serra
graphs updates
|
108
109
110
111
|
( support.optDisabled ?
!option.disabled : option.getAttribute( "disabled" ) === null ) &&
( !option.parentNode.disabled ||
!jQuery.nodeName( option.parentNode, "optgroup" ) ) ) {
|
74249687
Luigi Serra
Cross browser con...
|
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
// 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 ];
|
a1a3bc73
Luigi Serra
graphs updates
|
137
138
139
|
if ( option.selected =
jQuery.inArray( jQuery.valHooks.option.get( option ), values ) > -1
) {
|
74249687
Luigi Serra
Cross browser con...
|
140
141
142
143
144
145
146
147
148
149
150
151
|
optionSet = true;
}
}
// Force browsers to behave consistently when non-matching value is set
if ( !optionSet ) {
elem.selectedIndex = -1;
}
return values;
}
}
}
|
a1a3bc73
Luigi Serra
graphs updates
|
152
|
} );
|
74249687
Luigi Serra
Cross browser con...
|
153
154
|
// Radios and checkboxes getter/setter
|
a1a3bc73
Luigi Serra
graphs updates
|
155
|
jQuery.each( [ "radio", "checkbox" ], function() {
|
74249687
Luigi Serra
Cross browser con...
|
156
157
158
|
jQuery.valHooks[ this ] = {
set: function( elem, value ) {
if ( jQuery.isArray( value ) ) {
|
a1a3bc73
Luigi Serra
graphs updates
|
159
|
return ( elem.checked = jQuery.inArray( jQuery( elem ).val(), value ) > -1 );
|
74249687
Luigi Serra
Cross browser con...
|
160
161
162
163
164
|
}
}
};
if ( !support.checkOn ) {
jQuery.valHooks[ this ].get = function( elem ) {
|
a1a3bc73
Luigi Serra
graphs updates
|
165
|
return elem.getAttribute( "value" ) === null ? "on" : elem.value;
|
74249687
Luigi Serra
Cross browser con...
|
166
167
|
};
}
|
a1a3bc73
Luigi Serra
graphs updates
|
168
|
} );
|
74249687
Luigi Serra
Cross browser con...
|
169
|
|
a1a3bc73
Luigi Serra
graphs updates
|
170
|
} );
|