diff options
author | Oleg Gaidarenko <markelog@gmail.com> | 2015-08-16 09:59:58 +0300 |
---|---|---|
committer | Oleg Gaidarenko <markelog@gmail.com> | 2015-09-07 20:03:50 +0300 |
commit | 10fdad742a2a6aa9f0e00b3e04fc5264797c53c7 (patch) | |
tree | 6b6d7b1375ff88f4bebbfa0703f7b595eb485df9 /src/attributes/val.js | |
parent | 7aa46e0df8a673e6b00550bbbbed21eed50108b7 (diff) | |
download | jquery-10fdad742a2a6aa9f0e00b3e04fc5264797c53c7.tar.gz jquery-10fdad742a2a6aa9f0e00b3e04fc5264797c53c7.zip |
Build: Update jscs and lint files
Fixes gh-2056
Diffstat (limited to 'src/attributes/val.js')
-rw-r--r-- | src/attributes/val.js | 46 |
1 files changed, 27 insertions, 19 deletions
diff --git a/src/attributes/val.js b/src/attributes/val.js index 1bb9072e6..9999d985b 100644 --- a/src/attributes/val.js +++ b/src/attributes/val.js @@ -1,4 +1,4 @@ -define([ +define( [ "../core", "./support", "../core/init" @@ -6,25 +6,30 @@ define([ 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() ]; - 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, "") : + ret.replace( rreturn, "" ) : + // Handle cases where value is null/undef or number ret == null ? "" : ret; } @@ -34,7 +39,7 @@ jQuery.fn.extend({ isFunction = jQuery.isFunction( value ); - return this.each(function( i ) { + return this.each( function( i ) { var val; if ( this.nodeType !== 1 ) { @@ -57,23 +62,24 @@ jQuery.fn.extend({ } 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 ) { + // Support: IE<11 // option.value not trimmed (#14858) return jQuery.trim( elem.value ); @@ -97,6 +103,7 @@ jQuery.extend({ // 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 ) && @@ -127,8 +134,9 @@ jQuery.extend({ while ( i-- ) { option = options[ i ]; - if ( (option.selected = - jQuery.inArray( jQuery.valHooks.option.get( option ), values ) > -1) ) { + if ( option.selected = + jQuery.inArray( jQuery.valHooks.option.get( option ), values ) > -1 + ) { optionSet = true; } } @@ -141,22 +149,22 @@ jQuery.extend({ } } } -}); +} ); // 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 ) > -1 ); } } }; 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; }; } -}); +} ); -}); +} ); |