Skip to content

Commit

Permalink
Manipulation:Selector: Use the nodeName util where possible to save size
Browse files Browse the repository at this point in the history
Saves 20 bytes.

Closes gh-4504
  • Loading branch information
mgol authored Oct 8, 2019
1 parent e0022f2 commit 4504fc3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/manipulation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
35 changes: 17 additions & 18 deletions src/selector.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
define( [
"./core",
"./core/nodeName",
"./var/document",
"./var/documentElement",
"./var/indexOf",
Expand All @@ -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";

Expand Down Expand Up @@ -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" }
);
Expand Down Expand Up @@ -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;
};
}

Expand All @@ -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;
};
}

Expand Down Expand Up @@ -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 );
};
},

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 ) {

Expand Down Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 ) {
Expand Down

0 comments on commit 4504fc3

Please sign in to comment.