diff options
Diffstat (limited to 'libs/bower_components/jquery/src/attributes/val.js')
-rw-r--r-- | libs/bower_components/jquery/src/attributes/val.js | 93 |
1 files changed, 46 insertions, 47 deletions
diff --git a/libs/bower_components/jquery/src/attributes/val.js b/libs/bower_components/jquery/src/attributes/val.js index 4a3b0e5c17..1fa91713df 100644 --- a/libs/bower_components/jquery/src/attributes/val.js +++ b/libs/bower_components/jquery/src/attributes/val.js @@ -1,30 +1,37 @@ -define([ +define( [ "../core", "./support", "../core/init" ], function( jQuery, support ) { -var rreturn = /\r/g; +var rreturn = /\r/g, + rspaces = /[\x20\t\r\n\f]+/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; return typeof ret === "string" ? - // handle most common string cases - ret.replace(rreturn, "") : - // handle cases where value is null/undef or number + + // Handle most common string cases + ret.replace( rreturn, "" ) : + + // Handle cases where value is null/undef or number ret == null ? "" : ret; } @@ -33,7 +40,7 @@ jQuery.fn.extend({ isFunction = jQuery.isFunction( value ); - return this.each(function( i ) { + return this.each( function( i ) { var val; if ( this.nodeType !== 1 ) { @@ -49,34 +56,40 @@ jQuery.fn.extend({ // 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 + ""; - }); + } ); } 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: IE10-11+ // option.text throws exceptions (#14686, #14858) - jQuery.trim( jQuery.text( elem ) ); + // Strip and collapse whitespace + // https://html.spec.whatwg.org/#strip-and-collapse-whitespace + jQuery.trim( jQuery.text( elem ) ).replace( rspaces, " " ); } }, select: { @@ -95,11 +108,14 @@ jQuery.extend({ for ( ; i < max; i++ ) { option = options[ i ]; - // oldIE doesn't update selected after form reset (#2551) + // IE8-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 - ( support.optDisabled ? !option.disabled : option.getAttribute("disabled") === null ) && - ( !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(); @@ -125,24 +141,10 @@ jQuery.extend({ while ( i-- ) { option = options[ i ]; - - if ( jQuery.inArray( jQuery.valHooks.option.get( option ), values ) >= 0 ) { - - // Support: IE6 - // When new option element is added to select box we need to - // force reflow of newly added node in order to workaround delay - // of initialization properties - try { - option.selected = optionSet = true; - - } catch ( _ ) { - - // Will be executed only in IE6 - option.scrollHeight; - } - - } else { - option.selected = false; + if ( option.selected = + jQuery.inArray( jQuery.valHooks.option.get( option ), values ) > -1 + ) { + optionSet = true; } } @@ -150,29 +152,26 @@ jQuery.extend({ if ( !optionSet ) { elem.selectedIndex = -1; } - - return options; + return values; } } } -}); +} ); // 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 ) >= 0 ); + return ( elem.checked = jQuery.inArray( jQuery( elem ).val(), value ) > -1 ); } } }; if ( !support.checkOn ) { jQuery.valHooks[ this ].get = function( elem ) { - // Support: Webkit - // "" is returned instead of "on" if a value isn't specified - return elem.getAttribute("value") === null ? "on" : elem.value; + return elem.getAttribute( "value" ) === null ? "on" : elem.value; }; } -}); +} ); -}); +} ); |