From ac9e3016645078e1e42120822cfb2076151c8cbe Mon Sep 17 00:00:00 2001 From: karan-96 Date: Tue, 17 Jan 2017 22:22:50 +0530 Subject: [PATCH] Core: Deprecate jQuery.nodeName Fixes gh-3475 Closes gh-3505 --- src/attributes/attr.js | 5 +++-- src/attributes/val.js | 7 ++++--- src/core.js | 4 ---- src/core/nodeName.js | 13 +++++++++++++ src/deprecated.js | 8 +++++--- src/event.js | 8 +++++--- src/manipulation.js | 7 ++++--- src/manipulation/getAll.js | 7 ++++--- src/offset.js | 6 ++++-- src/traversing.js | 7 ++++--- test/unit/core.js | 4 ++-- test/unit/manipulation.js | 16 ++++++++-------- 12 files changed, 56 insertions(+), 36 deletions(-) create mode 100644 src/core/nodeName.js diff --git a/src/attributes/attr.js b/src/attributes/attr.js index 2d9c76feb..6b5cbd2c4 100644 --- a/src/attributes/attr.js +++ b/src/attributes/attr.js @@ -1,10 +1,11 @@ define( [ "../core", "../core/access", + "../core/nodeName", "./support", "../var/rnothtmlwhite", "../selector" -], function( jQuery, access, support, rnothtmlwhite ) { +], function( jQuery, access, nodeName, support, rnothtmlwhite ) { "use strict"; @@ -74,7 +75,7 @@ jQuery.extend( { type: { set: function( elem, value ) { if ( !support.radioValue && value === "radio" && - jQuery.nodeName( elem, "input" ) ) { + nodeName( elem, "input" ) ) { var val = elem.value; elem.setAttribute( "type", value ); if ( val ) { diff --git a/src/attributes/val.js b/src/attributes/val.js index 9245e4e0a..04572ba05 100644 --- a/src/attributes/val.js +++ b/src/attributes/val.js @@ -2,8 +2,9 @@ define( [ "../core", "../core/stripAndCollapse", "./support", - "../core/init" -], function( jQuery, stripAndCollapse, support ) { + "../core/init", + "../core/nodeName" +], function( jQuery, stripAndCollapse, support, nodeName ) { "use strict"; @@ -121,7 +122,7 @@ jQuery.extend( { // Don't return options that are disabled or in a disabled optgroup !option.disabled && ( !option.parentNode.disabled || - !jQuery.nodeName( option.parentNode, "optgroup" ) ) ) { + !nodeName( option.parentNode, "optgroup" ) ) ) { // Get the specific value for the option value = jQuery( option ).val(); diff --git a/src/core.js b/src/core.js index c99f27e22..54b44b1ea 100644 --- a/src/core.js +++ b/src/core.js @@ -289,10 +289,6 @@ jQuery.extend( { return string.replace( rmsPrefix, "ms-" ).replace( rdashAlpha, fcamelCase ); }, - nodeName: function( elem, name ) { - return elem.nodeName && elem.nodeName.toLowerCase() === name.toLowerCase(); - }, - each: function( obj, callback ) { var length, i = 0; diff --git a/src/core/nodeName.js b/src/core/nodeName.js new file mode 100644 index 000000000..8a5f5f036 --- /dev/null +++ b/src/core/nodeName.js @@ -0,0 +1,13 @@ +define( function() { + +"use strict"; + +function nodeName( elem, name ) { + + return elem.nodeName && elem.nodeName.toLowerCase() === name.toLowerCase(); + +}; + +return nodeName; + +} ); diff --git a/src/deprecated.js b/src/deprecated.js index 3c902657e..a18089c41 100644 --- a/src/deprecated.js +++ b/src/deprecated.js @@ -1,6 +1,7 @@ define( [ - "./core" -], function( jQuery ) { + "./core", + "./core/nodeName" +], function( jQuery, nodeName ) { "use strict"; @@ -29,7 +30,8 @@ jQuery.fn.extend( { } else { jQuery.ready( true ); } - } +}, + nodeName: nodeName } ); jQuery.isArray = Array.isArray; diff --git a/src/event.js b/src/event.js index 97431773c..6a07fba8e 100644 --- a/src/event.js +++ b/src/event.js @@ -7,8 +7,10 @@ define( [ "./var/slice", "./data/var/dataPriv", "./core/init", + "./core/nodeName", "./selector" -], function( jQuery, document, documentElement, rnothtmlwhite, rcheckableType, slice, dataPriv ) { +], function( jQuery, document, documentElement, rnothtmlwhite, rcheckableType, slice, dataPriv, + nodeName ) { "use strict"; @@ -477,7 +479,7 @@ jQuery.event = { // For checkable types, fire native event so checked state will be right trigger: function() { if ( rcheckableType.test( this.type ) && - this.click && jQuery.nodeName( this, "input" ) ) { + this.click && nodeName( this, "input" ) ) { this.click(); return false; @@ -486,7 +488,7 @@ jQuery.event = { // For cross-browser consistency, don't fire native .click() on links _default: function( event ) { - return jQuery.nodeName( event.target, "a" ); + return nodeName( event.target, "a" ); } }, diff --git a/src/manipulation.js b/src/manipulation.js index cadd89a2e..4e64cd132 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -18,13 +18,14 @@ define( [ "./core/DOMEval", "./core/init", + "./core/nodeName", "./traversing", "./selector", "./event" ], function( jQuery, concat, push, rcheckableType, access, rtagName, rscriptType, wrapMap, getAll, setGlobalEval, buildFragment, support, - dataPriv, dataUser, acceptData, DOMEval ) { + dataPriv, dataUser, acceptData, DOMEval, nodeName ) { "use strict"; @@ -49,8 +50,8 @@ var // Prefer a tbody over its parent table for containing new rows function manipulationTarget( elem, content ) { - if ( jQuery.nodeName( elem, "table" ) && - jQuery.nodeName( content.nodeType !== 11 ? content : content.firstChild, "tr" ) ) { + if ( nodeName( elem, "table" ) && + nodeName( content.nodeType !== 11 ? content : content.firstChild, "tr" ) ) { return jQuery( ">tbody", elem )[ 0 ] || elem; } diff --git a/src/manipulation/getAll.js b/src/manipulation/getAll.js index f68e3219e..fede6c78a 100644 --- a/src/manipulation/getAll.js +++ b/src/manipulation/getAll.js @@ -1,6 +1,7 @@ define( [ - "../core" -], function( jQuery ) { + "../core", + "../core/nodeName" +], function( jQuery, nodeName ) { "use strict"; @@ -20,7 +21,7 @@ function getAll( context, tag ) { ret = []; } - if ( tag === undefined || tag && jQuery.nodeName( context, tag ) ) { + if ( tag === undefined || tag && nodeName( context, tag ) ) { return jQuery.merge( [ context ], ret ); } diff --git a/src/offset.js b/src/offset.js index 467526d2a..1e5e04079 100644 --- a/src/offset.js +++ b/src/offset.js @@ -9,9 +9,11 @@ define( [ "./css/support", "./core/init", + "./core/nodeName", "./css", "./selector" // contains -], function( jQuery, access, document, documentElement, rnumnonpx, curCSS, addGetHookIf, support ) { +], function( jQuery, access, document, documentElement, rnumnonpx, curCSS, addGetHookIf, support, + nodeName ) { "use strict"; @@ -129,7 +131,7 @@ jQuery.fn.extend( { // Get correct offsets offset = this.offset(); - if ( !jQuery.nodeName( offsetParent[ 0 ], "html" ) ) { + if ( !nodeName( offsetParent[ 0 ], "html" ) ) { parentOffset = offsetParent.offset(); } diff --git a/src/traversing.js b/src/traversing.js index d96869017..cd7f747d5 100644 --- a/src/traversing.js +++ b/src/traversing.js @@ -5,9 +5,10 @@ define( [ "./traversing/var/siblings", "./traversing/var/rneedsContext", "./core/init", + "./core/nodeName", "./traversing/findFilter", "./selector" -], function( jQuery, indexOf, dir, siblings, rneedsContext ) { +], function( jQuery, indexOf, dir, siblings, rneedsContext, nodeName ) { "use strict"; @@ -143,14 +144,14 @@ jQuery.each( { return siblings( elem.firstChild ); }, contents: function( elem ) { - if ( jQuery.nodeName( elem, "iframe" ) ) { + if ( nodeName( elem, "iframe" ) ) { return elem.contentDocument; } // Support: IE 9 - 11 only, iOS 7 only, Android Browser <=4.3 only // Treat the template element as a regular one in browsers that // don't support it. - if ( jQuery.nodeName( elem, "template" ) ) { + if ( nodeName( elem, "template" ) ) { elem = elem.content || elem; } diff --git a/test/unit/core.js b/test/unit/core.js index 312e20ad0..adccfb58f 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -696,7 +696,7 @@ QUnit.test( "jQuery(element with non-alphanumeric name)", function( assert ) { var tagName = tag + symbol + "test"; var el = jQuery( "<" + tagName + ">" ); assert.ok( el[ 0 ], "Create a " + tagName + " element" ); - assert.ok( jQuery.nodeName( el[ 0 ], tagName.toUpperCase() ), + assert.ok( el[ 0 ].nodeName === tagName.toUpperCase(), tagName + " element has expected node name" ); } ); @@ -704,7 +704,7 @@ QUnit.test( "jQuery(element with non-alphanumeric name)", function( assert ) { var tagName = [ "tr", "multiple", "symbol" ].join( symbol ); var el = jQuery( "<" + tagName + ">" ); assert.ok( el[ 0 ], "Create a " + tagName + " element" ); - assert.ok( jQuery.nodeName( el[ 0 ], tagName.toUpperCase() ), + assert.ok( el[ 0 ].nodeName === tagName.toUpperCase(), tagName + " element has expected node name" ); } ); } ); diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index b1c04dbd5..5959d32bd 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -474,13 +474,13 @@ QUnit.test( "html(String) tag-hyphenated elements (Bug #1987)", function( assert jQuery.each( "thead tbody tfoot colgroup caption tr th td".split( " " ), function( i, name ) { var j = jQuery( "<" + name + "-d><" + name + "-d>" ); assert.ok( j[ 0 ], "Create a tag-hyphenated element" ); - assert.ok( jQuery.nodeName( j[ 0 ], name.toUpperCase() + "-D" ), "Hyphenated node name" ); - assert.ok( jQuery.nodeName( j[ 1 ], name.toUpperCase() + "-D" ), "Hyphenated node name" ); + assert.ok( j[ 0 ].nodeName === name.toUpperCase() + "-D", "Hyphenated node name" ); + assert.ok( j[ 1 ].nodeName === name.toUpperCase() + "-D", "Hyphenated node name" ); } ); var j = jQuery( "text" ); - assert.ok( jQuery.nodeName( j[ 0 ], "TR-MULTIPLE-HYPHENS" ), "Tags with multiple hyphens" ); - assert.ok( jQuery.nodeName( j.children()[ 0 ], "TD-WITH-HYPHEN" ), "Tags with multiple hyphens" ); + assert.ok( j[ 0 ].nodeName === "TR-MULTIPLE-HYPHENS", "Tags with multiple hyphens" ); + assert.ok( j.children()[ 0 ].nodeName === "TD-WITH-HYPHEN", "Tags with multiple hyphens" ); assert.equal( j.children().text(), "text", "Tags with multiple hyphens behave normally" ); } ); @@ -2616,14 +2616,14 @@ QUnit.test( "Make sure specific elements with content created correctly (#13232) jQuery.each( elems, function( name, value ) { var html = "<" + name + ">" + value + ""; - assert.ok( jQuery.nodeName( jQuery.parseHTML( "<" + name + ">" + value + "" )[ 0 ], name ), name + " is created correctly" ); + assert.ok( jQuery.parseHTML( "<" + name + ">" + value + "" )[ 0 ].nodeName.toLowerCase() === name, name + " is created correctly" ); results.push( name ); args.push( html ); } ); jQuery.fn.append.apply( jQuery( "
" ), args ).children().each( function( i ) { - assert.ok( jQuery.nodeName( this, results[ i ] ) ); + assert.ok( this.nodeName.toLowerCase() === results[ i ] ); } ); } ); @@ -2634,11 +2634,11 @@ QUnit.test( "Validate creation of multiple quantities of certain elements (#1381 jQuery.each( tags, function( index, tag ) { jQuery( "<" + tag + "/><" + tag + "/>" ).each( function() { - assert.ok( jQuery.nodeName( this, tag ), tag + " empty elements created correctly" ); + assert.ok( this.nodeName.toLowerCase() === tag, tag + " empty elements created correctly" ); } ); jQuery( "<" + this + "><" + tag + ">" ).each( function() { - assert.ok( jQuery.nodeName( this, tag ), tag + " elements with closing tag created correctly" ); + assert.ok( this.nodeName.toLowerCase() === tag, tag + " elements with closing tag created correctly" ); } ); } ); } ); -- 2.39.5