Core: Deprecate jQuery.nodeName

Fixes gh-3475
Closes gh-3505
This commit is contained in:
karan-96 2017-01-17 22:22:50 +05:30 committed by Michał Gołębiowski
parent bd984f0ee2
commit ac9e301664
12 changed files with 56 additions and 36 deletions

View File

@ -1,10 +1,11 @@
define( [ define( [
"../core", "../core",
"../core/access", "../core/access",
"../core/nodeName",
"./support", "./support",
"../var/rnothtmlwhite", "../var/rnothtmlwhite",
"../selector" "../selector"
], function( jQuery, access, support, rnothtmlwhite ) { ], function( jQuery, access, nodeName, support, rnothtmlwhite ) {
"use strict"; "use strict";
@ -74,7 +75,7 @@ jQuery.extend( {
type: { type: {
set: function( elem, value ) { set: function( elem, value ) {
if ( !support.radioValue && value === "radio" && if ( !support.radioValue && value === "radio" &&
jQuery.nodeName( elem, "input" ) ) { nodeName( elem, "input" ) ) {
var val = elem.value; var val = elem.value;
elem.setAttribute( "type", value ); elem.setAttribute( "type", value );
if ( val ) { if ( val ) {

View File

@ -2,8 +2,9 @@ define( [
"../core", "../core",
"../core/stripAndCollapse", "../core/stripAndCollapse",
"./support", "./support",
"../core/init" "../core/init",
], function( jQuery, stripAndCollapse, support ) { "../core/nodeName"
], function( jQuery, stripAndCollapse, support, nodeName ) {
"use strict"; "use strict";
@ -121,7 +122,7 @@ jQuery.extend( {
// Don't return options that are disabled or in a disabled optgroup // Don't return options that are disabled or in a disabled optgroup
!option.disabled && !option.disabled &&
( !option.parentNode.disabled || ( !option.parentNode.disabled ||
!jQuery.nodeName( option.parentNode, "optgroup" ) ) ) { !nodeName( option.parentNode, "optgroup" ) ) ) {
// Get the specific value for the option // Get the specific value for the option
value = jQuery( option ).val(); value = jQuery( option ).val();

View File

@ -289,10 +289,6 @@ jQuery.extend( {
return string.replace( rmsPrefix, "ms-" ).replace( rdashAlpha, fcamelCase ); return string.replace( rmsPrefix, "ms-" ).replace( rdashAlpha, fcamelCase );
}, },
nodeName: function( elem, name ) {
return elem.nodeName && elem.nodeName.toLowerCase() === name.toLowerCase();
},
each: function( obj, callback ) { each: function( obj, callback ) {
var length, i = 0; var length, i = 0;

13
src/core/nodeName.js Normal file
View File

@ -0,0 +1,13 @@
define( function() {
"use strict";
function nodeName( elem, name ) {
return elem.nodeName && elem.nodeName.toLowerCase() === name.toLowerCase();
};
return nodeName;
} );

View File

@ -1,6 +1,7 @@
define( [ define( [
"./core" "./core",
], function( jQuery ) { "./core/nodeName"
], function( jQuery, nodeName ) {
"use strict"; "use strict";
@ -29,7 +30,8 @@ jQuery.fn.extend( {
} else { } else {
jQuery.ready( true ); jQuery.ready( true );
} }
} },
nodeName: nodeName
} ); } );
jQuery.isArray = Array.isArray; jQuery.isArray = Array.isArray;

View File

@ -7,8 +7,10 @@ define( [
"./var/slice", "./var/slice",
"./data/var/dataPriv", "./data/var/dataPriv",
"./core/init", "./core/init",
"./core/nodeName",
"./selector" "./selector"
], function( jQuery, document, documentElement, rnothtmlwhite, rcheckableType, slice, dataPriv ) { ], function( jQuery, document, documentElement, rnothtmlwhite, rcheckableType, slice, dataPriv,
nodeName ) {
"use strict"; "use strict";
@ -477,7 +479,7 @@ jQuery.event = {
// For checkable types, fire native event so checked state will be right // For checkable types, fire native event so checked state will be right
trigger: function() { trigger: function() {
if ( rcheckableType.test( this.type ) && if ( rcheckableType.test( this.type ) &&
this.click && jQuery.nodeName( this, "input" ) ) { this.click && nodeName( this, "input" ) ) {
this.click(); this.click();
return false; return false;
@ -486,7 +488,7 @@ jQuery.event = {
// For cross-browser consistency, don't fire native .click() on links // For cross-browser consistency, don't fire native .click() on links
_default: function( event ) { _default: function( event ) {
return jQuery.nodeName( event.target, "a" ); return nodeName( event.target, "a" );
} }
}, },

View File

@ -18,13 +18,14 @@ define( [
"./core/DOMEval", "./core/DOMEval",
"./core/init", "./core/init",
"./core/nodeName",
"./traversing", "./traversing",
"./selector", "./selector",
"./event" "./event"
], function( jQuery, concat, push, rcheckableType, ], function( jQuery, concat, push, rcheckableType,
access, rtagName, rscriptType, access, rtagName, rscriptType,
wrapMap, getAll, setGlobalEval, buildFragment, support, wrapMap, getAll, setGlobalEval, buildFragment, support,
dataPriv, dataUser, acceptData, DOMEval ) { dataPriv, dataUser, acceptData, DOMEval, nodeName ) {
"use strict"; "use strict";
@ -49,8 +50,8 @@ var
// Prefer a tbody over its parent table for containing new rows // Prefer a tbody over its parent table for containing new rows
function manipulationTarget( elem, content ) { function manipulationTarget( elem, content ) {
if ( jQuery.nodeName( elem, "table" ) && if ( nodeName( elem, "table" ) &&
jQuery.nodeName( content.nodeType !== 11 ? content : content.firstChild, "tr" ) ) { nodeName( content.nodeType !== 11 ? content : content.firstChild, "tr" ) ) {
return jQuery( ">tbody", elem )[ 0 ] || elem; return jQuery( ">tbody", elem )[ 0 ] || elem;
} }

View File

@ -1,6 +1,7 @@
define( [ define( [
"../core" "../core",
], function( jQuery ) { "../core/nodeName"
], function( jQuery, nodeName ) {
"use strict"; "use strict";
@ -20,7 +21,7 @@ function getAll( context, tag ) {
ret = []; ret = [];
} }
if ( tag === undefined || tag && jQuery.nodeName( context, tag ) ) { if ( tag === undefined || tag && nodeName( context, tag ) ) {
return jQuery.merge( [ context ], ret ); return jQuery.merge( [ context ], ret );
} }

View File

@ -9,9 +9,11 @@ define( [
"./css/support", "./css/support",
"./core/init", "./core/init",
"./core/nodeName",
"./css", "./css",
"./selector" // contains "./selector" // contains
], function( jQuery, access, document, documentElement, rnumnonpx, curCSS, addGetHookIf, support ) { ], function( jQuery, access, document, documentElement, rnumnonpx, curCSS, addGetHookIf, support,
nodeName ) {
"use strict"; "use strict";
@ -129,7 +131,7 @@ jQuery.fn.extend( {
// Get correct offsets // Get correct offsets
offset = this.offset(); offset = this.offset();
if ( !jQuery.nodeName( offsetParent[ 0 ], "html" ) ) { if ( !nodeName( offsetParent[ 0 ], "html" ) ) {
parentOffset = offsetParent.offset(); parentOffset = offsetParent.offset();
} }

View File

@ -5,9 +5,10 @@ define( [
"./traversing/var/siblings", "./traversing/var/siblings",
"./traversing/var/rneedsContext", "./traversing/var/rneedsContext",
"./core/init", "./core/init",
"./core/nodeName",
"./traversing/findFilter", "./traversing/findFilter",
"./selector" "./selector"
], function( jQuery, indexOf, dir, siblings, rneedsContext ) { ], function( jQuery, indexOf, dir, siblings, rneedsContext, nodeName ) {
"use strict"; "use strict";
@ -143,14 +144,14 @@ jQuery.each( {
return siblings( elem.firstChild ); return siblings( elem.firstChild );
}, },
contents: function( elem ) { contents: function( elem ) {
if ( jQuery.nodeName( elem, "iframe" ) ) { if ( nodeName( elem, "iframe" ) ) {
return elem.contentDocument; return elem.contentDocument;
} }
// Support: IE 9 - 11 only, iOS 7 only, Android Browser <=4.3 only // Support: IE 9 - 11 only, iOS 7 only, Android Browser <=4.3 only
// Treat the template element as a regular one in browsers that // Treat the template element as a regular one in browsers that
// don't support it. // don't support it.
if ( jQuery.nodeName( elem, "template" ) ) { if ( nodeName( elem, "template" ) ) {
elem = elem.content || elem; elem = elem.content || elem;
} }

View File

@ -696,7 +696,7 @@ QUnit.test( "jQuery(element with non-alphanumeric name)", function( assert ) {
var tagName = tag + symbol + "test"; var tagName = tag + symbol + "test";
var el = jQuery( "<" + tagName + "></" + tagName + ">" ); var el = jQuery( "<" + tagName + "></" + tagName + ">" );
assert.ok( el[ 0 ], "Create a " + tagName + " element" ); 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" ); 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 tagName = [ "tr", "multiple", "symbol" ].join( symbol );
var el = jQuery( "<" + tagName + "></" + tagName + ">" ); var el = jQuery( "<" + tagName + "></" + tagName + ">" );
assert.ok( el[ 0 ], "Create a " + tagName + " element" ); 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" ); tagName + " element has expected node name" );
} ); } );
} ); } );

View File

@ -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 ) { jQuery.each( "thead tbody tfoot colgroup caption tr th td".split( " " ), function( i, name ) {
var j = jQuery( "<" + name + "-d></" + name + "-d><" + name + "-d></" + name + "-d>" ); var j = jQuery( "<" + name + "-d></" + name + "-d><" + name + "-d></" + name + "-d>" );
assert.ok( j[ 0 ], "Create a tag-hyphenated element" ); assert.ok( j[ 0 ], "Create a tag-hyphenated element" );
assert.ok( jQuery.nodeName( j[ 0 ], name.toUpperCase() + "-D" ), "Hyphenated node name" ); assert.ok( j[ 0 ].nodeName === name.toUpperCase() + "-D", "Hyphenated node name" );
assert.ok( jQuery.nodeName( j[ 1 ], name.toUpperCase() + "-D" ), "Hyphenated node name" ); assert.ok( j[ 1 ].nodeName === name.toUpperCase() + "-D", "Hyphenated node name" );
} ); } );
var j = jQuery( "<tr-multiple-hyphens><td-with-hyphen>text</td-with-hyphen></tr-multiple-hyphens>" ); var j = jQuery( "<tr-multiple-hyphens><td-with-hyphen>text</td-with-hyphen></tr-multiple-hyphens>" );
assert.ok( jQuery.nodeName( j[ 0 ], "TR-MULTIPLE-HYPHENS" ), "Tags with multiple hyphens" ); assert.ok( j[ 0 ].nodeName === "TR-MULTIPLE-HYPHENS", "Tags with multiple hyphens" );
assert.ok( jQuery.nodeName( j.children()[ 0 ], "TD-WITH-HYPHEN" ), "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" ); 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 ) { jQuery.each( elems, function( name, value ) {
var html = "<" + name + ">" + value + "</" + name + ">"; var html = "<" + name + ">" + value + "</" + name + ">";
assert.ok( jQuery.nodeName( jQuery.parseHTML( "<" + name + ">" + value + "</" + name + ">" )[ 0 ], name ), name + " is created correctly" ); assert.ok( jQuery.parseHTML( "<" + name + ">" + value + "</" + name + ">" )[ 0 ].nodeName.toLowerCase() === name, name + " is created correctly" );
results.push( name ); results.push( name );
args.push( html ); args.push( html );
} ); } );
jQuery.fn.append.apply( jQuery( "<div/>" ), args ).children().each( function( i ) { jQuery.fn.append.apply( jQuery( "<div/>" ), 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.each( tags, function( index, tag ) {
jQuery( "<" + tag + "/><" + tag + "/>" ).each( function() { 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 + "><" + tag + "></" + tag + ">" ).each( function() { jQuery( "<" + this + "></" + tag + "><" + tag + "></" + 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" );
} ); } );
} ); } );
} ); } );