mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Make sure that disconnected nodes aren't sorted/uniqued. Fixes #5791.
This commit is contained in:
parent
8e53f7b5d6
commit
5d49335eac
@ -146,9 +146,9 @@ jQuery.fn.extend({
|
|||||||
jQuery.makeArray( selector ),
|
jQuery.makeArray( selector ),
|
||||||
all = jQuery.merge( this.get(), set );
|
all = jQuery.merge( this.get(), set );
|
||||||
|
|
||||||
return this.pushStack( set[0] && (set[0].setInterval || set[0].nodeType === 9 || (set[0].parentNode && set[0].parentNode.nodeType !== 11)) ?
|
return this.pushStack( isDisconnected( set[0] ) || isDisconnected( all[0] ) ?
|
||||||
jQuery.unique( all ) :
|
all :
|
||||||
all );
|
jQuery.unique( all ) );
|
||||||
},
|
},
|
||||||
|
|
||||||
andSelf: function() {
|
andSelf: function() {
|
||||||
@ -156,6 +156,12 @@ jQuery.fn.extend({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// A painfully simple check to see if an element is disconnected
|
||||||
|
// from a document (should be improved, where feasible).
|
||||||
|
function isDisconnected( node ) {
|
||||||
|
return !node || !node.parentNode || node.parentNode.nodeType === 11;
|
||||||
|
}
|
||||||
|
|
||||||
jQuery.each({
|
jQuery.each({
|
||||||
parent: function( elem ) {
|
parent: function( elem ) {
|
||||||
var parent = elem.parentNode;
|
var parent = elem.parentNode;
|
||||||
|
@ -501,6 +501,15 @@ test("add(String|Element|Array|undefined)", function() {
|
|||||||
// use jQuery([]).add(form.elements) instead.
|
// use jQuery([]).add(form.elements) instead.
|
||||||
//equals( jQuery([]).add(jQuery("#form")[0].elements).length, jQuery(jQuery("#form")[0].elements).length, "Array in constructor must equals array in add()" );
|
//equals( jQuery([]).add(jQuery("#form")[0].elements).length, jQuery(jQuery("#form")[0].elements).length, "Array in constructor must equals array in add()" );
|
||||||
|
|
||||||
|
var divs = jQuery("<div/>").add("#sndp");
|
||||||
|
ok( !divs[0].parentNode, "Make sure the first element is still the disconnected node." );
|
||||||
|
|
||||||
|
divs = jQuery("<div>test</div>").add("#sndp");
|
||||||
|
equals( divs[0].parentNode.nodeType, 11, "Make sure the first element is still the disconnected node." );
|
||||||
|
|
||||||
|
divs = jQuery("#sndp").add("<div/>");
|
||||||
|
ok( !divs[1].parentNode, "Make sure the first element is still the disconnected node." );
|
||||||
|
|
||||||
var tmp = jQuery("<div/>");
|
var tmp = jQuery("<div/>");
|
||||||
|
|
||||||
var x = jQuery([]).add(jQuery("<p id='x1'>xxx</p>").appendTo(tmp)).add(jQuery("<p id='x2'>xxx</p>").appendTo(tmp));
|
var x = jQuery([]).add(jQuery("<p id='x1'>xxx</p>").appendTo(tmp)).add(jQuery("<p id='x2'>xxx</p>").appendTo(tmp));
|
||||||
@ -522,10 +531,6 @@ test("add(String|Element|Array|undefined)", function() {
|
|||||||
var notDefined;
|
var notDefined;
|
||||||
equals( jQuery([]).add(notDefined).length, 0, "Check that undefined adds nothing" );
|
equals( jQuery([]).add(notDefined).length, 0, "Check that undefined adds nothing" );
|
||||||
|
|
||||||
// Added after #2811
|
|
||||||
equals( jQuery([]).add([window,document,document.body,document]).length, 3, "Pass an array" );
|
|
||||||
equals( jQuery(document).add(document).length, 1, "Check duplicated elements" );
|
|
||||||
equals( jQuery(window).add(window).length, 1, "Check duplicated elements using the window" );
|
|
||||||
ok( jQuery([]).add( document.getElementById('form') ).length >= 13, "Add a form (adds the elements)" );
|
ok( jQuery([]).add( document.getElementById('form') ).length >= 13, "Add a form (adds the elements)" );
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user