diff options
author | Michał Gołębiowski-Owczarek <m.goleb@gmail.com> | 2019-10-08 22:41:59 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-08 22:41:59 +0200 |
commit | 4504fc3d722dd029d861cb47aa65a5edc651c4d3 (patch) | |
tree | aac9d6759f131c7e826573d4e02ef528e9dfcfde | |
parent | e0022f23144fd1dc6db86a5d8c18af47bc14f0f3 (diff) | |
download | jquery-4504fc3d722dd029d861cb47aa65a5edc651c4d3.tar.gz jquery-4504fc3d722dd029d861cb47aa65a5edc651c4d3.zip |
Manipulation:Selector: Use the nodeName util where possible to save size
Saves 20 bytes.
Closes gh-4504
-rw-r--r-- | src/manipulation.js | 2 | ||||
-rw-r--r-- | src/selector.js | 35 |
2 files changed, 18 insertions, 19 deletions
diff --git a/src/manipulation.js b/src/manipulation.js index 11bd5b079..803a67bd6 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -229,7 +229,7 @@ jQuery.extend( { // Support: IE <=11+ // IE fails to set the defaultValue to the correct value when // cloning textareas. - if ( destElements[ i ].nodeName.toLowerCase() === "textarea" ) { + if ( nodeName( destElements[ i ], "textarea" ) ) { destElements[ i ].defaultValue = srcElements[ i ].defaultValue; } } diff --git a/src/selector.js b/src/selector.js index 183adbbac..ea7a7b591 100644 --- a/src/selector.js +++ b/src/selector.js @@ -1,5 +1,6 @@ define( [ "./core", + "./core/nodeName", "./var/document", "./var/documentElement", "./var/indexOf", @@ -12,7 +13,8 @@ define( [ "./selector/contains", "./selector/escapeSelector", "./selector/uniqueSort" -], function( jQuery, document, documentElement, indexOf, pop, push, rbuggyQSA, support ) { +], function( jQuery, nodeName, document, documentElement, indexOf, pop, push, + rbuggyQSA, support ) { "use strict"; @@ -145,7 +147,7 @@ var i, inDisabledFieldset = addCombinator( function( elem ) { - return elem.disabled === true && elem.nodeName.toLowerCase() === "fieldset"; + return elem.disabled === true && nodeName( elem, "fieldset" ); }, { dir: "parentNode", next: "legend" } ); @@ -310,8 +312,7 @@ function markFunction( fn ) { */ function createInputPseudo( type ) { return function( elem ) { - var name = elem.nodeName.toLowerCase(); - return name === "input" && elem.type === type; + return nodeName( elem, "input" ) && elem.type === type; }; } @@ -321,8 +322,8 @@ function createInputPseudo( type ) { */ function createButtonPseudo( type ) { return function( elem ) { - var name = elem.nodeName.toLowerCase(); - return ( name === "input" || name === "button" ) && elem.type === type; + return ( nodeName( elem, "input" ) || nodeName( elem, "button" ) ) && + elem.type === type; }; } @@ -603,13 +604,13 @@ Expr = jQuery.expr = { }, TAG: function( nodeNameSelector ) { - var nodeName = nodeNameSelector.replace( runescape, funescape ).toLowerCase(); + var expectedNodeName = nodeNameSelector.replace( runescape, funescape ).toLowerCase(); return nodeNameSelector === "*" ? function() { return true; } : function( elem ) { - return elem.nodeName && elem.nodeName.toLowerCase() === nodeName; + return nodeName( elem, expectedNodeName ); }; }, @@ -697,7 +698,7 @@ Expr = jQuery.expr = { node = elem; while ( ( node = node[ dir ] ) ) { if ( ofType ? - node.nodeName.toLowerCase() === name : + nodeName( node, name ) : node.nodeType === 1 ) { return false; @@ -753,7 +754,7 @@ Expr = jQuery.expr = { ( diff = nodeIndex = 0 ) || start.pop() ) ) { if ( ( ofType ? - node.nodeName.toLowerCase() === name : + nodeName( node, name ) : node.nodeType === 1 ) && ++diff ) { @@ -919,9 +920,8 @@ Expr = jQuery.expr = { // In CSS3, :checked should return both checked and selected elements // http://www.w3.org/TR/2011/REC-css3-selectors-20110929/#checked - var nodeName = elem.nodeName.toLowerCase(); - return ( nodeName === "input" && !!elem.checked ) || - ( nodeName === "option" && !!elem.selected ); + return ( nodeName( elem, "input" ) && !!elem.checked ) || + ( nodeName( elem, "option" ) && !!elem.selected ); }, selected: function( elem ) { @@ -967,13 +967,12 @@ Expr = jQuery.expr = { }, button: function( elem ) { - var name = elem.nodeName.toLowerCase(); - return name === "input" && elem.type === "button" || name === "button"; + return nodeName( elem, "input" ) && elem.type === "button" || + nodeName( elem, "button" ); }, text: function( elem ) { - return elem.nodeName.toLowerCase() === "input" && - elem.type === "text"; + return nodeName( elem, "input" ) && elem.type === "text"; }, // Position-in-collection @@ -1167,7 +1166,7 @@ function addCombinator( matcher, combinator, base ) { if ( elem.nodeType === 1 || checkNonElements ) { outerCache = elem[ expando ] || ( elem[ expando ] = {} ); - if ( skip && skip === elem.nodeName.toLowerCase() ) { + if ( skip && nodeName( elem, skip ) ) { elem = elem[ dir ] || elem; } else if ( ( oldCache = outerCache[ key ] ) && oldCache[ 0 ] === dirruns && oldCache[ 1 ] === doneName ) { |