diff options
author | Matthieu Aubry <mattab@users.noreply.github.com> | 2016-06-28 08:50:40 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-06-28 08:50:40 +0300 |
commit | 02daed6db8fb7269d1b3a466cbb32ed7fab76e85 (patch) | |
tree | a534b2905593d44eece6a9f896522e524cb0d28f /libs/bower_components/jquery/src/attributes/attr.js | |
parent | f981b2579a95ce60a2b7d2aa146925b4d2222e0a (diff) |
Update JQuery to the latest 1.12.4 version (#10260)
* Update JQuery to the latest 1.* version
* UI tests: Updated Jquery to latest version
Diffstat (limited to 'libs/bower_components/jquery/src/attributes/attr.js')
-rw-r--r-- | libs/bower_components/jquery/src/attributes/attr.js | 132 |
1 files changed, 71 insertions, 61 deletions
diff --git a/libs/bower_components/jquery/src/attributes/attr.js b/libs/bower_components/jquery/src/attributes/attr.js index 47639c97eb..127c418f9e 100644 --- a/libs/bower_components/jquery/src/attributes/attr.js +++ b/libs/bower_components/jquery/src/attributes/attr.js @@ -1,12 +1,11 @@ -define([ +define( [ "../core", - "../var/rnotwhite", - "../var/strundefined", "../core/access", "./support", + "../var/rnotwhite", "./val", "../selector" -], function( jQuery, rnotwhite, strundefined, access, support ) { +], function( jQuery, access, support, rnotwhite ) { var nodeHook, boolHook, attrHandle = jQuery.expr.attrHandle, @@ -14,30 +13,30 @@ var nodeHook, boolHook, getSetAttribute = support.getSetAttribute, getSetInput = support.input; -jQuery.fn.extend({ +jQuery.fn.extend( { attr: function( name, value ) { return access( this, jQuery.attr, name, value, arguments.length > 1 ); }, removeAttr: function( name ) { - return this.each(function() { + return this.each( function() { jQuery.removeAttr( this, name ); - }); + } ); } -}); +} ); -jQuery.extend({ +jQuery.extend( { attr: function( elem, name, value ) { - var hooks, ret, + var ret, hooks, nType = elem.nodeType; - // don't get/set attributes on text, comment and attribute nodes - if ( !elem || nType === 3 || nType === 8 || nType === 2 ) { + // Don't get/set attributes on text, comment and attribute nodes + if ( nType === 3 || nType === 8 || nType === 2 ) { return; } // Fallback to prop when attributes are not supported - if ( typeof elem.getAttribute === strundefined ) { + if ( typeof elem.getAttribute === "undefined" ) { return jQuery.prop( elem, name, value ); } @@ -50,28 +49,46 @@ jQuery.extend({ } if ( value !== undefined ) { - if ( value === null ) { jQuery.removeAttr( elem, name ); + return; + } - } else if ( hooks && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ) { + if ( hooks && "set" in hooks && + ( ret = hooks.set( elem, value, name ) ) !== undefined ) { return ret; - - } else { - elem.setAttribute( name, value + "" ); - return value; } - } else if ( hooks && "get" in hooks && (ret = hooks.get( elem, name )) !== null ) { + elem.setAttribute( name, value + "" ); + return value; + } + + if ( hooks && "get" in hooks && ( ret = hooks.get( elem, name ) ) !== null ) { return ret; + } - } else { - ret = jQuery.find.attr( elem, name ); + ret = jQuery.find.attr( elem, name ); - // Non-existent attributes return null, we normalize to undefined - return ret == null ? - undefined : - ret; + // Non-existent attributes return null, we normalize to undefined + return ret == null ? undefined : ret; + }, + + attrHooks: { + type: { + set: function( elem, value ) { + if ( !support.radioValue && value === "radio" && + jQuery.nodeName( elem, "input" ) ) { + + // Setting the type on a radio button after the value resets the value in IE8-9 + // Reset value to default in case type is set after value during creation + var val = elem.value; + elem.setAttribute( "type", value ); + if ( val ) { + elem.value = val; + } + return value; + } + } } }, @@ -81,14 +98,16 @@ jQuery.extend({ attrNames = value && value.match( rnotwhite ); if ( attrNames && elem.nodeType === 1 ) { - while ( (name = attrNames[i++]) ) { + while ( ( name = attrNames[ i++ ] ) ) { propName = jQuery.propFix[ name ] || name; // Boolean attributes get special treatment (#10870) if ( jQuery.expr.match.bool.test( name ) ) { + // Set corresponding property to false if ( getSetInput && getSetAttribute || !ruseDefault.test( name ) ) { elem[ propName ] = false; + // Support: IE<9 // Also clear defaultChecked/defaultSelected (if appropriate) } else { @@ -104,54 +123,39 @@ jQuery.extend({ elem.removeAttribute( getSetAttribute ? name : propName ); } } - }, - - attrHooks: { - type: { - set: function( elem, value ) { - if ( !support.radioValue && value === "radio" && jQuery.nodeName(elem, "input") ) { - // Setting the type on a radio button after the value resets the value in IE6-9 - // Reset value to default in case type is set after value during creation - var val = elem.value; - elem.setAttribute( "type", value ); - if ( val ) { - elem.value = val; - } - return value; - } - } - } } -}); +} ); -// Hook for boolean attributes +// Hooks for boolean attributes boolHook = { set: function( elem, value, name ) { if ( value === false ) { + // Remove boolean attributes when set to false jQuery.removeAttr( elem, name ); } else if ( getSetInput && getSetAttribute || !ruseDefault.test( name ) ) { + // IE<8 needs the *property* name elem.setAttribute( !getSetAttribute && jQuery.propFix[ name ] || name, name ); - // Use defaultChecked and defaultSelected for oldIE } else { + + // Support: IE<9 + // Use defaultChecked and defaultSelected for oldIE elem[ jQuery.camelCase( "default-" + name ) ] = elem[ name ] = true; } - return name; } }; -// Retrieve booleans specially jQuery.each( jQuery.expr.match.bool.source.match( /\w+/g ), function( i, name ) { - var getter = attrHandle[ name ] || jQuery.find.attr; - attrHandle[ name ] = getSetInput && getSetAttribute || !ruseDefault.test( name ) ? - function( elem, name, isXML ) { + if ( getSetInput && getSetAttribute || !ruseDefault.test( name ) ) { + attrHandle[ name ] = function( elem, name, isXML ) { var ret, handle; if ( !isXML ) { + // Avoid an infinite loop by temporarily removing this function from the getter handle = attrHandle[ name ]; attrHandle[ name ] = ret; @@ -161,24 +165,28 @@ jQuery.each( jQuery.expr.match.bool.source.match( /\w+/g ), function( i, name ) attrHandle[ name ] = handle; } return ret; - } : - function( elem, name, isXML ) { + }; + } else { + attrHandle[ name ] = function( elem, name, isXML ) { if ( !isXML ) { return elem[ jQuery.camelCase( "default-" + name ) ] ? name.toLowerCase() : null; } }; -}); + } +} ); // fix oldIE attroperties if ( !getSetInput || !getSetAttribute ) { jQuery.attrHooks.value = { set: function( elem, value, name ) { if ( jQuery.nodeName( elem, "input" ) ) { + // Does not return so that setAttribute is also used elem.defaultValue = value; } else { + // Use nodeHook if defined (#1954); otherwise setAttribute is fine return nodeHook && nodeHook.set( elem, value, name ); } @@ -193,11 +201,12 @@ if ( !getSetAttribute ) { // This fixes almost every IE6/7 issue nodeHook = { set: function( elem, value, name ) { + // Set the existing or create a new attribute node var ret = elem.getAttributeNode( name ); if ( !ret ) { elem.setAttributeNode( - (ret = elem.ownerDocument.createAttribute( name )) + ( ret = elem.ownerDocument.createAttribute( name ) ) ); } @@ -215,7 +224,7 @@ if ( !getSetAttribute ) { function( elem, name, isXML ) { var ret; if ( !isXML ) { - return (ret = elem.getAttributeNode( name )) && ret.value !== "" ? + return ( ret = elem.getAttributeNode( name ) ) && ret.value !== "" ? ret.value : null; } @@ -242,7 +251,7 @@ if ( !getSetAttribute ) { // Set width and height to auto instead of 0 on empty string( Bug #8150 ) // This is for removals - jQuery.each([ "width", "height" ], function( i, name ) { + jQuery.each( [ "width", "height" ], function( i, name ) { jQuery.attrHooks[ name ] = { set: function( elem, value ) { if ( value === "" ) { @@ -251,15 +260,16 @@ if ( !getSetAttribute ) { } } }; - }); + } ); } if ( !support.style ) { jQuery.attrHooks.style = { get: function( elem ) { + // Return undefined in the case of empty string // Note: IE uppercases css property names, but if we were to .toLowerCase() - // .cssText, that would destroy case senstitivity in URL's, like in "background" + // .cssText, that would destroy case sensitivity in URL's, like in "background" return elem.style.cssText || undefined; }, set: function( elem, value ) { @@ -268,4 +278,4 @@ if ( !support.style ) { }; } -}); +} ); |