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 -... | Line 18... | |||
- | 18 | if ( hooks && "get" in hooks && (ret = hooks.get( elem, "value" )) !== undefined ) { |
||
25 | ) { |
19 | return ret; |
|
26 | 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 80... | Line 71... | |||
80 | |
71 | |
|
81 | jQuery.extend( { |
72 | jQuery.extend({ |
|
82 | valHooks: { |
73 | valHooks: { |
|
83 | option: { |
74 | option: { |
|
84 | get: function( elem ) { |
- | ||
85 | |
75 | get: function( elem ) { |
|
86 | var val = jQuery.find.attr( elem, "value" ); |
76 | var val = jQuery.find.attr( elem, "value" ); |
|
87 | return val != null ? |
77 | return val != null ? |
|
88 | val : |
- | ||
89 | |
78 | val : |
|
90 | // Support: IE <=10 - 11 only |
79 | // Support: IE10-11+ |
|
91 | // option.text throws exceptions (#14686, #14858) |
- | ||
92 | // Strip and collapse whitespace |
- | ||
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, |
88 | index = elem.selectedIndex, |
|
102 | one = elem.type === "select-one", |
89 | one = elem.type === "select-one" || index < 0, |
|
103 | values = one ? null : [], |
90 | values = one ? null : [], |
|
104 | max = one ? index + 1 : options.length; |
- | ||
105 | |
91 | max = one ? index + 1 : options.length, |
|
106 | if ( index < 0 ) { |
92 | i = index < 0 ? |
|
107 | i = max; |
- | ||
108 | |
- | ||
109 | } else { |
93 | max : |
|
110 | i = one ? index : 0; |
- | ||
Line 111... | Line 94... | |||
111 | } |
94 | one ? index : 0; |
|
112 | |
95 | |
|
113 | // Loop through all the selected options |
96 | // Loop through all the selected options |
|
Line 114... | Line -... | |||
114 | for ( ; i < max; i++ ) { |
- | ||
115 | option = options[ i ]; |
97 | for ( ; i < max; i++ ) { |
|
116 | |
98 | option = options[ i ]; |
|
117 | // Support: IE <=9 only |
- | ||
118 | // IE8-9 doesn't update selected after form reset (#2551) |
99 | |
|
119 | if ( ( option.selected || i === index ) && |
- | ||
120 | |
100 | // IE6-9 doesn't update selected after form reset (#2551) |
|
121 | // Don't return options that are disabled or in a disabled optgroup |
101 | if ( ( option.selected || i === index ) && |
|
Line 122... | Line 102... | |||
122 | !option.disabled && |
102 | // Don't return options that are disabled or in a disabled optgroup |
|
123 | ( !option.parentNode.disabled || |
103 | ( support.optDisabled ? !option.disabled : option.getAttribute( "disabled" ) === null ) && |
|
Line 124... | Line 104... | |||
124 | !jQuery.nodeName( option.parentNode, "optgroup" ) ) ) { |
104 | ( !option.parentNode.disabled || !jQuery.nodeName( option.parentNode, "optgroup" ) ) ) { |
|
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 |
|
Line 172... | Line 145... | |||
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 ) { |