/bower_components/jquery/src/attributes/val.js |
@@ -1,40 +1,31 @@ |
define( [ |
define([ |
"../core", |
"../core/stripAndCollapse", |
"./support", |
"../core/init" |
], function( jQuery, stripAndCollapse, support ) { |
], function( jQuery, support ) { |
|
"use strict"; |
|
var rreturn = /\r/g; |
|
jQuery.fn.extend( { |
jQuery.fn.extend({ |
val: function( value ) { |
var hooks, ret, isFunction, |
elem = this[ 0 ]; |
elem = this[0]; |
|
if ( !arguments.length ) { |
if ( elem ) { |
hooks = jQuery.valHooks[ elem.type ] || |
jQuery.valHooks[ elem.nodeName.toLowerCase() ]; |
hooks = jQuery.valHooks[ elem.type ] || jQuery.valHooks[ elem.nodeName.toLowerCase() ]; |
|
if ( hooks && |
"get" in hooks && |
( ret = hooks.get( elem, "value" ) ) !== undefined |
) { |
if ( hooks && "get" in hooks && (ret = hooks.get( elem, "value" )) !== undefined ) { |
return ret; |
} |
|
ret = elem.value; |
|
// 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; |
return typeof ret === "string" ? |
// Handle most common string cases |
ret.replace(rreturn, "") : |
// Handle cases where value is null/undef or number |
ret == null ? "" : ret; |
} |
|
return; |
@@ -42,7 +33,7 @@ |
|
isFunction = jQuery.isFunction( value ); |
|
return this.each( function( i ) { |
return this.each(function( i ) { |
var val; |
|
if ( this.nodeType !== 1 ) { |
@@ -65,63 +56,52 @@ |
} else if ( jQuery.isArray( val ) ) { |
val = jQuery.map( val, function( value ) { |
return value == null ? "" : value + ""; |
} ); |
}); |
} |
|
hooks = jQuery.valHooks[ this.type ] || jQuery.valHooks[ this.nodeName.toLowerCase() ]; |
|
// If set returns undefined, fall back to normal setting |
if ( !hooks || !( "set" in hooks ) || hooks.set( this, val, "value" ) === undefined ) { |
if ( !hooks || !("set" in hooks) || hooks.set( this, val, "value" ) === undefined ) { |
this.value = val; |
} |
} ); |
}); |
} |
} ); |
}); |
|
jQuery.extend( { |
jQuery.extend({ |
valHooks: { |
option: { |
get: function( elem ) { |
|
var val = jQuery.find.attr( elem, "value" ); |
return val != null ? |
val : |
|
// Support: IE <=10 - 11 only |
// Support: IE10-11+ |
// option.text throws exceptions (#14686, #14858) |
// Strip and collapse whitespace |
// https://html.spec.whatwg.org/#strip-and-collapse-whitespace |
stripAndCollapse( jQuery.text( elem ) ); |
jQuery.trim( jQuery.text( elem ) ); |
} |
}, |
select: { |
get: function( elem ) { |
var value, option, i, |
var value, option, |
options = elem.options, |
index = elem.selectedIndex, |
one = elem.type === "select-one", |
one = elem.type === "select-one" || index < 0, |
values = one ? null : [], |
max = one ? index + 1 : options.length; |
max = one ? index + 1 : options.length, |
i = index < 0 ? |
max : |
one ? index : 0; |
|
if ( index < 0 ) { |
i = max; |
|
} else { |
i = one ? index : 0; |
} |
|
// Loop through all the selected options |
for ( ; i < max; i++ ) { |
option = options[ i ]; |
|
// Support: IE <=9 only |
// IE8-9 doesn't update selected after form reset (#2551) |
// IE6-9 doesn't update selected after form reset (#2551) |
if ( ( option.selected || i === index ) && |
|
// Don't return options that are disabled or in a disabled optgroup |
!option.disabled && |
( !option.parentNode.disabled || |
!jQuery.nodeName( option.parentNode, "optgroup" ) ) ) { |
( support.optDisabled ? !option.disabled : option.getAttribute( "disabled" ) === null ) && |
( !option.parentNode.disabled || !jQuery.nodeName( option.parentNode, "optgroup" ) ) ) { |
|
// Get the specific value for the option |
value = jQuery( option ).val(); |
@@ -147,16 +127,9 @@ |
|
while ( i-- ) { |
option = options[ i ]; |
|
/* eslint-disable no-cond-assign */ |
|
if ( option.selected = |
jQuery.inArray( jQuery.valHooks.option.get( option ), values ) > -1 |
) { |
if ( (option.selected = jQuery.inArray( option.value, values ) >= 0) ) { |
optionSet = true; |
} |
|
/* eslint-enable no-cond-assign */ |
} |
|
// Force browsers to behave consistently when non-matching value is set |
@@ -167,22 +140,22 @@ |
} |
} |
} |
} ); |
}); |
|
// Radios and checkboxes getter/setter |
jQuery.each( [ "radio", "checkbox" ], function() { |
jQuery.each([ "radio", "checkbox" ], function() { |
jQuery.valHooks[ this ] = { |
set: function( elem, value ) { |
if ( jQuery.isArray( value ) ) { |
return ( elem.checked = jQuery.inArray( jQuery( elem ).val(), value ) > -1 ); |
return ( elem.checked = jQuery.inArray( jQuery(elem).val(), value ) >= 0 ); |
} |
} |
}; |
if ( !support.checkOn ) { |
jQuery.valHooks[ this ].get = function( elem ) { |
return elem.getAttribute( "value" ) === null ? "on" : elem.value; |
return elem.getAttribute("value") === null ? "on" : elem.value; |
}; |
} |
} ); |
}); |
|
} ); |
}); |