scratch – Diff between revs 58 and 125
?pathlinks?
Rev 58 | Rev 125 | |||
---|---|---|---|---|
Line 1... | Line 1... | |||
1 | define( [ |
1 | define([ |
|
2 | "../core", |
2 | "../core", |
|
3 | "../core/stripAndCollapse", |
- | ||
4 | "./support", |
3 | "./support", |
|
5 | "../core/init" |
4 | "../core/init" |
|
6 | ], function( jQuery, stripAndCollapse, support ) { |
5 | ], function( jQuery, support ) { |
|
7 | |
- | ||
8 | "use strict"; |
- | ||
Line 9... | Line 6... | |||
9 | |
6 | |
|
Line 10... | Line 7... | |||
10 | var rreturn = /\r/g; |
7 | var rreturn = /\r/g; |
|
11 | |
8 | |
|
12 | jQuery.fn.extend( { |
9 | jQuery.fn.extend({ |
|
13 | val: function( value ) { |
10 | val: function( value ) { |
|
Line 14... | Line 11... | |||
14 | var hooks, ret, isFunction, |
11 | var hooks, ret, isFunction, |
|
15 | elem = this[ 0 ]; |
12 | elem = this[0]; |
|
16 | |
- | ||
17 | if ( !arguments.length ) { |
13 | |
|
Line 18... | Line -... | |||
18 | if ( elem ) { |
- | ||
19 | hooks = jQuery.valHooks[ elem.type ] || |
- | ||
20 | jQuery.valHooks[ elem.nodeName.toLowerCase() ]; |
14 | if ( !arguments.length ) { |
|
21 | |
- | ||
22 | if ( hooks && |
15 | if ( elem ) { |
|
23 | "get" in hooks && |
16 | hooks = jQuery.valHooks[ elem.type ] || jQuery.valHooks[ elem.nodeName.toLowerCase() ]; |
|
Line 24... | Line 17... | |||
24 | ( ret = hooks.get( elem, "value" ) ) !== undefined |
17 | |
|
Line 25... | Line 18... | |||
25 | ) { |
18 | if ( hooks && "get" in hooks && (ret = hooks.get( elem, "value" )) !== undefined ) { |
|
26 | return ret; |
19 | return ret; |
|
27 | } |
20 | } |
|
28 | |
- | ||
29 | ret = elem.value; |
- | ||
30 | |
21 | |
|
31 | // Handle most common string cases |
22 | ret = elem.value; |
|
32 | if ( typeof ret === "string" ) { |
23 | |
|
Line 33... | Line 24... | |||
33 | return ret.replace( rreturn, "" ); |
24 | return typeof ret === "string" ? |
|
34 | } |
25 | // Handle most common string cases |
|
Line 35... | Line 26... | |||
35 | |
26 | ret.replace(rreturn, "") : |
|
Line 36... | Line 27... | |||
36 | // Handle cases where value is null/undef or number |
27 | // Handle cases where value is null/undef or number |
|
37 | return ret == null ? "" : ret; |
28 | ret == null ? "" : ret; |
|
Line 38... | Line 29... | |||
38 | } |
29 | } |
|
39 | |
30 | |
|
40 | return; |
31 | return; |
|
Line 63... | Line 54... | |||
63 | val += ""; |
54 | val += ""; |
|
Line 64... | Line 55... | |||
64 | |
55 | |
|
65 | } else if ( jQuery.isArray( val ) ) { |
56 | } else if ( jQuery.isArray( val ) ) { |
|
66 | val = jQuery.map( val, function( value ) { |
57 | val = jQuery.map( val, function( value ) { |
|
67 | return value == null ? "" : value + ""; |
58 | return value == null ? "" : value + ""; |
|
68 | } ); |
59 | }); |
|
Line 69... | Line 60... | |||
69 | } |
60 | } |
|
Line 70... | Line 61... | |||
70 | |
61 | |
|
71 | hooks = jQuery.valHooks[ this.type ] || jQuery.valHooks[ this.nodeName.toLowerCase() ]; |
62 | hooks = jQuery.valHooks[ this.type ] || jQuery.valHooks[ this.nodeName.toLowerCase() ]; |
|
72 | |
63 | |
|
73 | // If set returns undefined, fall back to normal setting |
64 | // If set returns undefined, fall back to normal setting |
|
74 | if ( !hooks || !( "set" in hooks ) || hooks.set( this, val, "value" ) === undefined ) { |
65 | if ( !hooks || !("set" in hooks) || hooks.set( this, val, "value" ) === undefined ) { |
|
75 | this.value = val; |
66 | this.value = val; |
|
76 | } |
67 | } |
|
Line 77... | Line 68... | |||
77 | } ); |
68 | }); |
|
78 | } |
69 | } |
|
79 | } ); |
70 | }); |
|
80 | |
71 | |
|
81 | jQuery.extend( { |
- | ||
82 | valHooks: { |
72 | jQuery.extend({ |
|
83 | option: { |
73 | valHooks: { |
|
84 | get: function( elem ) { |
74 | option: { |
|
85 | |
- | ||
86 | var val = jQuery.find.attr( elem, "value" ); |
75 | get: function( elem ) { |
|
87 | return val != null ? |
76 | var val = jQuery.find.attr( elem, "value" ); |
|
88 | val : |
- | ||
89 | |
- | ||
90 | // Support: IE <=10 - 11 only |
77 | return val != null ? |
|
91 | // option.text throws exceptions (#14686, #14858) |
78 | val : |
|
92 | // Strip and collapse whitespace |
79 | // Support: IE10-11+ |
|
93 | // https://html.spec.whatwg.org/#strip-and-collapse-whitespace |
80 | // option.text throws exceptions (#14686, #14858) |
|
94 | stripAndCollapse( jQuery.text( elem ) ); |
81 | jQuery.trim( jQuery.text( elem ) ); |
|
95 | } |
82 | } |
|
96 | }, |
83 | }, |
|
97 | select: { |
84 | select: { |
|
98 | get: function( elem ) { |
85 | get: function( elem ) { |
|
99 | var value, option, i, |
86 | var value, option, |
|
100 | options = elem.options, |
87 | options = elem.options, |
|
101 | index = elem.selectedIndex, |
- | ||
102 | one = elem.type === "select-one", |
88 | index = elem.selectedIndex, |
|
103 | values = one ? null : [], |
89 | one = elem.type === "select-one" || index < 0, |
|
104 | max = one ? index + 1 : options.length; |
- | ||
105 | |
- | ||
106 | if ( index < 0 ) { |
90 | values = one ? null : [], |
|
107 | i = max; |
- | ||
Line 108... | Line 91... | |||
108 | |
91 | max = one ? index + 1 : options.length, |
|
109 | } else { |
92 | i = index < 0 ? |
|
110 | i = one ? index : 0; |
93 | max : |
|
Line 111... | Line -... | |||
111 | } |
- | ||
112 | |
94 | one ? index : 0; |
|
113 | // Loop through all the selected options |
95 | |
|
114 | for ( ; i < max; i++ ) { |
- | ||
115 | option = options[ i ]; |
96 | // Loop through all the selected options |
|
116 | |
- | ||
117 | // Support: IE <=9 only |
97 | for ( ; i < max; i++ ) { |
|
118 | // IE8-9 doesn't update selected after form reset (#2551) |
98 | option = options[ i ]; |
|
Line 119... | Line 99... | |||
119 | if ( ( option.selected || i === index ) && |
99 | |
|
120 | |
100 | // IE6-9 doesn't update selected after form reset (#2551) |
|
Line 121... | Line 101... | |||
121 | // Don't return options that are disabled or in a disabled optgroup |
101 | if ( ( option.selected || i === index ) && |
|
Line 145... | Line 125... | |||
145 | values = jQuery.makeArray( value ), |
125 | values = jQuery.makeArray( value ), |
|
146 | i = options.length; |
126 | i = options.length; |
|
Line 147... | Line 127... | |||
147 | |
127 | |
|
148 | while ( i-- ) { |
128 | while ( i-- ) { |
|
149 | option = options[ i ]; |
- | ||
150 | |
- | ||
151 | /* eslint-disable no-cond-assign */ |
- | ||
152 | |
- | ||
153 | if ( option.selected = |
129 | option = options[ i ]; |
|
154 | jQuery.inArray( jQuery.valHooks.option.get( option ), values ) > -1 |
- | ||
155 | ) { |
130 | if ( (option.selected = jQuery.inArray( option.value, values ) >= 0) ) { |
|
156 | optionSet = true; |
131 | optionSet = true; |
|
157 | } |
- | ||
158 | |
- | ||
159 | /* eslint-enable no-cond-assign */ |
132 | } |
|
Line 160... | Line 133... | |||
160 | } |
133 | } |
|
161 | |
134 | |
|
162 | // Force browsers to behave consistently when non-matching value is set |
135 | // Force browsers to behave consistently when non-matching value is set |
|
163 | if ( !optionSet ) { |
136 | if ( !optionSet ) { |
|
164 | elem.selectedIndex = -1; |
137 | elem.selectedIndex = -1; |
|
165 | } |
138 | } |
|
166 | return values; |
139 | return values; |
|
167 | } |
140 | } |
|
168 | } |
141 | } |
|
Line 169... | Line 142... | |||
169 | } |
142 | } |
|
170 | } ); |
143 | }); |
|
171 | |
144 | |
|
172 | // Radios and checkboxes getter/setter |
145 | // Radios and checkboxes getter/setter |
|
173 | jQuery.each( [ "radio", "checkbox" ], function() { |
146 | jQuery.each([ "radio", "checkbox" ], function() { |
|
174 | jQuery.valHooks[ this ] = { |
147 | jQuery.valHooks[ this ] = { |
|
175 | set: function( elem, value ) { |
148 | set: function( elem, value ) { |
|
176 | if ( jQuery.isArray( value ) ) { |
149 | if ( jQuery.isArray( value ) ) { |
|
177 | return ( elem.checked = jQuery.inArray( jQuery( elem ).val(), value ) > -1 ); |
150 | return ( elem.checked = jQuery.inArray( jQuery(elem).val(), value ) >= 0 ); |
|
178 | } |
151 | } |
|
179 | } |
152 | } |
|
180 | }; |
153 | }; |
|
181 | if ( !support.checkOn ) { |
154 | if ( !support.checkOn ) { |
|
182 | jQuery.valHooks[ this ].get = function( elem ) { |
155 | jQuery.valHooks[ this ].get = function( elem ) { |
|
183 | return elem.getAttribute( "value" ) === null ? "on" : elem.value; |
156 | return elem.getAttribute("value") === null ? "on" : elem.value; |
|
Line 184... | Line 157... | |||
184 | }; |
157 | }; |