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