Merge branch 'master' of github.com:jquery/jquery

This commit is contained in:
John Resig 2011-04-17 11:58:58 -07:00
commit 7a8fac57eb
13 changed files with 171 additions and 171 deletions

44
src/effects.js vendored
View File

@ -173,7 +173,7 @@ jQuery.fn.extend({
this.style.display = "inline-block"; this.style.display = "inline-block";
} else { } else {
var display = defaultDisplay(this.nodeName); display = defaultDisplay(this.nodeName);
// inline-level elements accept inline-block; // inline-level elements accept inline-block;
// block-level elements need to be inline with layout // block-level elements need to be inline with layout
@ -274,6 +274,27 @@ jQuery.fn.extend({
}); });
// Animations created synchronously will run synchronously
function createFxNow() {
setTimeout( clearFxNow, 0 );
return ( fxNow = jQuery.now() );
}
function clearFxNow() {
fxNow = undefined;
}
// Generate parameters to create a standard animation
function genFx( type, num ) {
var obj = {};
jQuery.each( fxAttrs.concat.apply([], fxAttrs.slice(0,num)), function() {
obj[ this ] = type;
});
return obj;
}
// Generate shortcuts for custom animations // Generate shortcuts for custom animations
jQuery.each({ jQuery.each({
slideDown: genFx("show", 1), slideDown: genFx("show", 1),
@ -589,25 +610,4 @@ function defaultDisplay( nodeName ) {
return elemdisplay[ nodeName ]; return elemdisplay[ nodeName ];
} }
// Animations created synchronously will run synchronously
function createFxNow() {
setTimeout( clearFxNow, 0 );
return ( fxNow = jQuery.now() );
}
function clearFxNow() {
fxNow = undefined;
}
// Generate parameters to create a standard animation
function genFx( type, num ) {
var obj = {};
jQuery.each( fxAttrs.concat.apply([], fxAttrs.slice(0,num)), function() {
obj[ this ] = type;
});
return obj;
}
})( jQuery ); })( jQuery );

@ -1 +1 @@
Subproject commit 69ecd019852c1421cbd81fe6ceb4e22a81022ea7 Subproject commit 4bcc09702d6dadfd0b90c7de3c8b206e97ff97f4

View File

@ -58,10 +58,10 @@
<div id="nothiddendiv" style="height:1px;background:white;" class="nothiddendiv"> <div id="nothiddendiv" style="height:1px;background:white;" class="nothiddendiv">
<div id="nothiddendivchild"></div> <div id="nothiddendivchild"></div>
</div> </div>
<!-- this iframe is outside the #main so it won't reload constantly wasting time, but it means the tests must be "safe" and clean up after themselves --> <!-- this iframe is outside the #qunit-fixture so it won't reload constantly wasting time, but it means the tests must be "safe" and clean up after themselves -->
<iframe id="loadediframe" name="loadediframe" style="display:none;" src="data/iframe.html"></iframe> <iframe id="loadediframe" name="loadediframe" style="display:none;" src="data/iframe.html"></iframe>
<dl id="dl" style="position:absolute;top:-32767px;left:-32767px;"> <dl id="dl" style="position:absolute;top:-32767px;left:-32767px;width:1px">
<div id="main"> <div id="qunit-fixture">
<p id="firstp">See <a id="simon1" href="http://simon.incutio.com/archive/2003/03/25/#getElementsBySelector" rel="bookmark">this blog entry</a> for more information.</p> <p id="firstp">See <a id="simon1" href="http://simon.incutio.com/archive/2003/03/25/#getElementsBySelector" rel="bookmark">this blog entry</a> for more information.</p>
<p id="ap"> <p id="ap">
Here are some links in a normal paragraph: <a id="google" href="http://www.google.com/" title="Google!">Google</a>, Here are some links in a normal paragraph: <a id="google" href="http://www.google.com/" title="Google!">Google</a>,

@ -1 +1 @@
Subproject commit d404faf8f587fcbe6b8907943022e6318dd51e0c Subproject commit 69925bca552c1e227a93102dcfba9c8596a2e8ce

View File

