mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Core: Deprecate jQuery.nodeName
Fixes gh-3475 Closes gh-3505
This commit is contained in:
parent
bd984f0ee2
commit
ac9e301664
@ -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 ) {
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
|
||||
|
13
src/core/nodeName.js
Normal file
13
src/core/nodeName.js
Normal file
@ -0,0 +1,13 @@
|
||||
define( function() {
|
||||
|
||||
"use strict";
|
||||
|
||||
function nodeName( elem, name ) {
|
||||
|
||||
return elem.nodeName && elem.nodeName.toLowerCase() === name.toLowerCase();
|
||||
|
||||
};
|
||||
|
||||
return nodeName;
|
||||
|
||||
} );
|
@ -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;
|
||||
|
@ -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" );
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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 );
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -696,7 +696,7 @@ QUnit.test( "jQuery(element with non-alphanumeric name)", function( assert ) {
|
||||
var tagName = tag + symbol + "test";
|
||||
var el = jQuery( "<" + tagName + "></" + 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 + "></" + 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" );
|
||||
} );
|
||||
} );
|
||||
|
@ -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><" + 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( "<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( 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 + "</" + 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 );
|
||||
args.push( html );
|
||||
} );
|
||||
|
||||
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( "<" + 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() {
|
||||
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" );
|
||||
} );
|
||||
} );
|
||||
} );
|
||||
|
Loading…
Reference in New Issue
Block a user