@ -1782,7 +1782,7 @@ test("jQuery.ajaxSetup({timeout: Number}) - with global timeout", function() {
passed++; passed++;
if ( passed == 2 ) { if ( passed == 2 ) {
ok( true, "Check local and global callbacks after timeout" ); ok( true, "Check local and global callbacks after timeout" );
jQuery("#main").unbind("ajaxError"); jQuery("#qunit-fixture").unbind("ajaxError");
start(); start();
} }
}; };
@ -1792,7 +1792,7 @@ test("jQuery.ajaxSetup({timeout: Number}) - with global timeout", function() {
start(); start();
}; };
jQuery("#main").ajaxError(pass); jQuery("#qunit-fixture").ajaxError(pass);
jQuery.ajax({ jQuery.ajax({
type: "GET", type: "GET",

View File

@ -108,7 +108,7 @@ test("attr(String)", function() {
equals( jQuery("#area1").attr("maxLength"), "30", "Check for maxLength attribute" ); equals( jQuery("#area1").attr("maxLength"), "30", "Check for maxLength attribute" );
// using innerHTML in IE causes href attribute to be serialized to the full path // using innerHTML in IE causes href attribute to be serialized to the full path
jQuery("<a/>").attr({ "id": "tAnchor5", "href": "#5" }).appendTo("#main"); jQuery("<a/>").attr({ "id": "tAnchor5", "href": "#5" }).appendTo("#qunit-fixture");
equals( jQuery("#tAnchor5").attr("href"), "#5", "Check for non-absolute href (an anchor)" ); equals( jQuery("#tAnchor5").attr("href"), "#5", "Check for non-absolute href (an anchor)" );
// list attribute is readonly by default in browsers that support it // list attribute is readonly by default in browsers that support it
@ -599,7 +599,7 @@ test("val(Function) with incoming value", function() {
test("val(select) after form.reset() (Bug #2551)", function() { test("val(select) after form.reset() (Bug #2551)", function() {
expect(3); expect(3);
jQuery("<form id='kk' name='kk'><select id='kkk'><option value='cf'>cf</option><option value='gf'>gf</option></select></form>").appendTo("#main"); jQuery("<form id='kk' name='kk'><select id='kkk'><option value='cf'>cf</option><option value='gf'>gf</option></select></form>").appendTo("#qunit-fixture");
jQuery("#kkk").val( "gf" ); jQuery("#kkk").val( "gf" );

View File

@ -29,7 +29,7 @@ test("jQuery()", function() {
equals( jQuery(window).length, 1, "Correct number of elements generated for jQuery(window)" ); equals( jQuery(window).length, 1, "Correct number of elements generated for jQuery(window)" );
var main = jQuery("#main"); var main = jQuery("#qunit-fixture");
same( jQuery("div p", main).get(), q("sndp", "en", "sap"), "Basic selector with jQuery object as context" ); same( jQuery("div p", main).get(), q("sndp", "en", "sap"), "Basic selector with jQuery object as context" );
/* /*
@ -115,54 +115,54 @@ test("selector state", function() {
equals( test.selector, "", "Body Selector" ); equals( test.selector, "", "Body Selector" );
equals( test.context, document.body, "Body Context" ); equals( test.context, document.body, "Body Context" );
test = jQuery("#main"); test = jQuery("#qunit-fixture");
equals( test.selector, "#main", "#main Selector" ); equals( test.selector, "#qunit-fixture", "#qunit-fixture Selector" );
equals( test.context, document, "#main Context" ); equals( test.context, document, "#qunit-fixture Context" );
test = jQuery("#notfoundnono"); test = jQuery("#notfoundnono");
equals( test.selector, "#notfoundnono", "#notfoundnono Selector" ); equals( test.selector, "#notfoundnono", "#notfoundnono Selector" );
equals( test.context, document, "#notfoundnono Context" ); equals( test.context, document, "#notfoundnono Context" );
test = jQuery("#main", document); test = jQuery("#qunit-fixture", document);
equals( test.selector, "#main", "#main Selector" ); equals( test.selector, "#qunit-fixture", "#qunit-fixture Selector" );
equals( test.context, document, "#main Context" ); equals( test.context, document, "#qunit-fixture Context" );
test = jQuery("#main", document.body); test = jQuery("#qunit-fixture", document.body);
equals( test.selector, "#main", "#main Selector" ); equals( test.selector, "#qunit-fixture", "#qunit-fixture Selector" );
equals( test.context, document.body, "#main Context" ); equals( test.context, document.body, "#qunit-fixture Context" );
// Test cloning // Test cloning
test = jQuery(test); test = jQuery(test);
equals( test.selector, "#main", "#main Selector" ); equals( test.selector, "#qunit-fixture", "#qunit-fixture Selector" );
equals( test.context, document.body, "#main Context" ); equals( test.context, document.body, "#qunit-fixture Context" );
test = jQuery(document.body).find("#main"); test = jQuery(document.body).find("#qunit-fixture");
equals( test.selector, "#main", "#main find Selector" ); equals( test.selector, "#qunit-fixture", "#qunit-fixture find Selector" );
equals( test.context, document.body, "#main find Context" ); equals( test.context, document.body, "#qunit-fixture find Context" );
test = jQuery("#main").filter("div"); test = jQuery("#qunit-fixture").filter("div");
equals( test.selector, "#main.filter(div)", "#main filter Selector" ); equals( test.selector, "#qunit-fixture.filter(div)", "#qunit-fixture filter Selector" );
equals( test.context, document, "#main filter Context" ); equals( test.context, document, "#qunit-fixture filter Context" );
test = jQuery("#main").not("div"); test = jQuery("#qunit-fixture").not("div");
equals( test.selector, "#main.not(div)", "#main not Selector" ); equals( test.selector, "#qunit-fixture.not(div)", "#qunit-fixture not Selector" );
equals( test.context, document, "#main not Context" ); equals( test.context, document, "#qunit-fixture not Context" );
test = jQuery("#main").filter("div").not("div"); test = jQuery("#qunit-fixture").filter("div").not("div");
equals( test.selector, "#main.filter(div).not(div)", "#main filter, not Selector" ); equals( test.selector, "#qunit-fixture.filter(div).not(div)", "#qunit-fixture filter, not Selector" );
equals( test.context, document, "#main filter, not Context" ); equals( test.context, document, "#qunit-fixture filter, not Context" );
test = jQuery("#main").filter("div").not("div").end(); test = jQuery("#qunit-fixture").filter("div").not("div").end();
equals( test.selector, "#main.filter(div)", "#main filter, not, end Selector" ); equals( test.selector, "#qunit-fixture.filter(div)", "#qunit-fixture filter, not, end Selector" );
equals( test.context, document, "#main filter, not, end Context" ); equals( test.context, document, "#qunit-fixture filter, not, end Context" );
test = jQuery("#main").parent("body"); test = jQuery("#qunit-fixture").parent("body");
equals( test.selector, "#main.parent(body)", "#main parent Selector" ); equals( test.selector, "#qunit-fixture.parent(body)", "#qunit-fixture parent Selector" );
equals( test.context, document, "#main parent Context" ); equals( test.context, document, "#qunit-fixture parent Context" );
test = jQuery("#main").eq(0); test = jQuery("#qunit-fixture").eq(0);
equals( test.selector, "#main.slice(0,1)", "#main eq Selector" ); equals( test.selector, "#qunit-fixture.slice(0,1)", "#qunit-fixture eq Selector" );
equals( test.context, document, "#main eq Context" ); equals( test.context, document, "#qunit-fixture eq Context" );
var d = "<div />"; var d = "<div />";
equals( equals(
@ -228,7 +228,7 @@ test("noConflict", function() {
equals( jQuery.noConflict(true), $$, "noConflict returned the jQuery object" ); equals( jQuery.noConflict(true), $$, "noConflict returned the jQuery object" );
equals( jQuery, originaljQuery, "Make sure jQuery was reverted." ); equals( jQuery, originaljQuery, "Make sure jQuery was reverted." );
equals( $, original$, "Make sure $ was reverted." ); equals( $, original$, "Make sure $ was reverted." );
ok( $$("#main").html("test"), "Make sure that jQuery still works." ); ok( $$("#qunit-fixture").html("test"), "Make sure that jQuery still works." );
jQuery = $$; jQuery = $$;
}); });
@ -571,29 +571,29 @@ test("end()", function() {
test("length", function() { test("length", function() {
expect(1); expect(1);
equals( jQuery("#main p").length, 6, "Get Number of Elements Found" ); equals( jQuery("#qunit-fixture p").length, 6, "Get Number of Elements Found" );
}); });
test("size()", function() { test("size()", function() {
expect(1); expect(1);
equals( jQuery("#main p").size(), 6, "Get Number of Elements Found" ); equals( jQuery("#qunit-fixture p").size(), 6, "Get Number of Elements Found" );
}); });
test("get()", function() { test("get()", function() {
expect(1); expect(1);
same( jQuery("#main p").get(), q("firstp","ap","sndp","en","sap","first"), "Get All Elements" ); same( jQuery("#qunit-fixture p").get(), q("firstp","ap","sndp","en","sap","first"), "Get All Elements" );
}); });
test("toArray()", function() { test("toArray()", function() {
expect(1); expect(1);
same( jQuery("#main p").toArray(), same( jQuery("#qunit-fixture p").toArray(),
q("firstp","ap","sndp","en","sap","first"), q("firstp","ap","sndp","en","sap","first"),
"Convert jQuery object to an Array" ) "Convert jQuery object to an Array" )
}) })
test("get(Number)", function() { test("get(Number)", function() {
expect(2); expect(2);
equals( jQuery("#main p").get(0), document.getElementById("firstp"), "Get A Single Element" ); equals( jQuery("#qunit-fixture p").get(0), document.getElementById("firstp"), "Get A Single Element" );
strictEqual( jQuery("#firstp").get(1), undefined, "Try get with index larger elements count" ); strictEqual( jQuery("#firstp").get(1), undefined, "Try get with index larger elements count" );
}); });

View File

@ -3,7 +3,7 @@ module("css", { teardown: moduleTeardown });
test("css(String|Hash)", function() { test("css(String|Hash)", function() {
expect( 42 ); expect( 42 );
equals( jQuery("#main").css("display"), "block", "Check for css property \"display\""); equals( jQuery("#qunit-fixture").css("display"), "block", "Check for css property \"display\"");
ok( jQuery("#nothiddendiv").is(":visible"), "Modifying CSS display: Assert element is visible"); ok( jQuery("#nothiddendiv").is(":visible"), "Modifying CSS display: Assert element is visible");
jQuery("#nothiddendiv").css({display: "none"}); jQuery("#nothiddendiv").css({display: "none"});

View File

@ -316,7 +316,7 @@ test("data-* attributes", function() {
div.remove(); div.remove();
child.appendTo("#main"); child.appendTo("#qunit-fixture");
equals( child.data("myobj"), "old data", "Value accessed from data-* attribute"); equals( child.data("myobj"), "old data", "Value accessed from data-* attribute");
child.data("myobj", "replaced"); child.data("myobj", "replaced");
@ -406,7 +406,7 @@ test("data-* attributes", function() {
} }
var metadata = "<ol><li class='test test2' data-foo='bar' data-bar='baz' data-arr='[1,2]'>Some stuff</li><li class='test test2' data-test='bar' data-bar='baz'>Some stuff</li><li class='test test2' data-zoooo='bar' data-bar='{\"test\":\"baz\"}'>Some stuff</li><li class='test test2' data-number=true data-stuff='[2,8]'>Some stuff</li></ol>", var metadata = "<ol><li class='test test2' data-foo='bar' data-bar='baz' data-arr='[1,2]'>Some stuff</li><li class='test test2' data-test='bar' data-bar='baz'>Some stuff</li><li class='test test2' data-zoooo='bar' data-bar='{\"test\":\"baz\"}'>Some stuff</li><li class='test test2' data-number=true data-stuff='[2,8]'>Some stuff</li></ol>",
elem = jQuery(metadata).appendTo("#main"); elem = jQuery(metadata).appendTo("#qunit-fixture");
elem.find("li").each(testData); elem.find("li").each(testData);
elem.remove(); elem.remove();

20
test/unit/effects.js vendored
View File

@ -2,7 +2,7 @@ module("effects", { teardown: moduleTeardown });
test("sanity check", function() { test("sanity check", function() {
expect(1); expect(1);
ok( jQuery("#dl:visible, #main:visible, #foo:visible").length === 3, "QUnit state is correct for testing effects" ); ok( jQuery("#dl:visible, #qunit-fixture:visible, #foo:visible").length === 3, "QUnit state is correct for testing effects" );
}); });
test("show()", function() { test("show()", function() {
@ -14,7 +14,7 @@ test("show()", function() {
equals( hiddendiv.css("display"), "block", "Make sure a pre-hidden div is visible." ); equals( hiddendiv.css("display"), "block", "Make sure a pre-hidden div is visible." );
var div = jQuery("<div>").hide().appendTo("#main").show(); var div = jQuery("<div>").hide().appendTo("#qunit-fixture").show();
equal( div.css("display"), "block", "Make sure pre-hidden divs show" ); equal( div.css("display"), "block", "Make sure pre-hidden divs show" );
@ -32,7 +32,7 @@ test("show()", function() {
hiddendiv.css("display",""); hiddendiv.css("display","");
var pass = true, div = jQuery("#main div"); var pass = true, div = jQuery("#qunit-fixture div");
div.show().each(function(){ div.show().each(function(){
if ( this.style.display == "none" ) pass = false; if ( this.style.display == "none" ) pass = false;
}); });
@ -62,7 +62,7 @@ test("show()", function() {
}); });
// #show-tests * is set display: none in CSS // #show-tests * is set display: none in CSS
jQuery("#main").append("<div id='show-tests'><div><p><a href='#'></a></p><code></code><pre></pre><span></span></div><table><thead><tr><th></th></tr></thead><tbody><tr><td></td></tr></tbody></table><ul><li></li></ul></div><table id='test-table'></table>"); jQuery("#qunit-fixture").append("<div id='show-tests'><div><p><a href='#'></a></p><code></code><pre></pre><span></span></div><table><thead><tr><th></th></tr></thead><tbody><tr><td></td></tr></tbody></table><ul><li></li></ul></div><table id='test-table'></table>");
var old = jQuery("#test-table").show().css("display") !== "table"; var old = jQuery("#test-table").show().css("display") !== "table";
jQuery("#test-table").remove(); jQuery("#test-table").remove();
@ -100,7 +100,7 @@ test("show(Number) - other displays", function() {
stop(); stop();
// #show-tests * is set display: none in CSS // #show-tests * is set display: none in CSS
jQuery("#main").append("<div id='show-tests'><div><p><a href='#'></a></p><code></code><pre></pre><span></span></div><table><thead><tr><th></th></tr></thead><tbody><tr><td></td></tr></tbody></table><ul><li></li></ul></div><table id='test-table'></table>"); jQuery("#qunit-fixture").append("<div id='show-tests'><div><p><a href='#'></a></p><code></code><pre></pre><span></span></div><table><thead><tr><th></th></tr></thead><tbody><tr><td></td></tr></tbody></table><ul><li></li></ul></div><table id='test-table'></table>");
var old = jQuery("#test-table").show().css("display") !== "table", var old = jQuery("#test-table").show().css("display") !== "table",
num = 0; num = 0;
@ -142,7 +142,7 @@ test("Persist correct display value", function() {
stop(); stop();
// #show-tests * is set display: none in CSS // #show-tests * is set display: none in CSS
jQuery("#main").append("<div id='show-tests'><span style='position:absolute;'>foo</span></div>"); jQuery("#qunit-fixture").append("<div id='show-tests'><span style='position:absolute;'>foo</span></div>");
var $span = jQuery("#show-tests span"), var $span = jQuery("#show-tests span"),
displayNone = $span.css("display"), displayNone = $span.css("display"),
@ -585,7 +585,7 @@ jQuery.checkOverflowDisplay = function(){
} }
test( "jQuery.fx.prototype.cur()", 6, function() { test( "jQuery.fx.prototype.cur()", 6, function() {
var div = jQuery( "<div></div>" ).appendTo( "#main" ).css({ var div = jQuery( "<div></div>" ).appendTo( "#qunit-fixture" ).css({
color: "#ABC", color: "#ABC",
border: "5px solid black", border: "5px solid black",
left: "auto", left: "auto",
@ -958,7 +958,7 @@ test("hide hidden elements (bug #7141)", function() {
expect(3); expect(3);
QUnit.reset(); QUnit.reset();
var div = jQuery("<div style='display:none'></div>").appendTo("#main"); var div = jQuery("<div style='display:none'></div>").appendTo("#qunit-fixture");
equals( div.css("display"), "none", "Element is hidden by default" ); equals( div.css("display"), "none", "Element is hidden by default" );
div.hide(); div.hide();
ok( !jQuery._data(div, "olddisplay"), "olddisplay is undefined after hiding an already-hidden element" ); ok( !jQuery._data(div, "olddisplay"), "olddisplay is undefined after hiding an already-hidden element" );
@ -973,7 +973,7 @@ test("hide hidden elements, with animation (bug #7141)", function() {
QUnit.reset(); QUnit.reset();
stop(); stop();
var div = jQuery("<div style='display:none'></div>").appendTo("#main"); var div = jQuery("<div style='display:none'></div>").appendTo("#qunit-fixture");
equals( div.css("display"), "none", "Element is hidden by default" ); equals( div.css("display"), "none", "Element is hidden by default" );
div.hide(1, function () { div.hide(1, function () {
ok( !jQuery._data(div, "olddisplay"), "olddisplay is undefined after hiding an already-hidden element" ); ok( !jQuery._data(div, "olddisplay"), "olddisplay is undefined after hiding an already-hidden element" );
@ -986,7 +986,7 @@ test("hide hidden elements, with animation (bug #7141)", function() {
test("animate unit-less properties (#4966)", 2, function() { test("animate unit-less properties (#4966)", 2, function() {
stop(); stop();
var div = jQuery( "<div style='z-index: 0; position: absolute;'></div>" ).appendTo( "#main" ); var div = jQuery( "<div style='z-index: 0; position: absolute;'></div>" ).appendTo( "#qunit-fixture" );
equal( div.css( "z-index" ), "0", "z-index is 0" ); equal( div.css( "z-index" ), "0", "z-index is 0" );
div.animate({ zIndex: 2 }, function() { div.animate({ zIndex: 2 }, function() {
equal( div.css( "z-index" ), "2", "z-index is 2" ); equal( div.css( "z-index" ), "2", "z-index is 2" );

View File

@ -169,7 +169,7 @@ test("bind(), namespace with special add", function() {
}); });
// Should trigger 2 // Should trigger 2
div.appendTo("#main").remove(); div.appendTo("#qunit-fixture").remove();
delete jQuery.event.special.test; delete jQuery.event.special.test;
}); });
@ -307,7 +307,7 @@ test("live/delegate immediate propagation", function() {
test("bind/delegate bubbling, isDefaultPrevented", function() { test("bind/delegate bubbling, isDefaultPrevented", function() {
expect(2); expect(2);
var $anchor2 = jQuery( "#anchor2" ), var $anchor2 = jQuery( "#anchor2" ),
$main = jQuery( "#main" ), $main = jQuery( "#qunit-fixture" ),
fakeClick = function($jq) { fakeClick = function($jq) {
// Use a native click so we don't get jQuery simulated bubbling // Use a native click so we don't get jQuery simulated bubbling
if ( document.createEvent ) { if ( document.createEvent ) {
@ -415,7 +415,7 @@ test("bind(), namespaced events, cloned events", 18, function() {
}).trigger("tester"); }).trigger("tester");
// Make sure events stick with appendTo'd elements (which are cloned) #2027 // Make sure events stick with appendTo'd elements (which are cloned) #2027
jQuery("<a href='#fail' class='test'>test</a>").click(function(){ return false; }).appendTo("#main"); jQuery("<a href='#fail' class='test'>test</a>").click(function(){ return false; }).appendTo("#qunit-fixture");
ok( jQuery("a.test:first").triggerHandler("click") === false, "Handler is bound to appendTo'd elements" ); ok( jQuery("a.test:first").triggerHandler("click") === false, "Handler is bound to appendTo'd elements" );
}); });
@ -538,7 +538,7 @@ test("bind(name, false), unbind(name, false)", function() {
expect(3); expect(3);
var main = 0; var main = 0;
jQuery("#main").bind("click", function(e){ main++; }); jQuery("#qunit-fixture").bind("click", function(e){ main++; });
jQuery("#ap").trigger("click"); jQuery("#ap").trigger("click");
equals( main, 1, "Verify that the trigger happened correctly." ); equals( main, 1, "Verify that the trigger happened correctly." );
@ -553,14 +553,14 @@ test("bind(name, false), unbind(name, false)", function() {
equals( main, 1, "Verify that the trigger happened correctly." ); equals( main, 1, "Verify that the trigger happened correctly." );
// manually clean up events from elements outside the fixture // manually clean up events from elements outside the fixture
jQuery("#main").unbind("click"); jQuery("#qunit-fixture").unbind("click");
}); });
test("live(name, false), die(name, false)", function() { test("live(name, false), die(name, false)", function() {
expect(3); expect(3);
var main = 0; var main = 0;
jQuery("#main").live("click", function(e){ main++; }); jQuery("#qunit-fixture").live("click", function(e){ main++; });
jQuery("#ap").trigger("click"); jQuery("#ap").trigger("click");
equals( main, 1, "Verify that the trigger happened correctly." ); equals( main, 1, "Verify that the trigger happened correctly." );
@ -573,7 +573,7 @@ test("live(name, false), die(name, false)", function() {
jQuery("#ap").die("click", false); jQuery("#ap").die("click", false);
jQuery("#ap").trigger("click"); jQuery("#ap").trigger("click");
equals( main, 1, "Verify that the trigger happened correctly." ); equals( main, 1, "Verify that the trigger happened correctly." );
jQuery("#main").die("click"); jQuery("#qunit-fixture").die("click");
}); });
test("delegate(selector, name, false), undelegate(selector, name, false)", function() { test("delegate(selector, name, false), undelegate(selector, name, false)", function() {
@ -581,7 +581,7 @@ test("delegate(selector, name, false), undelegate(selector, name, false)", funct
var main = 0; var main = 0;
jQuery("#main").delegate("#ap", "click", function(e){ main++; }); jQuery("#qunit-fixture").delegate("#ap", "click", function(e){ main++; });
jQuery("#ap").trigger("click"); jQuery("#ap").trigger("click");
equals( main, 1, "Verify that the trigger happened correctly." ); equals( main, 1, "Verify that the trigger happened correctly." );
@ -594,7 +594,7 @@ test("delegate(selector, name, false), undelegate(selector, name, false)", funct
jQuery("#ap").undelegate("#groups", "click", false); jQuery("#ap").undelegate("#groups", "click", false);
jQuery("#groups").trigger("click"); jQuery("#groups").trigger("click");
equals( main, 1, "Verify that the trigger happened correctly." ); equals( main, 1, "Verify that the trigger happened correctly." );
jQuery("#main").undelegate("#ap", "click"); jQuery("#qunit-fixture").undelegate("#ap", "click");
}); });
test("bind()/trigger()/unbind() on plain object", function() { test("bind()/trigger()/unbind() on plain object", function() {
@ -798,7 +798,7 @@ test("trigger() bubbling", function() {
jQuery(document).bind("click", function(e){ if ( e.target !== document) { doc++; } }); jQuery(document).bind("click", function(e){ if ( e.target !== document) { doc++; } });
jQuery("html").bind("click", function(e){ html++; }); jQuery("html").bind("click", function(e){ html++; });
jQuery("body").bind("click", function(e){ body++; }); jQuery("body").bind("click", function(e){ body++; });
jQuery("#main").bind("click", function(e){ main++; }); jQuery("#qunit-fixture").bind("click", function(e){ main++; });
jQuery("#ap").bind("click", function(){ ap++; return false; }); jQuery("#ap").bind("click", function(){ ap++; return false; });
jQuery("html").trigger("click"); jQuery("html").trigger("click");
@ -812,7 +812,7 @@ test("trigger() bubbling", function() {
equals( html, 2, "Body bubble" ); equals( html, 2, "Body bubble" );
equals( body, 1, "Body bubble" ); equals( body, 1, "Body bubble" );
jQuery("#main").trigger("click"); jQuery("#qunit-fixture").trigger("click");
equals( win, 3, "Main bubble" ); equals( win, 3, "Main bubble" );
equals( doc, 3, "Main bubble" ); equals( doc, 3, "Main bubble" );
equals( html, 3, "Main bubble" ); equals( html, 3, "Main bubble" );
@ -828,7 +828,7 @@ test("trigger() bubbling", function() {
// manually clean up events from elements outside the fixture // manually clean up events from elements outside the fixture
jQuery(document).unbind("click"); jQuery(document).unbind("click");
jQuery("html, body, #main").unbind("click"); jQuery("html, body, #qunit-fixture").unbind("click");
}); });
test("trigger(type, [data], [fn])", function() { test("trigger(type, [data], [fn])", function() {
@ -889,7 +889,7 @@ test("trigger(type, [data], [fn])", function() {
pass = true; pass = true;
try { try {
jQuery("#main table:first").bind("test:test", function(){}).trigger("test:test"); jQuery("#qunit-fixture table:first").bind("test:test", function(){}).trigger("test:test");
} catch (e) { } catch (e) {
pass = false; pass = false;
} }
@ -1206,11 +1206,11 @@ test(".live()/.die()", function() {
jQuery("div").die("submit"); jQuery("div").die("submit");
// Test binding with a different context // Test binding with a different context
var clicked = 0, container = jQuery("#main")[0]; var clicked = 0, container = jQuery("#qunit-fixture")[0];
jQuery("#foo", container).live("click", function(e){ clicked++; }); jQuery("#foo", container).live("click", function(e){ clicked++; });
jQuery("div").trigger("click"); jQuery("div").trigger("click");
jQuery("#foo").trigger("click"); jQuery("#foo").trigger("click");
jQuery("#main").trigger("click"); jQuery("#qunit-fixture").trigger("click");
jQuery("body").trigger("click"); jQuery("body").trigger("click");
equals( clicked, 2, "live with a context" ); equals( clicked, 2, "live with a context" );
@ -1733,11 +1733,11 @@ test(".delegate()/.undelegate()", function() {
jQuery("#body").undelegate("div", "submit"); jQuery("#body").undelegate("div", "submit");
// Test binding with a different context // Test binding with a different context
var clicked = 0, container = jQuery("#main")[0]; var clicked = 0, container = jQuery("#qunit-fixture")[0];
jQuery("#main").delegate("#foo", "click", function(e){ clicked++; }); jQuery("#qunit-fixture").delegate("#foo", "click", function(e){ clicked++; });
jQuery("div").trigger("click"); jQuery("div").trigger("click");
jQuery("#foo").trigger("click"); jQuery("#foo").trigger("click");
jQuery("#main").trigger("click"); jQuery("#qunit-fixture").trigger("click");
jQuery("body").trigger("click"); jQuery("body").trigger("click");
equals( clicked, 2, "delegate with a context" ); equals( clicked, 2, "delegate with a context" );
@ -1745,7 +1745,7 @@ test(".delegate()/.undelegate()", function() {
ok( jQuery._data(container, "events").live, "delegate with a context" ); ok( jQuery._data(container, "events").live, "delegate with a context" );
// Test unbinding with a different context // Test unbinding with a different context
jQuery("#main").undelegate("#foo", "click"); jQuery("#qunit-fixture").undelegate("#foo", "click");
jQuery("#foo").trigger("click"); jQuery("#foo").trigger("click");
equals( clicked, 2, "undelegate with a context"); equals( clicked, 2, "undelegate with a context");

View File

@ -483,19 +483,19 @@ test("appendTo(String|Element|Array&lt;Element&gt;|jQuery)", function() {
var div = jQuery("<div/>").click(function(){ var div = jQuery("<div/>").click(function(){
ok(true, "Running a cloned click."); ok(true, "Running a cloned click.");
}); });
div.appendTo("#main, #moretests"); div.appendTo("#qunit-fixture, #moretests");
jQuery("#main div:last").click(); jQuery("#qunit-fixture div:last").click();
jQuery("#moretests div:last").click(); jQuery("#moretests div:last").click();
QUnit.reset(); QUnit.reset();
var div = jQuery("<div/>").appendTo("#main, #moretests"); var div = jQuery("<div/>").appendTo("#qunit-fixture, #moretests");
equals( div.length, 2, "appendTo returns the inserted elements" ); equals( div.length, 2, "appendTo returns the inserted elements" );
div.addClass("test"); div.addClass("test");
ok( jQuery("#main div:last").hasClass("test"), "appendTo element was modified after the insertion" ); ok( jQuery("#qunit-fixture div:last").hasClass("test"), "appendTo element was modified after the insertion" );
ok( jQuery("#moretests div:last").hasClass("test"), "appendTo element was modified after the insertion" ); ok( jQuery("#moretests div:last").hasClass("test"), "appendTo element was modified after the insertion" );
QUnit.reset(); QUnit.reset();
@ -507,10 +507,10 @@ test("appendTo(String|Element|Array&lt;Element&gt;|jQuery)", function() {
div = jQuery("#moretests div"); div = jQuery("#moretests div");
var num = jQuery("#main div").length; var num = jQuery("#qunit-fixture div").length;
div.remove().appendTo("#main"); div.remove().appendTo("#qunit-fixture");
equals( jQuery("#main div").length, num, "Make sure all the removed divs were inserted." ); equals( jQuery("#qunit-fixture div").length, num, "Make sure all the removed divs were inserted." );
QUnit.reset(); QUnit.reset();
}); });
@ -750,7 +750,7 @@ var testReplaceWith = function(val) {
ok( !jQuery("#yahoo")[0], "Verify that original element is gone, after element" ); ok( !jQuery("#yahoo")[0], "Verify that original element is gone, after element" );
QUnit.reset(); QUnit.reset();
jQuery("#main").append("<div id='bar'><div id='baz'</div></div>"); jQuery("#qunit-fixture").append("<div id='bar'><div id='baz'</div></div>");
jQuery("#baz").replaceWith("Baz"); jQuery("#baz").replaceWith("Baz");
equals( jQuery("#bar").text(),"Baz", "Replace element with text" ); equals( jQuery("#bar").text(),"Baz", "Replace element with text" );
ok( !jQuery("#baz")[0], "Verify that original element is gone, after element" ); ok( !jQuery("#baz")[0], "Verify that original element is gone, after element" );
@ -813,14 +813,14 @@ var testReplaceWith = function(val) {
QUnit.reset(); QUnit.reset();
jQuery("#main").append("<div id='replaceWith'></div>"); jQuery("#qunit-fixture").append("<div id='replaceWith'></div>");
equals( jQuery("#main").find("div[id=replaceWith]").length, 1, "Make sure only one div exists." ); equals( jQuery("#qunit-fixture").find("div[id=replaceWith]").length, 1, "Make sure only one div exists." );
jQuery("#replaceWith").replaceWith( val("<div id='replaceWith'></div>") ); jQuery("#replaceWith").replaceWith( val("<div id='replaceWith'></div>") );
equals( jQuery("#main").find("div[id=replaceWith]").length, 1, "Make sure only one div exists." ); equals( jQuery("#qunit-fixture").find("div[id=replaceWith]").length, 1, "Make sure only one div exists." );
jQuery("#replaceWith").replaceWith( val("<div id='replaceWith'></div>") ); jQuery("#replaceWith").replaceWith( val("<div id='replaceWith'></div>") );
equals( jQuery("#main").find("div[id=replaceWith]").length, 1, "Make sure only one div exists." ); equals( jQuery("#qunit-fixture").find("div[id=replaceWith]").length, 1, "Make sure only one div exists." );
} }
test("replaceWith(String|Element|Array&lt;Element&gt;|jQuery)", function() { test("replaceWith(String|Element|Array&lt;Element&gt;|jQuery)", function() {
@ -881,7 +881,7 @@ test("jQuery.clone() (#8017)", function() {
ok( jQuery.clone && jQuery.isFunction( jQuery.clone ) , "jQuery.clone() utility exists and is a function."); ok( jQuery.clone && jQuery.isFunction( jQuery.clone ) , "jQuery.clone() utility exists and is a function.");
var main = jQuery("#main")[0], var main = jQuery("#qunit-fixture")[0],
clone = jQuery.clone( main ); clone = jQuery.clone( main );
equals( main.childNodes.length, clone.childNodes.length, "Simple child length to ensure a large dom tree copies correctly" ); equals( main.childNodes.length, clone.childNodes.length, "Simple child length to ensure a large dom tree copies correctly" );
@ -890,7 +890,7 @@ test("jQuery.clone() (#8017)", function() {
test("clone() (#8070)", function () { test("clone() (#8070)", function () {
expect(2); expect(2);
jQuery("<select class='test8070'></select><select class='test8070'></select>").appendTo("#main"); jQuery("<select class='test8070'></select><select class='test8070'></select>").appendTo("#qunit-fixture");
var selects = jQuery(".test8070"); var selects = jQuery(".test8070");
selects.append("<OPTION>1</OPTION><OPTION>2</OPTION>"); selects.append("<OPTION>1</OPTION><OPTION>2</OPTION>");
@ -1062,7 +1062,7 @@ var testHtml = function(valueObj) {
jQuery.scriptorder = 0; jQuery.scriptorder = 0;
var div = jQuery("#main > div"); var div = jQuery("#qunit-fixture > div");
div.html(valueObj("<b>test</b>")); div.html(valueObj("<b>test</b>"));
var pass = true; var pass = true;
for ( var i = 0; i < div.size(); i++ ) { for ( var i = 0; i < div.size(); i++ ) {
@ -1079,10 +1079,10 @@ var testHtml = function(valueObj) {
ok( /^\xA0$|^&nbsp;$/.test( space ), "Make sure entities are passed through correctly." ); ok( /^\xA0$|^&nbsp;$/.test( space ), "Make sure entities are passed through correctly." );
equals( jQuery("<div/>").html(valueObj("&amp;"))[0].innerHTML, "&amp;", "Make sure entities are passed through correctly." ); equals( jQuery("<div/>").html(valueObj("&amp;"))[0].innerHTML, "&amp;", "Make sure entities are passed through correctly." );
jQuery("#main").html(valueObj("<style>.foobar{color:green;}</style>")); jQuery("#qunit-fixture").html(valueObj("<style>.foobar{color:green;}</style>"));
equals( jQuery("#main").children().length, 1, "Make sure there is a child element." ); equals( jQuery("#qunit-fixture").children().length, 1, "Make sure there is a child element." );
equals( jQuery("#main").children()[0].nodeName.toUpperCase(), "STYLE", "And that a style element was inserted." ); equals( jQuery("#qunit-fixture").children()[0].nodeName.toUpperCase(), "STYLE", "And that a style element was inserted." );
QUnit.reset(); QUnit.reset();
// using contents will get comments regular, text, and comment nodes // using contents will get comments regular, text, and comment nodes
@ -1093,9 +1093,9 @@ var testHtml = function(valueObj) {
j.find("b").removeData(); j.find("b").removeData();
equals( j.html().replace(/ xmlns="[^"]+"/g, "").toLowerCase(), "<b>bold</b>", "Check node,textnode,comment with html()" ); equals( j.html().replace(/ xmlns="[^"]+"/g, "").toLowerCase(), "<b>bold</b>", "Check node,textnode,comment with html()" );
jQuery("#main").html(valueObj("<select/>")); jQuery("#qunit-fixture").html(valueObj("<select/>"));
jQuery("#main select").html(valueObj("<option>O1</option><option selected='selected'>O2</option><option>O3</option>")); jQuery("#qunit-fixture select").html(valueObj("<option>O1</option><option selected='selected'>O2</option><option>O3</option>"));
equals( jQuery("#main select").val(), "O2", "Selected option correct" ); equals( jQuery("#qunit-fixture select").val(), "O2", "Selected option correct" );
var $div = jQuery("<div />"); var $div = jQuery("<div />");
equals( $div.html(valueObj( 5 )).html(), "5", "Setting a number as html" ); equals( $div.html(valueObj( 5 )).html(), "5", "Setting a number as html" );
@ -1113,23 +1113,23 @@ var testHtml = function(valueObj) {
QUnit.reset(); QUnit.reset();
jQuery("#main").html(valueObj("<script type='something/else'>ok( false, 'Non-script evaluated.' );</script><script type='text/javascript'>ok( true, 'text/javascript is evaluated.' );</script><script>ok( true, 'No type is evaluated.' );</script><div><script type='text/javascript'>ok( true, 'Inner text/javascript is evaluated.' );</script><script>ok( true, 'Inner No type is evaluated.' );</script><script type='something/else'>ok( false, 'Non-script evaluated.' );</script></div>")); jQuery("#qunit-fixture").html(valueObj("<script type='something/else'>ok( false, 'Non-script evaluated.' );</script><script type='text/javascript'>ok( true, 'text/javascript is evaluated.' );</script><script>ok( true, 'No type is evaluated.' );</script><div><script type='text/javascript'>ok( true, 'Inner text/javascript is evaluated.' );</script><script>ok( true, 'Inner No type is evaluated.' );</script><script type='something/else'>ok( false, 'Non-script evaluated.' );</script></div>"));
var child = jQuery("#main").find("script"); var child = jQuery("#qunit-fixture").find("script");
equals( child.length, 2, "Make sure that two non-JavaScript script tags are left." ); equals( child.length, 2, "Make sure that two non-JavaScript script tags are left." );
equals( child[0].type, "something/else", "Verify type of script tag." ); equals( child[0].type, "something/else", "Verify type of script tag." );
equals( child[1].type, "something/else", "Verify type of script tag." ); equals( child[1].type, "something/else", "Verify type of script tag." );
jQuery("#main").html(valueObj("<script>ok( true, 'Test repeated injection of script.' );</script>")); jQuery("#qunit-fixture").html(valueObj("<script>ok( true, 'Test repeated injection of script.' );</script>"));
jQuery("#main").html(valueObj("<script>ok( true, 'Test repeated injection of script.' );</script>")); jQuery("#qunit-fixture").html(valueObj("<script>ok( true, 'Test repeated injection of script.' );</script>"));
jQuery("#main").html(valueObj("<script>ok( true, 'Test repeated injection of script.' );</script>")); jQuery("#qunit-fixture").html(valueObj("<script>ok( true, 'Test repeated injection of script.' );</script>"));
jQuery("#main").html(valueObj("<script type='text/javascript'>ok( true, 'jQuery().html().evalScripts() Evals Scripts Twice in Firefox, see #975 (1)' );</script>")); jQuery("#qunit-fixture").html(valueObj("<script type='text/javascript'>ok( true, 'jQuery().html().evalScripts() Evals Scripts Twice in Firefox, see #975 (1)' );</script>"));
jQuery("#main").html(valueObj("foo <form><script type='text/javascript'>ok( true, 'jQuery().html().evalScripts() Evals Scripts Twice in Firefox, see #975 (2)' );</script></form>")); jQuery("#qunit-fixture").html(valueObj("foo <form><script type='text/javascript'>ok( true, 'jQuery().html().evalScripts() Evals Scripts Twice in Firefox, see #975 (2)' );</script></form>"));
jQuery("#main").html(valueObj("<script>equals(jQuery.scriptorder++, 0, 'Script is executed in order');equals(jQuery('#scriptorder').length, 1,'Execute after html (even though appears before)')<\/script><span id='scriptorder'><script>equals(jQuery.scriptorder++, 1, 'Script (nested) is executed in order');equals(jQuery('#scriptorder').length, 1,'Execute after html')<\/script></span><script>equals(jQuery.scriptorder++, 2, 'Script (unnested) is executed in order');equals(jQuery('#scriptorder').length, 1,'Execute after html')<\/script>")); jQuery("#qunit-fixture").html(valueObj("<script>equals(jQuery.scriptorder++, 0, 'Script is executed in order');equals(jQuery('#scriptorder').length, 1,'Execute after html (even though appears before)')<\/script><span id='scriptorder'><script>equals(jQuery.scriptorder++, 1, 'Script (nested) is executed in order');equals(jQuery('#scriptorder').length, 1,'Execute after html')<\/script></span><script>equals(jQuery.scriptorder++, 2, 'Script (unnested) is executed in order');equals(jQuery('#scriptorder').length, 1,'Execute after html')<\/script>"));
} }
test("html(String)", function() { test("html(String)", function() {
@ -1143,18 +1143,18 @@ test("html(Function)", function() {
QUnit.reset(); QUnit.reset();
jQuery("#main").html(function(){ jQuery("#qunit-fixture").html(function(){
return jQuery(this).text(); return jQuery(this).text();
}); });
ok( !/</.test( jQuery("#main").html() ), "Replace html with text." ); ok( !/</.test( jQuery("#qunit-fixture").html() ), "Replace html with text." );
ok( jQuery("#main").html().length > 0, "Make sure text exists." ); ok( jQuery("#qunit-fixture").html().length > 0, "Make sure text exists." );
}); });
test("html(Function) with incoming value", function() { test("html(Function) with incoming value", function() {
expect(20); expect(20);
var div = jQuery("#main > div"), old = div.map(function(){ return jQuery(this).html() }); var div = jQuery("#qunit-fixture > div"), old = div.map(function(){ return jQuery(this).html() });
div.html(function(i, val) { div.html(function(i, val) {
equals( val, old[i], "Make sure the incoming value is correct." ); equals( val, old[i], "Make sure the incoming value is correct." );
@ -1251,7 +1251,7 @@ var testRemove = function(method) {
var count = 0; var count = 0;
var first = jQuery("#ap").children(":first"); var first = jQuery("#ap").children(":first");
var cleanUp = first.click(function() { count++ })[method]().appendTo("#main").click(); var cleanUp = first.click(function() { count++ })[method]().appendTo("#qunit-fixture").click();
equals( method == "remove" ? 0 : 1, count ); equals( method == "remove" ? 0 : 1, count );
@ -1359,7 +1359,7 @@ test("jQuery.buildFragment - no plain-text caching (Bug #6779)", function() {
expect(1); expect(1);
// DOM manipulation fails if added text matches an Object method // DOM manipulation fails if added text matches an Object method
var $f = jQuery( "<div />" ).appendTo( "#main" ), var $f = jQuery( "<div />" ).appendTo( "#qunit-fixture" ),
bad = [ "start-", "toString", "hasOwnProperty", "append", "here&there!", "-end" ]; bad = [ "start-", "toString", "hasOwnProperty", "append", "here&there!", "-end" ];
for ( var i=0; i < bad.length; i++ ) { for ( var i=0; i < bad.length; i++ ) {

View File

@ -8,9 +8,9 @@ test("find(String)", function() {
var j = jQuery("#nonnodes").contents(); var j = jQuery("#nonnodes").contents();
equals( j.find("div").length, 0, "Check node,textnode,comment to find zero divs" ); equals( j.find("div").length, 0, "Check node,textnode,comment to find zero divs" );
same( jQuery("#main").find("> div").get(), q("foo", "moretests", "tabindex-tests", "liveHandlerOrder", "siblingTest"), "find child elements" ); same( jQuery("#qunit-fixture").find("> div").get(), q("foo", "moretests", "tabindex-tests", "liveHandlerOrder", "siblingTest"), "find child elements" );
same( jQuery("#main").find("> #foo, > #moretests").get(), q("foo", "moretests"), "find child elements" ); same( jQuery("#qunit-fixture").find("> #foo, > #moretests").get(), q("foo", "moretests"), "find child elements" );
same( jQuery("#main").find("> #foo > p").get(), q("sndp", "en", "sap"), "find child elements" ); same( jQuery("#qunit-fixture").find("> #foo > p").get(), q("sndp", "en", "sap"), "find child elements" );
}); });
test("find(node|jQuery object)", function() { test("find(node|jQuery object)", function() {
@ -155,9 +155,9 @@ test("filter(Selector|undefined)", function() {
test("filter(Function)", function() { test("filter(Function)", function() {
expect(2); expect(2);
same( jQuery("#main p").filter(function() { return !jQuery("a", this).length }).get(), q("sndp", "first"), "filter(Function)" ); same( jQuery("#qunit-fixture p").filter(function() { return !jQuery("a", this).length }).get(), q("sndp", "first"), "filter(Function)" );
same( jQuery("#main p").filter(function(i, elem) { return !jQuery("a", elem).length }).get(), q("sndp", "first"), "filter(Function) using arg" ); same( jQuery("#qunit-fixture p").filter(function(i, elem) { return !jQuery("a", elem).length }).get(), q("sndp", "first"), "filter(Function) using arg" );
}); });
test("filter(Element)", function() { test("filter(Element)", function() {
@ -186,7 +186,7 @@ test("closest()", function() {
same( jQuery("body").closest("body").get(), q("body"), "closest(body)" ); same( jQuery("body").closest("body").get(), q("body"), "closest(body)" );
same( jQuery("body").closest("html").get(), q("html"), "closest(html)" ); same( jQuery("body").closest("html").get(), q("html"), "closest(html)" );
same( jQuery("body").closest("div").get(), [], "closest(div)" ); same( jQuery("body").closest("div").get(), [], "closest(div)" );
same( jQuery("#main").closest("span,#html").get(), q("html"), "closest(span,#html)" ); same( jQuery("#qunit-fixture").closest("span,#html").get(), q("html"), "closest(span,#html)" );
same( jQuery("div:eq(1)").closest("div:first").get(), [], "closest(div:first)" ); same( jQuery("div:eq(1)").closest("div:first").get(), [], "closest(div:first)" );
same( jQuery("div").closest("body:first div:last").get(), q("fx-tests"), "closest(body:first div:last)" ); same( jQuery("div").closest("body:first div:last").get(), q("fx-tests"), "closest(body:first div:last)" );
@ -198,7 +198,7 @@ test("closest()", function() {
same( jq.closest("#nothiddendiv", document.body).get(), q("nothiddendiv"), "Context not reached." ); same( jq.closest("#nothiddendiv", document.body).get(), q("nothiddendiv"), "Context not reached." );
//Test that .closest() returns unique'd set //Test that .closest() returns unique'd set
equals( jQuery("#main p").closest("#main").length, 1, "Closest should return a unique set" ); equals( jQuery("#qunit-fixture p").closest("#qunit-fixture").length, 1, "Closest should return a unique set" );
// Test on disconnected node // Test on disconnected node
equals( jQuery("<div><p></p></div>").find("p").closest("table").length, 0, "Make sure disconnected closest work." ); equals( jQuery("<div><p></p></div>").find("p").closest("table").length, 0, "Make sure disconnected closest work." );
@ -213,8 +213,8 @@ test("closest(Array)", function() {
same( jQuery("body").closest(["body"]), [{selector:"body", elem:document.body, level:1}], "closest([body])" ); same( jQuery("body").closest(["body"]), [{selector:"body", elem:document.body, level:1}], "closest([body])" );
same( jQuery("body").closest(["html"]), [{selector:"html", elem:document.documentElement, level:2}], "closest([html])" ); same( jQuery("body").closest(["html"]), [{selector:"html", elem:document.documentElement, level:2}], "closest([html])" );
same( jQuery("body").closest(["div"]), [], "closest([div])" ); same( jQuery("body").closest(["div"]), [], "closest([div])" );
same( jQuery("#yahoo").closest(["div"]), [{"selector":"div", "elem": document.getElementById("foo"), "level": 3}, { "selector": "div", "elem": document.getElementById("main"), "level": 4 }], "closest([div])" ); same( jQuery("#yahoo").closest(["div"]), [{"selector":"div", "elem": document.getElementById("foo"), "level": 3}, { "selector": "div", "elem": document.getElementById("qunit-fixture"), "level": 4 }], "closest([div])" );
same( jQuery("#main").closest(["span,#html"]), [{selector:"span,#html", elem:document.documentElement, level:4}], "closest([span,#html])" ); same( jQuery("#qunit-fixture").closest(["span,#html"]), [{selector:"span,#html", elem:document.documentElement, level:4}], "closest([span,#html])" );
same( jQuery("body").closest(["body","html"]), [{selector:"body", elem:document.body, level:1}, {selector:"html", elem:document.documentElement, level:2}], "closest([body, html])" ); same( jQuery("body").closest(["body","html"]), [{selector:"body", elem:document.body, level:1}, {selector:"html", elem:document.documentElement, level:2}], "closest([body, html])" );
same( jQuery("body").closest(["span","html"]), [{selector:"html", elem:document.documentElement, level:2}], "closest([body, html])" ); same( jQuery("body").closest(["span","html"]), [{selector:"html", elem:document.documentElement, level:2}], "closest([body, html])" );
@ -224,7 +224,7 @@ test("closest(jQuery)", function() {
expect(8); expect(8);
var $child = jQuery("#nothiddendivchild"), var $child = jQuery("#nothiddendivchild"),
$parent = jQuery("#nothiddendiv"), $parent = jQuery("#nothiddendiv"),
$main = jQuery("#main"), $main = jQuery("#qunit-fixture"),
$body = jQuery("body"); $body = jQuery("body");
ok( $child.closest( $parent ).is("#nothiddendiv"), "closest( jQuery('#nothiddendiv') )" ); ok( $child.closest( $parent ).is("#nothiddendiv"), "closest( jQuery('#nothiddendiv') )" );
ok( $child.closest( $parent[0] ).is("#nothiddendiv"), "closest( jQuery('#nothiddendiv') ) :: node" ); ok( $child.closest( $parent[0] ).is("#nothiddendiv"), "closest( jQuery('#nothiddendiv') ) :: node" );
@ -238,7 +238,7 @@ test("closest(jQuery)", function() {
test("not(Selector|undefined)", function() { test("not(Selector|undefined)", function() {
expect(11); expect(11);
equals( jQuery("#main > p#ap > a").not("#google").length, 2, "not('selector')" ); equals( jQuery("#qunit-fixture > p#ap > a").not("#google").length, 2, "not('selector')" );
same( jQuery("p").not(".result").get(), q("firstp", "ap", "sndp", "en", "sap", "first"), "not('.class')" ); same( jQuery("p").not(".result").get(), q("firstp", "ap", "sndp", "en", "sap", "first"), "not('.class')" );
same( jQuery("p").not("#ap, #sndp, .result").get(), q("firstp", "en", "sap", "first"), "not('selector, selector')" ); same( jQuery("p").not("#ap, #sndp, .result").get(), q("firstp", "en", "sap", "first"), "not('selector, selector')" );
same( jQuery("#form option").not("option.emptyopt:contains('Nothing'),[selected],[value='1']").get(), q("option1c", "option1d", "option2c", "option3d", "option3e", "option4e","option5b"), "not('complex selector')"); same( jQuery("#form option").not("option.emptyopt:contains('Nothing'),[selected],[value='1']").get(), q("option1c", "option1d", "option2c", "option3d", "option3e", "option4e","option5b"), "not('complex selector')");
@ -262,13 +262,13 @@ test("not(Element)", function() {
}); });
test("not(Function)", function() { test("not(Function)", function() {
same( jQuery("#main p").not(function() { return jQuery("a", this).length }).get(), q("sndp", "first"), "not(Function)" ); same( jQuery("#qunit-fixture p").not(function() { return jQuery("a", this).length }).get(), q("sndp", "first"), "not(Function)" );
}); });
test("not(Array)", function() { test("not(Array)", function() {
expect(2); expect(2);
equals( jQuery("#main > p#ap > a").not(document.getElementById("google")).length, 2, "not(DOMElement)" ); equals( jQuery("#qunit-fixture > p#ap > a").not(document.getElementById("google")).length, 2, "not(DOMElement)" );
equals( jQuery("p").not(document.getElementsByTagName("p")).length, 0, "not(Array-like DOM collection)" ); equals( jQuery("p").not(document.getElementsByTagName("p")).length, 0, "not(Array-like DOM collection)" );
}); });
@ -281,37 +281,37 @@ test("not(jQuery)", function() {
test("has(Element)", function() { test("has(Element)", function() {
expect(2); expect(2);
var obj = jQuery("#main").has(jQuery("#sndp")[0]); var obj = jQuery("#qunit-fixture").has(jQuery("#sndp")[0]);
same( obj.get(), q("main"), "Keeps elements that have the element as a descendant" ); same( obj.get(), q("qunit-fixture"), "Keeps elements that have the element as a descendant" );
var multipleParent = jQuery("#main, #header").has(jQuery("#sndp")[0]); var multipleParent = jQuery("#qunit-fixture, #header").has(jQuery("#sndp")[0]);
same( obj.get(), q("main"), "Does not include elements that do not have the element as a descendant" ); same( obj.get(), q("qunit-fixture"), "Does not include elements that do not have the element as a descendant" );
}); });
test("has(Selector)", function() { test("has(Selector)", function() {
expect(3); expect(3);
var obj = jQuery("#main").has("#sndp"); var obj = jQuery("#qunit-fixture").has("#sndp");
same( obj.get(), q("main"), "Keeps elements that have any element matching the selector as a descendant" ); same( obj.get(), q("qunit-fixture"), "Keeps elements that have any element matching the selector as a descendant" );
var multipleParent = jQuery("#main, #header").has("#sndp"); var multipleParent = jQuery("#qunit-fixture, #header").has("#sndp");
same( obj.get(), q("main"), "Does not include elements that do not have the element as a descendant" ); same( obj.get(), q("qunit-fixture"), "Does not include elements that do not have the element as a descendant" );
var multipleHas = jQuery("#main").has("#sndp, #first"); var multipleHas = jQuery("#qunit-fixture").has("#sndp, #first");
same( multipleHas.get(), q("main"), "Only adds elements once" ); same( multipleHas.get(), q("qunit-fixture"), "Only adds elements once" );
}); });
test("has(Arrayish)", function() { test("has(Arrayish)", function() {
expect(3); expect(3);
var simple = jQuery("#main").has(jQuery("#sndp")); var simple = jQuery("#qunit-fixture").has(jQuery("#sndp"));
same( simple.get(), q("main"), "Keeps elements that have any element in the jQuery list as a descendant" ); same( simple.get(), q("qunit-fixture"), "Keeps elements that have any element in the jQuery list as a descendant" );
var multipleParent = jQuery("#main, #header").has(jQuery("#sndp")); var multipleParent = jQuery("#qunit-fixture, #header").has(jQuery("#sndp"));
same( multipleParent.get(), q("main"), "Does not include elements that do not have an element in the jQuery list as a descendant" ); same( multipleParent.get(), q("qunit-fixture"), "Does not include elements that do not have an element in the jQuery list as a descendant" );
var multipleHas = jQuery("#main").has(jQuery("#sndp, #first")); var multipleHas = jQuery("#qunit-fixture").has(jQuery("#sndp, #first"));
same( simple.get(), q("main"), "Only adds elements once" ); same( simple.get(), q("qunit-fixture"), "Only adds elements once" );
}); });
test("andSelf()", function() { test("andSelf()", function() {
@ -319,7 +319,7 @@ test("andSelf()", function() {
same( jQuery("#en").siblings().andSelf().get(), q("sndp", "en", "sap"), "Check for siblings and self" ); same( jQuery("#en").siblings().andSelf().get(), q("sndp", "en", "sap"), "Check for siblings and self" );
same( jQuery("#foo").children().andSelf().get(), q("foo", "sndp", "en", "sap"), "Check for children and self" ); same( jQuery("#foo").children().andSelf().get(), q("foo", "sndp", "en", "sap"), "Check for children and self" );
same( jQuery("#sndp, #en").parent().andSelf().get(), q("foo","sndp","en"), "Check for parent and self" ); same( jQuery("#sndp, #en").parent().andSelf().get(), q("foo","sndp","en"), "Check for parent and self" );
same( jQuery("#groups").parents("p, div").andSelf().get(), q("main", "ap", "groups"), "Check for parents and self" ); same( jQuery("#groups").parents("p, div").andSelf().get(), q("qunit-fixture", "ap", "groups"), "Check for parents and self" );
}); });
test("siblings([String])", function() { test("siblings([String])", function() {
@ -352,9 +352,9 @@ test("parents([String])", function() {
expect(5); expect(5);
equals( jQuery("#groups").parents()[0].id, "ap", "Simple parents check" ); equals( jQuery("#groups").parents()[0].id, "ap", "Simple parents check" );
equals( jQuery("#groups").parents("p")[0].id, "ap", "Filtered parents check" ); equals( jQuery("#groups").parents("p")[0].id, "ap", "Filtered parents check" );
equals( jQuery("#groups").parents("div")[0].id, "main", "Filtered parents check2" ); equals( jQuery("#groups").parents("div")[0].id, "qunit-fixture", "Filtered parents check2" );
same( jQuery("#groups").parents("p, div").get(), q("ap", "main"), "Check for multiple filters" ); same( jQuery("#groups").parents("p, div").get(), q("ap", "qunit-fixture"), "Check for multiple filters" );
same( jQuery("#en, #sndp").parents().get(), q("foo", "main", "dl", "body", "html"), "Check for unique results from parents" ); same( jQuery("#en, #sndp").parents().get(), q("foo", "qunit-fixture", "dl", "body", "html"), "Check for unique results from parents" );
}); });
test("parentsUntil([String])", function() { test("parentsUntil([String])", function() {
@ -367,7 +367,7 @@ test("parentsUntil([String])", function() {
same( jQuery("#groups").parentsUntil("#html").get(), parents.not(":last").get(), "Simple parentsUntil check" ); same( jQuery("#groups").parentsUntil("#html").get(), parents.not(":last").get(), "Simple parentsUntil check" );
equals( jQuery("#groups").parentsUntil("#ap").length, 0, "Simple parentsUntil check" ); equals( jQuery("#groups").parentsUntil("#ap").length, 0, "Simple parentsUntil check" );
same( jQuery("#groups").parentsUntil("#html, #body").get(), parents.slice( 0, 3 ).get(), "Less simple parentsUntil check" ); same( jQuery("#groups").parentsUntil("#html, #body").get(), parents.slice( 0, 3 ).get(), "Less simple parentsUntil check" );
same( jQuery("#groups").parentsUntil("#html", "div").get(), jQuery("#main").get(), "Filtered parentsUntil check" ); same( jQuery("#groups").parentsUntil("#html", "div").get(), jQuery("#qunit-fixture").get(), "Filtered parentsUntil check" );
same( jQuery("#groups").parentsUntil("#html", "p,div,dl").get(), parents.slice( 0, 3 ).get(), "Multiple-filtered parentsUntil check" ); same( jQuery("#groups").parentsUntil("#html", "p,div,dl").get(), parents.slice( 0, 3 ).get(), "Multiple-filtered parentsUntil check" );
equals( jQuery("#groups").parentsUntil("#html", "span").length, 0, "Filtered parentsUntil check, no match" ); equals( jQuery("#groups").parentsUntil("#html", "span").length, 0, "Filtered parentsUntil check, no match" );
same( jQuery("#groups, #ap").parentsUntil("#html", "p,div,dl").get(), parents.slice( 0, 3 ).get(), "Multi-source, multiple-filtered parentsUntil check" ); same( jQuery("#groups, #ap").parentsUntil("#html", "p,div,dl").get(), parents.slice( 0, 3 ).get(), "Multi-source, multiple-filtered parentsUntil check" );