diff options
Diffstat (limited to 'npm_assets/node_modules/html5shiv/test/jquery-1.7.1')
11 files changed, 4147 insertions, 0 deletions
diff --git a/npm_assets/node_modules/html5shiv/test/jquery-1.7.1/data/dashboard.xml b/npm_assets/node_modules/html5shiv/test/jquery-1.7.1/data/dashboard.xml new file mode 100644 index 0000000..5a6f561 --- /dev/null +++ b/npm_assets/node_modules/html5shiv/test/jquery-1.7.1/data/dashboard.xml @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="UTF-8"?> +<dashboard> + <locations class="foo"> + <location for="bar" checked="different"> + <infowindowtab> + <tab title="Location"><![CDATA[blabla]]></tab> + <tab title="Users"><![CDATA[blublu]]></tab> + </infowindowtab> + </location> + </locations> +</dashboard> diff --git a/npm_assets/node_modules/html5shiv/test/jquery-1.7.1/data/iframe.html b/npm_assets/node_modules/html5shiv/test/jquery-1.7.1/data/iframe.html new file mode 100644 index 0000000..3ff26e1 --- /dev/null +++ b/npm_assets/node_modules/html5shiv/test/jquery-1.7.1/data/iframe.html @@ -0,0 +1,8 @@ +<html> + <head> + <title>iframe</title> + </head> + <body> + <div><span>span text</span></div> + </body> +</html> diff --git a/npm_assets/node_modules/html5shiv/test/jquery-1.7.1/data/test.js b/npm_assets/node_modules/html5shiv/test/jquery-1.7.1/data/test.js new file mode 100644 index 0000000..69f492d --- /dev/null +++ b/npm_assets/node_modules/html5shiv/test/jquery-1.7.1/data/test.js @@ -0,0 +1,3 @@ +var foobar = "bar"; +jQuery('#ap').html('bar'); +ok( true, "test.js executed"); diff --git a/npm_assets/node_modules/html5shiv/test/jquery-1.7.1/data/testinit.js b/npm_assets/node_modules/html5shiv/test/jquery-1.7.1/data/testinit.js new file mode 100644 index 0000000..aeda243 --- /dev/null +++ b/npm_assets/node_modules/html5shiv/test/jquery-1.7.1/data/testinit.js @@ -0,0 +1,121 @@ +var jQuery = this.jQuery || "jQuery", // For testing .noConflict() + $ = this.$ || "$", + originaljQuery = jQuery, + original$ = $, + amdDefined; + +/** + * Set up a mock AMD define function for testing AMD registration. + */ +function define(name, dependencies, callback) { + amdDefined = callback(); +} + +define.amd = { + jQuery: true +}; + +/** + * Returns an array of elements with the given IDs, eg. + * @example q("main", "foo", "bar") + * @result [<div id="main">, <span id="foo">, <input id="bar">] + */ +function q() { + var r = []; + + for ( var i = 0; i < arguments.length; i++ ) { + r.push( document.getElementById( arguments[i] ) ); + } + + return r; +} + +/** + * Asserts that a select matches the given IDs * @example t("Check for something", "//[a]", ["foo", "baar"]); + * @result returns true if "//[a]" return two elements with the IDs 'foo' and 'baar' + */ +function t(a,b,c) { + var f = jQuery(b).get(), s = ""; + + for ( var i = 0; i < f.length; i++ ) { + s += (s && ",") + '"' + f[i].id + '"'; + } + + deepEqual(f, q.apply(q,c), a + " (" + b + ")"); +} + +var fireNative; +if ( document.createEvent ) { + fireNative = function( node, type ) { + var event = document.createEvent('HTMLEvents'); + event.initEvent( type, true, true ); + node.dispatchEvent( event ); + }; +} else { + fireNative = function( node, type ) { + var event = document.createEventObject(); + node.fireEvent( 'on' + type, event ); + }; +} + +/** + * Add random number to url to stop IE from caching + * + * @example url("data/test.html") + * @result "data/test.html?10538358428943" + * + * @example url("data/test.php?foo=bar") + * @result "data/test.php?foo=bar&10538358345554" + */ +function url(value) { + return value + (/\?/.test(value) ? "&" : "?") + new Date().getTime() + "" + parseInt(Math.random()*100000); +} + +(function () { + // Store the old counts so that we only assert on tests that have actually leaked, + // instead of asserting every time a test has leaked sometime in the past + var oldCacheLength = 0, + oldFragmentsLength = 0, + oldTimersLength = 0, + oldActive = 0; + + /** + * Ensures that tests have cleaned up properly after themselves. Should be passed as the + * teardown function on all modules' lifecycle object. + */ + this.moduleTeardown = function () { + var i, fragmentsLength = 0, cacheLength = 0; + + // Allow QUnit.reset to clean up any attached elements before checking for leaks + QUnit.reset(); + + for ( i in jQuery.cache ) { + ++cacheLength; + } + + jQuery.fragments = {}; + + for ( i in jQuery.fragments ) { + ++fragmentsLength; + } + + // Because QUnit doesn't have a mechanism for retrieving the number of expected assertions for a test, + // if we unconditionally assert any of these, the test will fail with too many assertions :| + if ( cacheLength !== oldCacheLength ) { + equal( cacheLength, oldCacheLength, "No unit tests leak memory in jQuery.cache" ); + oldCacheLength = cacheLength; + } + if ( fragmentsLength !== oldFragmentsLength ) { + equal( fragmentsLength, oldFragmentsLength, "No unit tests leak memory in jQuery.fragments" ); + oldFragmentsLength = fragmentsLength; + } + if ( jQuery.timers.length !== oldTimersLength ) { + equal( jQuery.timers.length, oldTimersLength, "No timers are still running" ); + oldTimersLength = jQuery.timers.length; + } + if ( jQuery.active !== oldActive ) { + equal( jQuery.active, 0, "No AJAX requests are still active" ); + oldActive = jQuery.active; + } + } +}());
\ No newline at end of file diff --git a/npm_assets/node_modules/html5shiv/test/jquery-1.7.1/data/testrunner.js b/npm_assets/node_modules/html5shiv/test/jquery-1.7.1/data/testrunner.js new file mode 100644 index 0000000..bdfbcac --- /dev/null +++ b/npm_assets/node_modules/html5shiv/test/jquery-1.7.1/data/testrunner.js @@ -0,0 +1,27 @@ +jQuery.noConflict(); // Allow the test to run with other libs or jQuery's. + +// jQuery-specific QUnit.reset +(function() { + var reset = QUnit.reset, + ajaxSettings = jQuery.ajaxSettings; + + QUnit.reset = function() { + reset.apply(this, arguments); + jQuery.event.global = {}; + jQuery.ajaxSettings = jQuery.extend({}, ajaxSettings); + }; +})(); + +// load testswarm agent +(function() { + var url = window.location.search; + url = decodeURIComponent( url.slice( url.indexOf("swarmURL=") + 9 ) ); + if ( !url || url.indexOf("http") !== 0 ) { + return; + } + + // (Temporarily) Disable Ajax tests to reduce network strain + // isLocal = QUnit.isLocal = true; + + document.write("<scr" + "ipt src='http://swarm.jquery.org/js/inject.js?" + (new Date).getTime() + "'></scr" + "ipt>"); +})(); diff --git a/npm_assets/node_modules/html5shiv/test/jquery-1.7.1/data/testsuite.css b/npm_assets/node_modules/html5shiv/test/jquery-1.7.1/data/testsuite.css new file mode 100644 index 0000000..d3e4b4e --- /dev/null +++ b/npm_assets/node_modules/html5shiv/test/jquery-1.7.1/data/testsuite.css @@ -0,0 +1,128 @@ +/* for testing opacity set in styles in IE */ +ol#empty { opacity: 0; filter:Alpha(opacity=0) progid:DXImageTransform.Microsoft.gradient(startColorStr='#ffff0000', EndColorStr='#ffffffff'); } + +div#fx-tests h4 { + background: red; +} + +div#fx-tests h4.pass { + background: green; +} + +div#fx-tests div.box { + background: red; + overflow: hidden; + border: 2px solid #000; +} + +div#fx-tests div.overflow { + overflow: visible; +} + +div.inline { + display: inline; +} + +div.autoheight { + height: auto; +} + +div.autowidth { + width: auto; +} + +div.autoopacity { + opacity: auto; +} + +div.largewidth { + width: 100px; +} + +div.largeheight { + height: 100px; +} + +div.largeopacity { + filter: progid:DXImageTransform.Microsoft.Alpha(opacity=100); +} + +div.medwidth { + width: 50px; +} + +div.medheight { + height: 50px; +} + +div.medopacity { + opacity: 0.5; + filter: progid:DXImageTransform.Microsoft.Alpha(opacity=50); +} + +div.nowidth { + width: 0px; +} + +div.noheight { + height: 0px; +} + +div.noopacity { + opacity: 0; + filter: progid:DXImageTransform.Microsoft.Alpha(opacity=0); +} + +div.hidden { + display: none; +} + +div#fx-tests div.widewidth { + background-repeat: repeat-x; +} + +div#fx-tests div.wideheight { + background-repeat: repeat-y; +} + +div#fx-tests div.widewidth.wideheight { + background-repeat: repeat; +} + +div#fx-tests div.noback { + background-image: none; +} + +div.chain, div.chain div { width: 100px; height: 20px; position: relative; float: left; } +div.chain div { position: absolute; top: 0px; left: 0px; } + +div.chain.test { background: red; } +div.chain.test div { background: green; } + +div.chain.out { background: green; } +div.chain.out div { background: red; display: none; } + +/* tests to ensure jQuery can determine the native display mode of elements + that have been set as display: none in stylesheets */ +div#show-tests * { display: none; } + +#nothiddendiv { font-size: 16px; } +#nothiddendivchild.em { font-size: 2em; } +#nothiddendivchild.prct { font-size: 150%; } + +/* For testing type on vml in IE #7071 */ +v\:oval { behavior:url(#default#VML); display:inline-block; } + +/* 8099 changes to default styles are read correctly */ +tt { display: none; } +sup { display: none; } +dfn { display: none; } + +/* #9239 Attach a background to the body( avoid crashes in removing the test element in support ) */ +body, div { background: url(http://static.jquery.com/files/rocker/images/logo_jquery_215x53.gif) no-repeat -1000px 0; } + +/* #6652 REMOVE FILTER:ALPHA(OPACITY=100) AFTER ANIMATION */ +#t6652 div { filter: alpha(opacity=50); } + +/* #10501 */ +section { background:#f0f; display:block; }
\ No newline at end of file diff --git a/npm_assets/node_modules/html5shiv/test/jquery-1.7.1/data/versioncheck.js b/npm_assets/node_modules/html5shiv/test/jquery-1.7.1/data/versioncheck.js new file mode 100644 index 0000000..f4b7790 --- /dev/null +++ b/npm_assets/node_modules/html5shiv/test/jquery-1.7.1/data/versioncheck.js @@ -0,0 +1,8 @@ +// Run minified source from dist (do make first) +// Should be loaded before QUnit but after src +(function() { + if ( /jquery\=min/.test( window.location.search ) ) { + jQuery.noConflict( true ); + document.write(unescape("%3Cscript%20src%3D%27../dist/jquery.min.js%27%3E%3C/script%3E")); + } +})();
\ No newline at end of file diff --git a/npm_assets/node_modules/html5shiv/test/jquery-1.7.1/index.html b/npm_assets/node_modules/html5shiv/test/jquery-1.7.1/index.html new file mode 100644 index 0000000..1810d3b --- /dev/null +++ b/npm_assets/node_modules/html5shiv/test/jquery-1.7.1/index.html @@ -0,0 +1,249 @@ +<!doctype html> +<html lang="en" dir="ltr" id="html"> + <head> + <meta charset="utf-8"> + <title>jQuery Test Suite</title> + <link rel="stylesheet" media="screen" href="../qunit/qunit.css"> + <link rel="stylesheet" media="screen" href="data/testsuite.css"> + <script src="data/testinit.js"></script> + <script src="../../src/html5shiv-printshiv.js"></script> + <script src="//code.jquery.com/jquery-1.7.1.min.js"></script> + <script src="data/versioncheck.js"></script> + <script src="../qunit/qunit.js"></script> + <script src="data/testrunner.js"></script> + <script src="unit/core.js"></script> + <script src="unit/traversing.js"></script> + <script src="unit/manipulation.js"></script> + </head> + <body id="body"> + <h1 id="qunit-header"><a href="/jquery/test/index.html">jQuery Test Suite</a> + <a href="?jquery=min">(minified)</a> + </h1> + <h2 id="qunit-banner"></h2> + <div id="qunit-testrunner-toolbar"></div> + <h2 id="qunit-userAgent"></h2> + <ol id="qunit-tests"></ol> + + <!-- Test HTML --> + <div id="nothiddendiv" style="height:1px;background:white;" class="nothiddendiv"> + <div id="nothiddendivchild"></div> + </div> + + <!-- 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> + <dl id="dl" style="position:absolute;top:-32767px;left:-32767px;width:1px"> + <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="ap"> + Here are some links in a normal paragraph: <a id="google" href="http://www.google.com/" title="Google!">Google</a>, + <a id="groups" href="http://groups.google.com/" class="GROUPS">Google Groups (Link)</a>. + This link has <code><a href="http://smin" id="anchor1">class="blog"</a></code>: + <a href="http://diveintomark.org/" class="blog" hreflang="en" id="mark">diveintomark</a> + </p> + <div id="foo"> + <p id="sndp">Everything inside the red border is inside a div with <code>id="foo"</code>.</p> + <p lang="en" id="en">This is a normal link: <a id="yahoo" href="http://www.yahoo.com/" class="blogTest">Yahoo</a></p> + <p id="sap">This link has <code><a href="#2" id="anchor2">class="blog"</a></code>: <a href="http://simon.incutio.com/" class="blog link" id="simon">Simon Willison's Weblog</a></p> + </div> + <span id="name+value"></span> + <p id="first">Try them out:</p> + <ul id="firstUL"></ul> + <ol id="empty"></ol> + <form id="form" action="formaction"> + <label for="action" id="label-for">Action:</label> + <input type="text" name="action" value="Test" id="text1" maxlength="30"> + <input type="text" name="text2" value="Test" id="text2" disabled="disabled"> + <input type="radio" name="radio1" id="radio1" value="on"> + + <input type="radio" name="radio2" id="radio2" checked="checked"> + <input type="checkbox" name="check" id="check1" checked="checked"> + <input type="checkbox" id="check2" value="on"> + + <input type="hidden" name="hidden" id="hidden1"> + <input type="text" style="display:none;" name="foo[bar]" id="hidden2"> + + <input type="text" id="name" name="name" value="name"> + <input type="search" id="search" name="search" value="search"> + + <button id="button" name="button" type="button">Button</button> + <textarea id="area1" maxlength="30">foobar</textarea> + + <select name="select1" id="select1"> + <option id="option1a" class="emptyopt" value="">Nothing</option> + <option id="option1b" value="1">1</option> + <option id="option1c" value="2">2</option> + <option id="option1d" value="3">3</option> + </select> + <select name="select2" id="select2"> + <option id="option2a" class="emptyopt" value="">Nothing</option> + <option id="option2b" value="1">1</option> + <option id="option2c" value="2">2</option> + <option id="option2d" selected="selected" value="3">3</option> + </select> + <select name="select3" id="select3" multiple="multiple"> + <option id="option3a" class="emptyopt" value="">Nothing</option> + <option id="option3b" selected="selected" value="1">1</option> + <option id="option3c" selected="selected" value="2">2</option> + <option id="option3d" value="3">3</option> + <option id="option3e">no value</option> + </select> + <select name="select4" id="select4" multiple="multiple"> + <optgroup disabled="disabled"> + <option id="option4a" class="emptyopt" value="">Nothing</option> + <option id="option4b" disabled="disabled" selected="selected" value="1">1</option> + <option id="option4c" selected="selected" value="2">2</option> + </optgroup> + <option selected="selected" disabled="disabled" id="option4d" value="3">3</option> + <option id="option4e">no value</option> + </select> + <select name="select5" id="select5"> + <option id="option5a" value="3">1</option> + <option id="option5b" value="2">2</option> + <option id="option5c" value="1" data-attr="">3</option> + </select> + + <object id="object1" codebase="stupid"> + <param name="p1" value="x1"> + <param name="p2" value="x2"> + </object> + + <span id="台北Táiběi"></span> + <span id="台北" lang="中文"></span> + <span id="utf8class1" class="台北Táiběi 台北"></span> + <span id="utf8class2" class="台北"></span> + <span id="foo:bar" class="foo:bar"></span> + <span id="test.foo[5]bar" class="test.foo[5]bar"></span> + <foo_bar id="foobar">test element</foo_bar> + </form> + <b id="floatTest">Float test.</b> + <iframe id="iframe" name="iframe"></iframe> + <form id="lengthtest"> + <input type="text" id="length" name="test"> + <input type="text" id="idTest" name="id"> + </form> + <table id="table"></table> + + <form id="name-tests"> + <!-- Inputs with a grouped name attribute. --> + <input name="types[]" id="types_all" type="checkbox" value="all"> + <input name="types[]" id="types_anime" type="checkbox" value="anime"> + <input name="types[]" id="types_movie" type="checkbox" value="movie"> + </form> + + <form id="testForm" action="#" method="get"> + <textarea name="T3" rows="2" cols="15">? +Z</textarea> + <input type="hidden" name="H1" value="x"> + <input type="hidden" name="H2"> + <input name="PWD" type="password" value=""> + <input name="T1" type="text"> + <input name="T2" type="text" value="YES" readonly="readonly"> + <input type="checkbox" name="C1" value="1"> + <input type="checkbox" name="C2"> + <input type="radio" name="R1" value="1"> + <input type="radio" name="R1" value="2"> + <input type="text" name="My Name" value="me"> + <input type="reset" name="reset" value="NO"> + <select name="S1"> + <option value="abc">ABC</option> + <option value="abc">ABC</option> + <option value="abc">ABC</option> + </select> + <select name="S2" multiple="multiple" size="3"> + <option value="abc">ABC</option> + <option value="abc">ABC</option> + <option value="abc">ABC</option> + </select> + <select name="S3"> + <option selected="selected">YES</option> + </select> + <select name="S4"> + <option value="" selected="selected">NO</option> + </select> + <input type="submit" name="sub1" value="NO"> + <input type="submit" name="sub2" value="NO"> + <input type="image" name="sub3" value="NO"> + <button name="sub4" type="submit" value="NO">NO</button> + <input name="D1" type="text" value="NO" disabled="disabled"> + <input type="checkbox" checked="checked" disabled="disabled" name="D2" value="NO"> + <input type="radio" name="D3" value="NO" checked="checked" disabled="disabled"> + <select name="D4" disabled="disabled"> + <option selected="selected" value="NO">NO</option> + </select> + <input id="list-test" type="text"> + <datalist id="datalist"> + <option value="option"></option> + </datalist> + </form> + <div id="moretests"> + <form> + <div id="checkedtest" style="display:none;"> + <input type="radio" name="checkedtestradios" checked="checked"> + <input type="radio" name="checkedtestradios" value="on"> + <input type="checkbox" name="checkedtestcheckboxes" checked="checked"> + <input type="checkbox" name="checkedtestcheckboxes"> + </div> + </form> + <div id="nonnodes"><span>hi</span> there <!-- mon ami --></div> + <div id="t2037"> + <div><div class="hidden">hidden</div></div> + </div> + <div id="t6652"> + <div></div> + </div> + <div id="no-clone-exception"><object><embed></embed></object></div> + </div> + + <div id="tabindex-tests"> + <ol id="listWithTabIndex" tabindex="5"> + <li id="foodWithNegativeTabIndex" tabindex="-1">Rice</li> + <li id="foodNoTabIndex">Beans</li> + <li>Blinis</li> + <li>Tofu</li> + </ol> + <div id="divWithNoTabIndex">I'm hungry. I should...</div> + <span>...</span><a href="#" id="linkWithNoTabIndex">Eat lots of food</a><span>...</span> | + <span>...</span><a href="#" id="linkWithTabIndex" tabindex="2">Eat a little food</a><span>...</span> | + <span>...</span><a href="#" id="linkWithNegativeTabIndex" tabindex="-1">Eat no food</a><span>...</span> + <span>...</span><a id="linkWithNoHrefWithNoTabIndex">Eat a burger</a><span>...</span> + <span>...</span><a id="linkWithNoHrefWithTabIndex" tabindex="1">Eat some funyuns</a><span>...</span> + <span>...</span><a id="linkWithNoHrefWithNegativeTabIndex" tabindex="-1">Eat some funyuns</a><span>...</span> + </div> + + <div id="liveHandlerOrder"> + <span id="liveSpan1"><a href="#" id="liveLink1"></a></span> + <span id="liveSpan2"><a href="#" id="liveLink2"></a></span> + </div> + + <div id="siblingTest"> + <em id="siblingfirst">1</em> + <em id="siblingnext">2</em> + </div> + </div> + </dl> + <div id="fx-test-group" style="position:absolute;width:1px;height:1px;overflow:hidden;"> + <div id="fx-queue" name="test"> + <div id="fadein" class='chain test' name='div'>fadeIn<div>fadeIn</div></div> + <div id="fadeout" class='chain test out'>fadeOut<div>fadeOut</div></div> + + <div id="show" class='chain test'>show<div>show</div></div> + <div id="hide" class='chain test out'>hide<div>hide</div></div> + + <div id="togglein" class='chain test'>togglein<div>togglein</div></div> + <div id="toggleout" class='chain test out'>toggleout<div>toggleout</div></div> + + <div id="slideup" class='chain test'>slideUp<div>slideUp</div></div> + <div id="slidedown" class='chain test out'>slideDown<div>slideDown</div></div> + + <div id="slidetogglein" class='chain test'>slideToggleIn<div>slideToggleIn</div></div> + <div id="slidetoggleout" class='chain test out'>slideToggleOut<div>slideToggleOut</div></div> + + <div id="fadetogglein" class='chain test'>fadeToggleIn<div>fadeToggleIn</div></div> + <div id="fadetoggleout" class='chain test out'>fadeToggleOut<div>fadeToggleOut</div></div> + + <div id="fadeto" class='chain test'>fadeTo<div>fadeTo</div></div> + </div> + <div id="fx-tests"></div> + </div> + </body> +</html>
\ No newline at end of file diff --git a/npm_assets/node_modules/html5shiv/test/jquery-1.7.1/unit/core.js b/npm_assets/node_modules/html5shiv/test/jquery-1.7.1/unit/core.js new file mode 100644 index 0000000..6d8dfaa --- /dev/null +++ b/npm_assets/node_modules/html5shiv/test/jquery-1.7.1/unit/core.js @@ -0,0 +1,1249 @@ +module("core", { teardown: moduleTeardown }); + +test("Basic requirements", function() { + expect(7); + ok( Array.prototype.push, "Array.push()" ); + ok( Function.prototype.apply, "Function.apply()" ); + ok( document.getElementById, "getElementById" ); + ok( document.getElementsByTagName, "getElementsByTagName" ); + ok( RegExp, "RegExp" ); + ok( jQuery, "jQuery" ); + ok( $, "$" ); +}); + +test("jQuery()", function() { + expect(29); + + // Basic constructor's behavior + + equal( jQuery().length, 0, "jQuery() === jQuery([])" ); + equal( jQuery(undefined).length, 0, "jQuery(undefined) === jQuery([])" ); + equal( jQuery(null).length, 0, "jQuery(null) === jQuery([])" ); + equal( jQuery("").length, 0, "jQuery('') === jQuery([])" ); + equal( jQuery("#").length, 0, "jQuery('#') === jQuery([])" ); + + var obj = jQuery("div"); + equal( jQuery(obj).selector, "div", "jQuery(jQueryObj) == jQueryObj" ); + + // can actually yield more than one, when iframes are included, the window is an array as well + equal( jQuery(window).length, 1, "Correct number of elements generated for jQuery(window)" ); + + + var main = jQuery("#qunit-fixture"); + deepEqual( jQuery("div p", main).get(), q("sndp", "en", "sap"), "Basic selector with jQuery object as context" ); + +/* + // disabled since this test was doing nothing. i tried to fix it but i'm not sure + // what the expected behavior should even be. FF returns "\n" for the text node + // make sure this is handled + var crlfContainer = jQuery('<p>\r\n</p>'); + var x = crlfContainer.contents().get(0).nodeValue; + equal( x, what???, "Check for \\r and \\n in jQuery()" ); +*/ + + /* // Disabled until we add this functionality in + var pass = true; + try { + jQuery("<div>Testing</div>").appendTo(document.getElementById("iframe").contentDocument.body); + } catch(e){ + pass = false; + } + ok( pass, "jQuery('<tag>') needs optional document parameter to ease cross-frame DOM wrangling, see #968" );*/ + + var code = jQuery("<code/>"); + equal( code.length, 1, "Correct number of elements generated for code" ); + equal( code.parent().length, 0, "Make sure that the generated HTML has no parent." ); + var img = jQuery("<img/>"); + equal( img.length, 1, "Correct number of elements generated for img" ); + equal( img.parent().length, 0, "Make sure that the generated HTML has no parent." ); + var div = jQuery("<div/><hr/><code/><b/>"); + equal( div.length, 4, "Correct number of elements generated for div hr code b" ); + equal( div.parent().length, 0, "Make sure that the generated HTML has no parent." ); + + equal( jQuery([1,2,3]).get(1), 2, "Test passing an array to the factory" ); + + equal( jQuery(document.body).get(0), jQuery("body").get(0), "Test passing an html node to the factory" ); + + var exec = false; + + var elem = jQuery("<div/>", { + width: 10, + css: { paddingLeft:1, paddingRight:1 }, + click: function(){ ok(exec, "Click executed."); }, + text: "test", + "class": "test2", + id: "test3" + }); + + equal( elem[0].style.width, "10px", "jQuery() quick setter width"); + equal( elem[0].style.paddingLeft, "1px", "jQuery quick setter css"); + equal( elem[0].style.paddingRight, "1px", "jQuery quick setter css"); + equal( elem[0].childNodes.length, 1, "jQuery quick setter text"); + equal( elem[0].firstChild.nodeValue, "test", "jQuery quick setter text"); + equal( elem[0].className, "test2", "jQuery() quick setter class"); + equal( elem[0].id, "test3", "jQuery() quick setter id"); + + exec = true; + elem.click(); + + // manually clean up detached elements + elem.remove(); + + for ( var i = 0; i < 3; ++i ) { + elem = jQuery("<input type='text' value='TEST' />"); + } + equal( elem[0].defaultValue, "TEST", "Ensure cached nodes are cloned properly (Bug #6655)" ); + + // manually clean up detached elements + elem.remove(); + + equal( jQuery(" <div/> ").length, 1, "Make sure whitespace is trimmed." ); + equal( jQuery(" a<div/>b ").length, 1, "Make sure whitespace and other characters are trimmed." ); + + var long = ""; + for ( var i = 0; i < 128; i++ ) { + long += "12345678"; + } + + equal( jQuery(" <div>" + long + "</div> ").length, 1, "Make sure whitespace is trimmed on long strings." ); + equal( jQuery(" a<div>" + long + "</div>b ").length, 1, "Make sure whitespace and other characters are trimmed on long strings." ); +}); + +test("selector state", function() { + expect(31); + + var test; + + test = jQuery(undefined); + equal( test.selector, "", "Empty jQuery Selector" ); + equal( test.context, undefined, "Empty jQuery Context" ); + + test = jQuery(document); + equal( test.selector, "", "Document Selector" ); + equal( test.context, document, "Document Context" ); + + test = jQuery(document.body); + equal( test.selector, "", "Body Selector" ); + equal( test.context, document.body, "Body Context" ); + + test = jQuery("#qunit-fixture"); + equal( test.selector, "#qunit-fixture", "#qunit-fixture Selector" ); + equal( test.context, document, "#qunit-fixture Context" ); + + test = jQuery("#notfoundnono"); + equal( test.selector, "#notfoundnono", "#notfoundnono Selector" ); + equal( test.context, document, "#notfoundnono Context" ); + + test = jQuery("#qunit-fixture", document); + equal( test.selector, "#qunit-fixture", "#qunit-fixture Selector" ); + equal( test.context, document, "#qunit-fixture Context" ); + + test = jQuery("#qunit-fixture", document.body); + equal( test.selector, "#qunit-fixture", "#qunit-fixture Selector" ); + equal( test.context, document.body, "#qunit-fixture Context" ); + + // Test cloning + test = jQuery(test); + equal( test.selector, "#qunit-fixture", "#qunit-fixture Selector" ); + equal( test.context, document.body, "#qunit-fixture Context" ); + + test = jQuery(document.body).find("#qunit-fixture"); + equal( test.selector, "#qunit-fixture", "#qunit-fixture find Selector" ); + equal( test.context, document.body, "#qunit-fixture find Context" ); + + test = jQuery("#qunit-fixture").filter("div"); + equal( test.selector, "#qunit-fixture.filter(div)", "#qunit-fixture filter Selector" ); + equal( test.context, document, "#qunit-fixture filter Context" ); + + test = jQuery("#qunit-fixture").not("div"); + equal( test.selector, "#qunit-fixture.not(div)", "#qunit-fixture not Selector" ); + equal( test.context, document, "#qunit-fixture not Context" ); + + test = jQuery("#qunit-fixture").filter("div").not("div"); + equal( test.selector, "#qunit-fixture.filter(div).not(div)", "#qunit-fixture filter, not Selector" ); + equal( test.context, document, "#qunit-fixture filter, not Context" ); + + test = jQuery("#qunit-fixture").filter("div").not("div").end(); + equal( test.selector, "#qunit-fixture.filter(div)", "#qunit-fixture filter, not, end Selector" ); + equal( test.context, document, "#qunit-fixture filter, not, end Context" ); + + test = jQuery("#qunit-fixture").parent("body"); + equal( test.selector, "#qunit-fixture.parent(body)", "#qunit-fixture parent Selector" ); + equal( test.context, document, "#qunit-fixture parent Context" ); + + test = jQuery("#qunit-fixture").eq(0); + equal( test.selector, "#qunit-fixture.slice(0,1)", "#qunit-fixture eq Selector" ); + equal( test.context, document, "#qunit-fixture eq Context" ); + + var d = "<div />"; + equal( + jQuery(d).appendTo(jQuery(d)).selector, + jQuery(d).appendTo(d).selector, + "manipulation methods make same selector for jQuery objects" + ); +}); + +test( "globalEval", function() { + + expect( 3 ); + + jQuery.globalEval( "var globalEvalTest = true;" ); + ok( window.globalEvalTest, "Test variable declarations are global" ); + + window.globalEvalTest = false; + + jQuery.globalEval( "globalEvalTest = true;" ); + ok( window.globalEvalTest, "Test variable assignments are global" ); + + window.globalEvalTest = false; + + jQuery.globalEval( "this.globalEvalTest = true;" ); + ok( window.globalEvalTest, "Test context (this) is the window object" ); + + window.globalEvalTest = undefined; +}); + + + +test("noConflict", function() { + expect(7); + + var $$ = jQuery; + + equal( jQuery, jQuery.noConflict(), "noConflict returned the jQuery object" ); + equal( jQuery, $$, "Make sure jQuery wasn't touched." ); + equal( $, original$, "Make sure $ was reverted." ); + + jQuery = $ = $$; + + equal( jQuery.noConflict(true), $$, "noConflict returned the jQuery object" ); + equal( jQuery, originaljQuery, "Make sure jQuery was reverted." ); + equal( $, original$, "Make sure $ was reverted." ); + ok( $$("#qunit-fixture").html("test"), "Make sure that jQuery still works." ); + + jQuery = $$; +}); + +test("trim", function() { + expect(9); + + var nbsp = String.fromCharCode(160); + + equal( jQuery.trim("hello "), "hello", "trailing space" ); + equal( jQuery.trim(" hello"), "hello", "leading space" ); + equal( jQuery.trim(" hello "), "hello", "space on both sides" ); + equal( jQuery.trim(" " + nbsp + "hello " + nbsp + " "), "hello", " " ); + + equal( jQuery.trim(), "", "Nothing in." ); + equal( jQuery.trim( undefined ), "", "Undefined" ); + equal( jQuery.trim( null ), "", "Null" ); + equal( jQuery.trim( 5 ), "5", "Number" ); + equal( jQuery.trim( false ), "false", "Boolean" ); +}); + +test("type", function() { + expect(23); + + equal( jQuery.type(null), "null", "null" ); + equal( jQuery.type(undefined), "undefined", "undefined" ); + equal( jQuery.type(true), "boolean", "Boolean" ); + equal( jQuery.type(false), "boolean", "Boolean" ); + equal( jQuery.type(Boolean(true)), "boolean", "Boolean" ); + equal( jQuery.type(0), "number", "Number" ); + equal( jQuery.type(1), "number", "Number" ); + equal( jQuery.type(Number(1)), "number", "Number" ); + equal( jQuery.type(""), "string", "String" ); + equal( jQuery.type("a"), "string", "String" ); + equal( jQuery.type(String("a")), "string", "String" ); + equal( jQuery.type({}), "object", "Object" ); + equal( jQuery.type(/foo/), "regexp", "RegExp" ); + equal( jQuery.type(new RegExp("asdf")), "regexp", "RegExp" ); + equal( jQuery.type([1]), "array", "Array" ); + equal( jQuery.type(new Date()), "date", "Date" ); + equal( jQuery.type(new Function("return;")), "function", "Function" ); + equal( jQuery.type(function(){}), "function", "Function" ); + equal( jQuery.type(window), "object", "Window" ); + equal( jQuery.type(document), "object", "Document" ); + equal( jQuery.type(document.body), "object", "Element" ); + equal( jQuery.type(document.createTextNode("foo")), "object", "TextNode" ); + equal( jQuery.type(document.getElementsByTagName("*")), "object", "NodeList" ); +}); + +test("isPlainObject", function() { + expect(15); + + stop(); + + // The use case that we want to match + ok(jQuery.isPlainObject({}), "{}"); + + // Not objects shouldn't be matched + ok(!jQuery.isPlainObject(""), "string"); + ok(!jQuery.isPlainObject(0) && !jQuery.isPlainObject(1), "number"); + ok(!jQuery.isPlainObject(true) && !jQuery.isPlainObject(false), "boolean"); + ok(!jQuery.isPlainObject(null), "null"); + ok(!jQuery.isPlainObject(undefined), "undefined"); + + // Arrays shouldn't be matched + ok(!jQuery.isPlainObject([]), "array"); + + // Instantiated objects shouldn't be matched + ok(!jQuery.isPlainObject(new Date), "new Date"); + + var fn = function(){}; + + // Functions shouldn't be matched + ok(!jQuery.isPlainObject(fn), "fn"); + + // Again, instantiated objects shouldn't be matched + ok(!jQuery.isPlainObject(new fn), "new fn (no methods)"); + + // Makes the function a little more realistic + // (and harder to detect, incidentally) + fn.prototype = {someMethod: function(){}}; + + // Again, instantiated objects shouldn't be matched + ok(!jQuery.isPlainObject(new fn), "new fn"); + + // DOM Element + ok(!jQuery.isPlainObject(document.createElement("div")), "DOM Element"); + + // Window + ok(!jQuery.isPlainObject(window), "window"); + + try { + jQuery.isPlainObject( window.location ); + ok( true, "Does not throw exceptions on host objects"); + } catch ( e ) { + ok( false, "Does not throw exceptions on host objects -- FAIL"); + } + + try { + var iframe = document.createElement("iframe"); + document.body.appendChild(iframe); + + window.iframeDone = function(otherObject){ + // Objects from other windows should be matched + ok(jQuery.isPlainObject(new otherObject), "new otherObject"); + document.body.removeChild( iframe ); + start(); + }; + + var doc = iframe.contentDocument || iframe.contentWindow.document; + doc.open(); + doc.write("<body onload='window.parent.iframeDone(Object);'>"); + doc.close(); + } catch(e) { + document.body.removeChild( iframe ); + + ok(true, "new otherObject - iframes not supported"); + start(); + } +}); + +test("isFunction", function() { + expect(19); + + // Make sure that false values return false + ok( !jQuery.isFunction(), "No Value" ); + ok( !jQuery.isFunction( null ), "null Value" ); + ok( !jQuery.isFunction( undefined ), "undefined Value" ); + ok( !jQuery.isFunction( "" ), "Empty String Value" ); + ok( !jQuery.isFunction( 0 ), "0 Value" ); + + // Check built-ins + // Safari uses "(Internal Function)" + ok( jQuery.isFunction(String), "String Function("+String+")" ); + ok( jQuery.isFunction(Array), "Array Function("+Array+")" ); + ok( jQuery.isFunction(Object), "Object Function("+Object+")" ); + ok( jQuery.isFunction(Function), "Function Function("+Function+")" ); + + // When stringified, this could be misinterpreted + var mystr = "function"; + ok( !jQuery.isFunction(mystr), "Function String" ); + + // When stringified, this could be misinterpreted + var myarr = [ "function" ]; + ok( !jQuery.isFunction(myarr), "Function Array" ); + + // When stringified, this could be misinterpreted + var myfunction = { "function": "test" }; + ok( !jQuery.isFunction(myfunction), "Function Object" ); + + // Make sure normal functions still work + var fn = function(){}; + ok( jQuery.isFunction(fn), "Normal Function" ); + + var obj = document.createElement("object"); + + // Firefox says this is a function + ok( !jQuery.isFunction(obj), "Object Element" ); + + // IE says this is an object + // Since 1.3, this isn't supported (#2968) + //ok( jQuery.isFunction(obj.getAttribute), "getAttribute Function" ); + + var nodes = document.body.childNodes; + + // Safari says this is a function + ok( !jQuery.isFunction(nodes), "childNodes Property" ); + + var first = document.body.firstChild; + + // Normal elements are reported ok everywhere + ok( !jQuery.isFunction(first), "A normal DOM Element" ); + + var input = document.createElement("input"); + input.type = "text"; + document.body.appendChild( input ); + + // IE says this is an object + // Since 1.3, this isn't supported (#2968) + //ok( jQuery.isFunction(input.focus), "A default function property" ); + + document.body.removeChild( input ); + + var a = document.createElement("a"); + a.href = "some-function"; + document.body.appendChild( a ); + + // This serializes with the word 'function' in it + ok( !jQuery.isFunction(a), "Anchor Element" ); + + document.body.removeChild( a ); + + // Recursive function calls have lengths and array-like properties + function callme(callback){ + function fn(response){ + callback(response); + } + + ok( jQuery.isFunction(fn), "Recursive Function Call" ); + + fn({ some: "data" }); + }; + + callme(function(){ + callme(function(){}); + }); +}); + +test( "isNumeric", function() { + expect( 37 ); + + var t = jQuery.isNumeric, + Traditionalists = function(n) { + this.value = n; + this.toString = function(){ + return String(this.value); + }; + }, + answer = new Traditionalists( "42" ), + rong = new Traditionalists( "Devo" ); + + ok( t("-10"), "Negative integer string"); + ok( t("0"), "Zero string"); + ok( t("5"), "Positive integer string"); + ok( t(-16), "Negative integer number"); + ok( t(0), "Zero integer number"); + ok( t(32), "Positive integer number"); + ok( t("040"), "Octal integer literal string"); + ok( t(0144), "Octal integer literal"); + ok( t("0xFF"), "Hexadecimal integer literal string"); + ok( t(0xFFF), "Hexadecimal integer literal"); + ok( t("-1.6"), "Negative floating point string"); + ok( t("4.536"), "Positive floating point string"); + ok( t(-2.6), "Negative floating point number"); + ok( t(3.1415), "Positive floating point number"); + ok( t(8e5), "Exponential notation"); + ok( t("123e-2"), "Exponential notation string"); + ok( t(answer), "Custom .toString returning number"); + equal( t(""), false, "Empty string"); + equal( t(" "), false, "Whitespace characters string"); + equal( t("\t\t"), false, "Tab characters string"); + equal( t("abcdefghijklm1234567890"), false, "Alphanumeric character string"); + equal( t("xabcdefx"), false, "Non-numeric character string"); + equal( t(true), false, "Boolean true literal"); + equal( t(false), false, "Boolean false literal"); + equal( t("bcfed5.2"), false, "Number with preceding non-numeric characters"); + equal( t("7.2acdgs"), false, "Number with trailling non-numeric characters"); + equal( t(undefined), false, "Undefined value"); + equal( t(null), false, "Null value"); + equal( t(NaN), false, "NaN value"); + equal( t(Infinity), false, "Infinity primitive"); + equal( t(Number.POSITIVE_INFINITY), false, "Positive Infinity"); + equal( t(Number.NEGATIVE_INFINITY), false, "Negative Infinity"); + equal( t(rong), false, "Custom .toString returning non-number"); + equal( t({}), false, "Empty object"); + equal( t(function(){} ), false, "Instance of a function"); + equal( t( new Date ), false, "Instance of a Date"); + equal( t(function(){} ), false, "Instance of a function"); +}); + +test("isXMLDoc - HTML", function() { + expect(4); + + ok( !jQuery.isXMLDoc( document ), "HTML document" ); + ok( !jQuery.isXMLDoc( document.documentElement ), "HTML documentElement" ); + ok( !jQuery.isXMLDoc( document.body ), "HTML Body Element" ); + + var iframe = document.createElement("iframe"); + document.body.appendChild( iframe ); + + try { + var body = jQuery(iframe).contents()[0]; + + try { + ok( !jQuery.isXMLDoc( body ), "Iframe body element" ); + } catch(e) { + ok( false, "Iframe body element exception" ); + } + + } catch(e) { + ok( true, "Iframe body element - iframe not working correctly" ); + } + + document.body.removeChild( iframe ); +}); + +test("XSS via location.hash", function() { + expect(1); + + stop(); + jQuery._check9521 = function(x){ + ok( x, "script called from #id-like selector with inline handler" ); + jQuery("#check9521").remove(); + delete jQuery._check9521; + start(); + }; + try { + // This throws an error because it's processed like an id + jQuery( '#<img id="check9521" src="no-such-.gif" onerror="jQuery._check9521(false)">' ).appendTo("#qunit-fixture"); + } catch (err) { + jQuery._check9521(true); + }; +}); + +if ( !isLocal ) { +test("isXMLDoc - XML", function() { + expect(3); + stop(); + jQuery.get("data/dashboard.xml", function(xml) { + ok( jQuery.isXMLDoc( xml ), "XML document" ); + ok( jQuery.isXMLDoc( xml.documentElement ), "XML documentElement" ); + ok( jQuery.isXMLDoc( jQuery("tab", xml)[0] ), "XML Tab Element" ); + start(); + }); +}); +} + +test("isWindow", function() { + expect( 12 ); + + ok( jQuery.isWindow(window), "window" ); + ok( !jQuery.isWindow(), "empty" ); + ok( !jQuery.isWindow(null), "null" ); + ok( !jQuery.isWindow(undefined), "undefined" ); + ok( !jQuery.isWindow(document), "document" ); + ok( !jQuery.isWindow(document.documentElement), "documentElement" ); + ok( !jQuery.isWindow(""), "string" ); + ok( !jQuery.isWindow(1), "number" ); + ok( !jQuery.isWindow(true), "boolean" ); + ok( !jQuery.isWindow({}), "object" ); + // HMMM + // ok( !jQuery.isWindow({ setInterval: function(){} }), "fake window" ); + ok( !jQuery.isWindow(/window/), "regexp" ); + ok( !jQuery.isWindow(function(){}), "function" ); +}); + +test("jQuery('html')", function() { + expect(18); + + QUnit.reset(); + jQuery.foo = false; + var s = jQuery("<script>jQuery.foo='test';</script>")[0]; + ok( s, "Creating a script" ); + ok( !jQuery.foo, "Make sure the script wasn't executed prematurely" ); + jQuery("body").append("<script>jQuery.foo='test';</script>"); + ok( jQuery.foo, "Executing a scripts contents in the right context" ); + + // Test multi-line HTML + var div = jQuery("<div>\r\nsome text\n<p>some p</p>\nmore text\r\n</div>")[0]; + equal( div.nodeName.toUpperCase(), "DIV", "Make sure we're getting a div." ); + equal( div.firstChild.nodeType, 3, "Text node." ); + equal( div.lastChild.nodeType, 3, "Text node." ); + equal( div.childNodes[1].nodeType, 1, "Paragraph." ); + equal( div.childNodes[1].firstChild.nodeType, 3, "Paragraph text." ); + + QUnit.reset(); + ok( jQuery("<link rel='stylesheet'/>")[0], "Creating a link" ); + + ok( !jQuery("<script/>")[0].parentNode, "Create a script" ); + + ok( jQuery("<input/>").attr("type", "hidden"), "Create an input and set the type." ); + + var j = jQuery("<span>hi</span> there <!-- mon ami -->"); + ok( j.length >= 2, "Check node,textnode,comment creation (some browsers delete comments)" ); + + ok( !jQuery("<option>test</option>")[0].selected, "Make sure that options are auto-selected #2050" ); + + ok( jQuery("<div></div>")[0], "Create a div with closing tag." ); + ok( jQuery("<table></table>")[0], "Create a table with closing tag." ); + + // Test very large html string #7990 + var i; + var li = "<li>very large html string</li>"; + var html = ["<ul>"]; + for ( i = 0; i < 50000; i += 1 ) { + html.push(li); + } + html.push("</ul>"); + html = jQuery(html.join(""))[0]; + equal( html.nodeName.toUpperCase(), "UL"); + equal( html.firstChild.nodeName.toUpperCase(), "LI"); + equal( html.childNodes.length, 50000 ); +}); + +test("jQuery('html', context)", function() { + expect(1); + + var $div = jQuery("<div/>")[0]; + var $span = jQuery("<span/>", $div); + equal($span.length, 1, "Verify a span created with a div context works, #1763"); +}); + +if ( !isLocal ) { +test("jQuery(selector, xml).text(str) - Loaded via XML document", function() { + expect(2); + stop(); + jQuery.get("data/dashboard.xml", function(xml) { + // tests for #1419 where IE was a problem + var tab = jQuery("tab", xml).eq(0); + equal( tab.text(), "blabla", "Verify initial text correct" ); + tab.text("newtext"); + equal( tab.text(), "newtext", "Verify new text correct" ); + start(); + }); +}); +} + +test("end()", function() { + expect(3); + equal( "Yahoo", jQuery("#yahoo").parent().end().text(), "Check for end" ); + ok( jQuery("#yahoo").end(), "Check for end with nothing to end" ); + + var x = jQuery("#yahoo"); + x.parent(); + equal( "Yahoo", jQuery("#yahoo").text(), "Check for non-destructive behaviour" ); +}); + +test("length", function() { + expect(1); + equal( jQuery("#qunit-fixture p").length, 6, "Get Number of Elements Found" ); +}); + +test("size()", function() { + expect(1); + equal( jQuery("#qunit-fixture p").size(), 6, "Get Number of Elements Found" ); +}); + +test("get()", function() { + expect(1); + deepEqual( jQuery("#qunit-fixture p").get(), q("firstp","ap","sndp","en","sap","first"), "Get All Elements" ); +}); + +test("toArray()", function() { + expect(1); + deepEqual( jQuery("#qunit-fixture p").toArray(), + q("firstp","ap","sndp","en","sap","first"), + "Convert jQuery object to an Array" ) +}) + +test("inArray()", function() { + expect(19); + + var selections = { + p: q("firstp", "sap", "ap", "first"), + em: q("siblingnext", "siblingfirst"), + div: q("qunit-testrunner-toolbar", "nothiddendiv", "nothiddendivchild", "foo"), + a: q("mark", "groups", "google", "simon1"), + empty: [] + }, + tests = { + p: { elem: jQuery("#ap")[0], index: 2 }, + em: { elem: jQuery("#siblingfirst")[0], index: 1 }, + div: { elem: jQuery("#nothiddendiv")[0], index: 1 }, + a: { elem: jQuery("#simon1")[0], index: 3 } + }, + falseTests = { + p: jQuery("#liveSpan1")[0], + em: jQuery("#nothiddendiv")[0], + empty: "" + }; + + jQuery.each( tests, function( key, obj ) { + equal( jQuery.inArray( obj.elem, selections[ key ] ), obj.index, "elem is in the array of selections of its tag" ); + // Third argument (fromIndex) + equal( !!~jQuery.inArray( obj.elem, selections[ key ], 5 ), false, "elem is NOT in the array of selections given a starting index greater than its position" ); + equal( !!~jQuery.inArray( obj.elem, selections[ key ], 1 ), true, "elem is in the array of selections given a starting index less than or equal to its position" ); + equal( !!~jQuery.inArray( obj.elem, selections[ key ], -3 ), true, "elem is in the array of selections given a negative index" ); + }); + + jQuery.each( falseTests, function( key, elem ) { + equal( !!~jQuery.inArray( elem, selections[ key ] ), false, "elem is NOT in the array of selections" ); + }); + +}); + +test("get(Number)", function() { + expect(2); + equal( 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" ); +}); + +test("get(-Number)",function() { + expect(2); + equal( jQuery("p").get(-1), document.getElementById("first"), "Get a single element with negative index" ); + strictEqual( jQuery("#firstp").get(-2), undefined, "Try get with index negative index larger then elements count" ); +}) + +test("each(Function)", function() { + expect(1); + var div = jQuery("div"); + div.each(function(){this.foo = "zoo";}); + var pass = true; + for ( var i = 0; i < div.size(); i++ ) { + if ( div.get(i).foo != "zoo" ) pass = false; + } + ok( pass, "Execute a function, Relative" ); +}); + +test("slice()", function() { + expect(7); + + var $links = jQuery("#ap a"); + + deepEqual( $links.slice(1,2).get(), q("groups"), "slice(1,2)" ); + deepEqual( $links.slice(1).get(), q("groups", "anchor1", "mark"), "slice(1)" ); + deepEqual( $links.slice(0,3).get(), q("google", "groups", "anchor1"), "slice(0,3)" ); + deepEqual( $links.slice(-1).get(), q("mark"), "slice(-1)" ); + + deepEqual( $links.eq(1).get(), q("groups"), "eq(1)" ); + deepEqual( $links.eq("2").get(), q("anchor1"), "eq('2')" ); + deepEqual( $links.eq(-1).get(), q("mark"), "eq(-1)" ); +}); + +test("first()/last()", function() { + expect(4); + + var $links = jQuery("#ap a"), $none = jQuery("asdf"); + + deepEqual( $links.first().get(), q("google"), "first()" ); + deepEqual( $links.last().get(), q("mark"), "last()" ); + + deepEqual( $none.first().get(), [], "first() none" ); + deepEqual( $none.last().get(), [], "last() none" ); +}); + +test("map()", function() { + expect(8); + + deepEqual( + jQuery("#ap").map(function(){ + return jQuery(this).find("a").get(); + }).get(), + q("google", "groups", "anchor1", "mark"), + "Array Map" + ); + + deepEqual( + jQuery("#ap > a").map(function(){ + return this.parentNode; + }).get(), + q("ap","ap","ap"), + "Single Map" + ); + + //for #2616 + var keys = jQuery.map( {a:1,b:2}, function( v, k ){ + return k; + }); + equal( keys.join(""), "ab", "Map the keys from a hash to an array" ); + + var values = jQuery.map( {a:1,b:2}, function( v, k ){ + return v; + }); + equal( values.join(""), "12", "Map the values from a hash to an array" ); + + // object with length prop + var values = jQuery.map( {a:1,b:2, length:3}, function( v, k ){ + return v; + }); + equal( values.join(""), "123", "Map the values from a hash with a length property to an array" ); + + var scripts = document.getElementsByTagName("script"); + var mapped = jQuery.map( scripts, function( v, k ){ + return v; + }); + equal( mapped.length, scripts.length, "Map an array(-like) to a hash" ); + + var nonsense = document.getElementsByTagName("asdf"); + var mapped = jQuery.map( nonsense, function( v, k ){ + return v; + }); + equal( mapped.length, nonsense.length, "Map an empty array(-like) to a hash" ); + + var flat = jQuery.map( Array(4), function( v, k ){ + return k % 2 ? k : [k,k,k];//try mixing array and regular returns + }); + equal( flat.join(""), "00012223", "try the new flatten technique(#2616)" ); +}); + +test("jQuery.merge()", function() { + expect(8); + + var parse = jQuery.merge; + + deepEqual( parse([],[]), [], "Empty arrays" ); + + deepEqual( parse([1],[2]), [1,2], "Basic" ); + deepEqual( parse([1,2],[3,4]), [1,2,3,4], "Basic" ); + + deepEqual( parse([1,2],[]), [1,2], "Second empty" ); + deepEqual( parse([],[1,2]), [1,2], "First empty" ); + + // Fixed at [5998], #3641 + deepEqual( parse([-2,-1], [0,1,2]), [-2,-1,0,1,2], "Second array including a zero (falsy)"); + + // After fixing #5527 + deepEqual( parse([], [null, undefined]), [null, undefined], "Second array including null and undefined values"); + deepEqual( parse({length:0}, [1,2]), {length:2, 0:1, 1:2}, "First array like"); +}); + +test("jQuery.extend(Object, Object)", function() { + expect(28); + + var settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" }, + options = { xnumber2: 1, xstring2: "x", xxx: "newstring" }, + optionsCopy = { xnumber2: 1, xstring2: "x", xxx: "newstring" }, + merged = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "x", xxx: "newstring" }, + deep1 = { foo: { bar: true } }, + deep1copy = { foo: { bar: true } }, + deep2 = { foo: { baz: true }, foo2: document }, + deep2copy = { foo: { baz: true }, foo2: document }, + deepmerged = { foo: { bar: true, baz: true }, foo2: document }, + arr = [1, 2, 3], + nestedarray = { arr: arr }; + + jQuery.extend(settings, options); + deepEqual( settings, merged, "Check if extended: settings must be extended" ); + deepEqual( options, optionsCopy, "Check if not modified: options must not be modified" ); + + jQuery.extend(settings, null, options); + deepEqual( settings, merged, "Check if extended: settings must be extended" ); + deepEqual( options, optionsCopy, "Check if not modified: options must not be modified" ); + + jQuery.extend(true, deep1, deep2); + deepEqual( deep1.foo, deepmerged.foo, "Check if foo: settings must be extended" ); + deepEqual( deep2.foo, deep2copy.foo, "Check if not deep2: options must not be modified" ); + equal( deep1.foo2, document, "Make sure that a deep clone was not attempted on the document" ); + + ok( jQuery.extend(true, {}, nestedarray).arr !== arr, "Deep extend of object must clone child array" ); + + // #5991 + ok( jQuery.isArray( jQuery.extend(true, { arr: {} }, nestedarray).arr ), "Cloned array heve to be an Array" ); + ok( jQuery.isPlainObject( jQuery.extend(true, { arr: arr }, { arr: {} }).arr ), "Cloned object heve to be an plain object" ); + + var empty = {}; + var optionsWithLength = { foo: { length: -1 } }; + jQuery.extend(true, empty, optionsWithLength); + deepEqual( empty.foo, optionsWithLength.foo, "The length property must copy correctly" ); + + empty = {}; + var optionsWithDate = { foo: { date: new Date } }; + jQuery.extend(true, empty, optionsWithDate); + deepEqual( empty.foo, optionsWithDate.foo, "Dates copy correctly" ); + + var myKlass = function() {}; + var customObject = new myKlass(); + var optionsWithCustomObject = { foo: { date: customObject } }; + empty = {}; + jQuery.extend(true, empty, optionsWithCustomObject); + ok( empty.foo && empty.foo.date === customObject, "Custom objects copy correctly (no methods)" ); + + // Makes the class a little more realistic + myKlass.prototype = { someMethod: function(){} }; + empty = {}; + jQuery.extend(true, empty, optionsWithCustomObject); + ok( empty.foo && empty.foo.date === customObject, "Custom objects copy correctly" ); + + var ret = jQuery.extend(true, { foo: 4 }, { foo: new Number(5) } ); + ok( ret.foo == 5, "Wrapped numbers copy correctly" ); + + var nullUndef; + nullUndef = jQuery.extend({}, options, { xnumber2: null }); + ok( nullUndef.xnumber2 === null, "Check to make sure null values are copied"); + + nullUndef = jQuery.extend({}, options, { xnumber2: undefined }); + ok( nullUndef.xnumber2 === options.xnumber2, "Check to make sure undefined values are not copied"); + + nullUndef = jQuery.extend({}, options, { xnumber0: null }); + ok( nullUndef.xnumber0 === null, "Check to make sure null values are inserted"); + + var target = {}; + var recursive = { foo:target, bar:5 }; + jQuery.extend(true, target, recursive); + deepEqual( target, { bar:5 }, "Check to make sure a recursive obj doesn't go never-ending loop by not copying it over" ); + + var ret = jQuery.extend(true, { foo: [] }, { foo: [0] } ); // 1907 + equal( ret.foo.length, 1, "Check to make sure a value with coersion 'false' copies over when necessary to fix #1907" ); + + var ret = jQuery.extend(true, { foo: "1,2,3" }, { foo: [1, 2, 3] } ); + ok( typeof ret.foo != "string", "Check to make sure values equal with coersion (but not actually equal) overwrite correctly" ); + + var ret = jQuery.extend(true, { foo:"bar" }, { foo:null } ); + ok( typeof ret.foo !== "undefined", "Make sure a null value doesn't crash with deep extend, for #1908" ); + + var obj = { foo:null }; + jQuery.extend(true, obj, { foo:"notnull" } ); + equal( obj.foo, "notnull", "Make sure a null value can be overwritten" ); + + function func() {} + jQuery.extend(func, { key: "value" } ); + equal( func.key, "value", "Verify a function can be extended" ); + + var defaults = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" }, + defaultsCopy = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" }, + options1 = { xnumber2: 1, xstring2: "x" }, + options1Copy = { xnumber2: 1, xstring2: "x" }, + options2 = { xstring2: "xx", xxx: "newstringx" }, + options2Copy = { xstring2: "xx", xxx: "newstringx" }, + merged2 = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "xx", xxx: "newstringx" }; + + var settings = jQuery.extend({}, defaults, options1, options2); + deepEqual( settings, merged2, "Check if extended: settings must be extended" ); + deepEqual( defaults, defaultsCopy, "Check if not modified: options1 must not be modified" ); + deepEqual( options1, options1Copy, "Check if not modified: options1 must not be modified" ); + deepEqual( options2, options2Copy, "Check if not modified: options2 must not be modified" ); +}); + +test("jQuery.each(Object,Function)", function() { + expect(14); + jQuery.each( [0,1,2], function(i, n){ + equal( i, n, "Check array iteration" ); + }); + + jQuery.each( [5,6,7], function(i, n){ + equal( i, n - 5, "Check array iteration" ); + }); + + jQuery.each( { name: "name", lang: "lang" }, function(i, n){ + equal( i, n, "Check object iteration" ); + }); + + var total = 0; + jQuery.each([1,2,3], function(i,v){ total += v; }); + equal( total, 6, "Looping over an array" ); + total = 0; + jQuery.each([1,2,3], function(i,v){ total += v; if ( i == 1 ) return false; }); + equal( total, 3, "Looping over an array, with break" ); + total = 0; + jQuery.each({"a":1,"b":2,"c":3}, function(i,v){ total += v; }); + equal( total, 6, "Looping over an object" ); + total = 0; + jQuery.each({"a":3,"b":3,"c":3}, function(i,v){ total += v; return false; }); + equal( total, 3, "Looping over an object, with break" ); + + var f = function(){}; + f.foo = "bar"; + jQuery.each(f, function(i){ + f[i] = "baz"; + }); + equal( "baz", f.foo, "Loop over a function" ); + + var stylesheet_count = 0; + jQuery.each(document.styleSheets, function(i){ + stylesheet_count++; + }); + //html5shiv may add 1-2 stylesheets + ok(stylesheet_count > 1 && stylesheet_count < 5, "should not throw an error in IE while looping over document.styleSheets and return proper amount"); + +}); + +test("jQuery.makeArray", function(){ + expect(17); + + equal( jQuery.makeArray(jQuery("html>*"))[0].nodeName.toUpperCase(), "HEAD", "Pass makeArray a jQuery object" ); + + equal( jQuery.makeArray(document.getElementsByName("PWD")).slice(0,1)[0].name, "PWD", "Pass makeArray a nodelist" ); + + equal( (function(){ return jQuery.makeArray(arguments); })(1,2).join(""), "12", "Pass makeArray an arguments array" ); + + equal( jQuery.makeArray([1,2,3]).join(""), "123", "Pass makeArray a real array" ); + + equal( jQuery.makeArray().length, 0, "Pass nothing to makeArray and expect an empty array" ); + + equal( jQuery.makeArray( 0 )[0], 0 , "Pass makeArray a number" ); + + equal( jQuery.makeArray( "foo" )[0], "foo", "Pass makeArray a string" ); + + equal( jQuery.makeArray( true )[0].constructor, Boolean, "Pass makeArray a boolean" ); + + equal( jQuery.makeArray( document.createElement("div") )[0].nodeName.toUpperCase(), "DIV", "Pass makeArray a single node" ); + + equal( jQuery.makeArray( {length:2, 0:"a", 1:"b"} ).join(""), "ab", "Pass makeArray an array like map (with length)" ); + + ok( !!jQuery.makeArray( document.documentElement.childNodes ).slice(0,1)[0].nodeName, "Pass makeArray a childNodes array" ); + + // function, is tricky as it has length + equal( jQuery.makeArray( function(){ return 1;} )[0](), 1, "Pass makeArray a function" ); + + //window, also has length + equal( jQuery.makeArray(window)[0], window, "Pass makeArray the window" ); + + equal( jQuery.makeArray(/a/)[0].constructor, RegExp, "Pass makeArray a regex" ); + + ok( jQuery.makeArray(document.getElementById("form")).length >= 13, "Pass makeArray a form (treat as elements)" ); + + // For #5610 + deepEqual( jQuery.makeArray({length: "0"}), [], "Make sure object is coerced properly."); + deepEqual( jQuery.makeArray({length: "5"}), [], "Make sure object is coerced properly."); +}); + +test("jQuery.inArray", function(){ + expect(3); + + equal( jQuery.inArray( 0, false ), -1 , "Search in 'false' as array returns -1 and doesn't throw exception" ); + + equal( jQuery.inArray( 0, null ), -1 , "Search in 'null' as array returns -1 and doesn't throw exception" ); + + equal( jQuery.inArray( 0, undefined ), -1 , "Search in 'undefined' as array returns -1 and doesn't throw exception" ); +}); + +test("jQuery.isEmptyObject", function(){ + expect(2); + + equal(true, jQuery.isEmptyObject({}), "isEmptyObject on empty object literal" ); + equal(false, jQuery.isEmptyObject({a:1}), "isEmptyObject on non-empty object literal" ); + + // What about this ? + // equal(true, jQuery.isEmptyObject(null), "isEmptyObject on null" ); +}); + +test("jQuery.proxy", function(){ + expect(7); + + var test = function(){ equal( this, thisObject, "Make sure that scope is set properly." ); }; + var thisObject = { foo: "bar", method: test }; + + // Make sure normal works + test.call( thisObject ); + + // Basic scoping + jQuery.proxy( test, thisObject )(); + + // Another take on it + jQuery.proxy( thisObject, "method" )(); + + // Make sure it doesn't freak out + equal( jQuery.proxy( null, thisObject ), undefined, "Make sure no function was returned." ); + + // Partial application + var test2 = function( a ){ equal( a, "pre-applied", "Ensure arguments can be pre-applied." ); }; + jQuery.proxy( test2, null, "pre-applied" )(); + + // Partial application w/ normal arguments + var test3 = function( a, b ){ equal( b, "normal", "Ensure arguments can be pre-applied and passed as usual." ); }; + jQuery.proxy( test3, null, "pre-applied" )( "normal" ); + + // Test old syntax + var test4 = { meth: function( a ){ equal( a, "boom", "Ensure old syntax works." ); } }; + jQuery.proxy( test4, "meth" )( "boom" ); +}); + +test("jQuery.parseJSON", function(){ + expect(8); + + equal( jQuery.parseJSON(), null, "Nothing in, null out." ); + equal( jQuery.parseJSON( null ), null, "Nothing in, null out." ); + equal( jQuery.parseJSON( "" ), null, "Nothing in, null out." ); + + deepEqual( jQuery.parseJSON("{}"), {}, "Plain object parsing." ); + deepEqual( jQuery.parseJSON("{\"test\":1}"), {"test":1}, "Plain object parsing." ); + + deepEqual( jQuery.parseJSON("\n{\"test\":1}"), {"test":1}, "Make sure leading whitespaces are handled." ); + + try { + jQuery.parseJSON("{a:1}"); + ok( false, "Test malformed JSON string." ); + } catch( e ) { + ok( true, "Test malformed JSON string." ); + } + + try { + jQuery.parseJSON("{'a':1}"); + ok( false, "Test malformed JSON string." ); + } catch( e ) { + ok( true, "Test malformed JSON string." ); + } +}); + +test("jQuery.parseXML", 4, function(){ + var xml, tmp; + try { + xml = jQuery.parseXML( "<p>A <b>well-formed</b> xml string</p>" ); + tmp = xml.getElementsByTagName( "p" )[ 0 ]; + ok( !!tmp, "<p> present in document" ); + tmp = tmp.getElementsByTagName( "b" )[ 0 ]; + ok( !!tmp, "<b> present in document" ); + strictEqual( tmp.childNodes[ 0 ].nodeValue, "well-formed", "<b> text is as expected" ); + } catch (e) { + strictEqual( e, undefined, "unexpected error" ); + } + try { + xml = jQuery.parseXML( "<p>Not a <<b>well-formed</b> xml string</p>" ); + ok( false, "invalid xml not detected" ); + } catch( e ) { + strictEqual( e.message, "Invalid XML: <p>Not a <<b>well-formed</b> xml string</p>", "invalid xml detected" ); + } +}); + +test("jQuery.sub() - Static Methods", function(){ + expect(18); + var Subclass = jQuery.sub(); + Subclass.extend({ + topLevelMethod: function() {return this.debug;}, + debug: false, + config: { + locale: "en_US" + }, + setup: function(config) { + this.extend(true, this.config, config); + } + }); + Subclass.fn.extend({subClassMethod: function() { return this;}}); + + //Test Simple Subclass + ok(Subclass.topLevelMethod() === false, "Subclass.topLevelMethod thought debug was true"); + ok(Subclass.config.locale == "en_US", Subclass.config.locale + " is wrong!"); + deepEqual(Subclass.config.test, undefined, "Subclass.config.test is set incorrectly"); + equal(jQuery.ajax, Subclass.ajax, "The subclass failed to get all top level methods"); + + //Create a SubSubclass + var SubSubclass = Subclass.sub(); + + //Make Sure the SubSubclass inherited properly + ok(SubSubclass.topLevelMethod() === false, "SubSubclass.topLevelMethod thought debug was true"); + ok(SubSubclass.config.locale == "en_US", SubSubclass.config.locale + " is wrong!"); + deepEqual(SubSubclass.config.test, undefined, "SubSubclass.config.test is set incorrectly"); + equal(jQuery.ajax, SubSubclass.ajax, "The subsubclass failed to get all top level methods"); + + //Modify The Subclass and test the Modifications + SubSubclass.fn.extend({subSubClassMethod: function() { return this;}}); + SubSubclass.setup({locale: "es_MX", test: "worked"}); + SubSubclass.debug = true; + SubSubclass.ajax = function() {return false;}; + ok(SubSubclass.topLevelMethod(), "SubSubclass.topLevelMethod thought debug was false"); + deepEqual(SubSubclass(document).subClassMethod, Subclass.fn.subClassMethod, "Methods Differ!"); + ok(SubSubclass.config.locale == "es_MX", SubSubclass.config.locale + " is wrong!"); + ok(SubSubclass.config.test == "worked", "SubSubclass.config.test is set incorrectly"); + notEqual(jQuery.ajax, SubSubclass.ajax, "The subsubclass failed to get all top level methods"); + + //This shows that the modifications to the SubSubClass did not bubble back up to it's superclass + ok(Subclass.topLevelMethod() === false, "Subclass.topLevelMethod thought debug was true"); + ok(Subclass.config.locale == "en_US", Subclass.config.locale + " is wrong!"); + deepEqual(Subclass.config.test, undefined, "Subclass.config.test is set incorrectly"); + deepEqual(Subclass(document).subSubClassMethod, undefined, "subSubClassMethod set incorrectly"); + equal(jQuery.ajax, Subclass.ajax, "The subclass failed to get all top level methods"); +}); + +test("jQuery.sub() - .fn Methods", function(){ + expect(378); + + var Subclass = jQuery.sub(), + SubclassSubclass = Subclass.sub(), + jQueryDocument = jQuery(document), + selectors, contexts, methods, method, arg, description; + + jQueryDocument.toString = function(){ return "jQueryDocument"; }; + + Subclass.fn.subclassMethod = function(){}; + SubclassSubclass.fn.subclassSubclassMethod = function(){}; + + selectors = [ + "body", + "html, body", + "<div></div>" + ]; + + methods = [ // all methods that return a new jQuery instance + ["eq", 1], + ["add", document], + ["end"], + ["has"], + ["closest", "div"], + ["filter", document], + ["find", "div"] + ]; + + contexts = [undefined, document, jQueryDocument]; + + jQuery.each(selectors, function(i, selector){ + + jQuery.each(methods, function(){ + method = this[0]; + arg = this[1]; + + jQuery.each(contexts, function(i, context){ + + description = "(\""+selector+"\", "+context+")."+method+"("+(arg||"")+")"; + + deepEqual( + jQuery(selector, context)[method](arg).subclassMethod, undefined, + "jQuery"+description+" doesn't have Subclass methods" + ); + deepEqual( + jQuery(selector, context)[method](arg).subclassSubclassMethod, undefined, + "jQuery"+description+" doesn't have SubclassSubclass methods" + ); + deepEqual( + Subclass(selector, context)[method](arg).subclassMethod, Subclass.fn.subclassMethod, + "Subclass"+description+" has Subclass methods" + ); + deepEqual( + Subclass(selector, context)[method](arg).subclassSubclassMethod, undefined, + "Subclass"+description+" doesn't have SubclassSubclass methods" + ); + deepEqual( + SubclassSubclass(selector, context)[method](arg).subclassMethod, Subclass.fn.subclassMethod, + "SubclassSubclass"+description+" has Subclass methods" + ); + deepEqual( + SubclassSubclass(selector, context)[method](arg).subclassSubclassMethod, SubclassSubclass.fn.subclassSubclassMethod, + "SubclassSubclass"+description+" has SubclassSubclass methods" + ); + + }); + }); + }); + +}); + +test("jQuery.camelCase()", function() { + + var tests = { + "foo-bar": "fooBar", + "foo-bar-baz": "fooBarBaz", + "girl-u-want": "girlUWant", + "the-4th-dimension": "the4thDimension", + "-o-tannenbaum": "OTannenbaum", + "-moz-illa": "MozIlla", + "-ms-take": "msTake" + }; + + expect(7); + + jQuery.each( tests, function( key, val ) { + equal( jQuery.camelCase( key ), val, "Converts: " + key + " => " + val ); + }); +}); diff --git a/npm_assets/node_modules/html5shiv/test/jquery-1.7.1/unit/manipulation.js b/npm_assets/node_modules/html5shiv/test/jquery-1.7.1/unit/manipulation.js new file mode 100644 index 0000000..6b4a9e0 --- /dev/null +++ b/npm_assets/node_modules/html5shiv/test/jquery-1.7.1/unit/manipulation.js @@ -0,0 +1,1701 @@ +module("manipulation", { teardown: moduleTeardown }); + +// Ensure that an extended Array prototype doesn't break jQuery +Array.prototype.arrayProtoFn = function(arg) { throw("arrayProtoFn should not be called"); }; + +var bareObj = function(value) { return value; }; +var functionReturningObj = function(value) { return (function() { return value; }); }; + +test("text()", function() { + expect(3); + var expected = "This link has class=\"blog\": Simon Willison's Weblog"; + equal( jQuery("#sap").text(), expected, "Check for merged text of more then one element." ); + + // Check serialization of text values + equal( jQuery(document.createTextNode("foo")).text(), "foo", "Text node was retreived from .text()." ); + notEqual( jQuery(document).text(), "", "Retrieving text for the document retrieves all text (#10724)."); +}); + +var testText = function(valueObj) { + expect(4); + var val = valueObj("<div><b>Hello</b> cruel world!</div>"); + equal( jQuery("#foo").text(val)[0].innerHTML.replace(/>/g, ">"), "<div><b>Hello</b> cruel world!</div>", "Check escaped text" ); + + // using contents will get comments regular, text, and comment nodes + var j = jQuery("#nonnodes").contents(); + j.text(valueObj("hi!")); + equal( jQuery(j[0]).text(), "hi!", "Check node,textnode,comment with text()" ); + equal( j[1].nodeValue, " there ", "Check node,textnode,comment with text()" ); + + // Blackberry 4.6 doesn't maintain comments in the DOM + equal( jQuery("#nonnodes")[0].childNodes.length < 3 ? 8 : j[2].nodeType, 8, "Check node,textnode,comment with text()" ); +}; + +test("text(String)", function() { + testText(bareObj); +}); + +test("text(Function)", function() { + testText(functionReturningObj); +}); + +test("text(Function) with incoming value", function() { + expect(2); + + var old = "This link has class=\"blog\": Simon Willison's Weblog"; + + jQuery("#sap").text(function(i, val) { + equal( val, old, "Make sure the incoming value is correct." ); + return "foobar"; + }); + + equal( jQuery("#sap").text(), "foobar", "Check for merged text of more then one element." ); + + QUnit.reset(); +}); + +var testWrap = function(val) { + expect(19); + var defaultText = "Try them out:"; + var result = jQuery("#first").wrap(val( "<div class='red'><span></span></div>" )).text(); + equal( defaultText, result, "Check for wrapping of on-the-fly html" ); + ok( jQuery("#first").parent().parent().is(".red"), "Check if wrapper has class 'red'" ); + + QUnit.reset(); + result = jQuery("#first").wrap(val( document.getElementById("empty") )).parent(); + ok( result.is("ol"), "Check for element wrapping" ); + equal( result.text(), defaultText, "Check for element wrapping" ); + + QUnit.reset(); + jQuery("#check1").click(function() { + var checkbox = this; + ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" ); + jQuery(checkbox).wrap(val( "<div id='c1' style='display:none;'></div>" )); + ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" ); + }).click(); + + // using contents will get comments regular, text, and comment nodes + var j = jQuery("#nonnodes").contents(); + j.wrap(val( "<i></i>" )); + + // Blackberry 4.6 doesn't maintain comments in the DOM + equal( jQuery("#nonnodes > i").length, jQuery("#nonnodes")[0].childNodes.length, "Check node,textnode,comment wraps ok" ); + equal( jQuery("#nonnodes > i").text(), j.text(), "Check node,textnode,comment wraps doesn't hurt text" ); + + // Try wrapping a disconnected node + var cacheLength = 0; + for (var i in jQuery.cache) { + cacheLength++; + } + + j = jQuery("<label/>").wrap(val( "<li/>" )); + equal( j[0].nodeName.toUpperCase(), "LABEL", "Element is a label" ); + equal( j[0].parentNode.nodeName.toUpperCase(), "LI", "Element has been wrapped" ); + + for (i in jQuery.cache) { + cacheLength--; + } + equal(cacheLength, 0, "No memory leak in jQuery.cache (bug #7165)"); + + // Wrap an element containing a text node + j = jQuery("<span/>").wrap("<div>test</div>"); + equal( j[0].previousSibling.nodeType, 3, "Make sure the previous node is a text element" ); + equal( j[0].parentNode.nodeName.toUpperCase(), "DIV", "And that we're in the div element." ); + + // Try to wrap an element with multiple elements (should fail) + j = jQuery("<div><span></span></div>").children().wrap("<p></p><div></div>"); + equal( j[0].parentNode.parentNode.childNodes.length, 1, "There should only be one element wrapping." ); + equal( j.length, 1, "There should only be one element (no cloning)." ); + equal( j[0].parentNode.nodeName.toUpperCase(), "P", "The span should be in the paragraph." ); + + // Wrap an element with a jQuery set + j = jQuery("<span/>").wrap(jQuery("<div></div>")); + equal( j[0].parentNode.nodeName.toLowerCase(), "div", "Wrapping works." ); + + // Wrap an element with a jQuery set and event + result = jQuery("<div></div>").click(function(){ + ok(true, "Event triggered."); + + // Remove handlers on detached elements + result.unbind(); + jQuery(this).unbind(); + }); + + j = jQuery("<span/>").wrap(result); + equal( j[0].parentNode.nodeName.toLowerCase(), "div", "Wrapping works." ); + + j.parent().trigger("click"); + + // clean up attached elements + QUnit.reset(); +} + +test("wrap(String|Element)", function() { + testWrap(bareObj); +}); + +test("wrap(Function)", function() { + testWrap(functionReturningObj); +}); + +test("wrap(Function) with index (#10177)", function() { + var expectedIndex = 0, + targets = jQuery("#qunit-fixture p"); + + expect(targets.length); + targets.wrap(function(i) { + equal( i, expectedIndex, "Check if the provided index (" + i + ") is as expected (" + expectedIndex + ")" ); + expectedIndex++; + + return "<div id='wrap_index_'" + i + "'></div>"; + }); +}); + +test("wrap(String) consecutive elements (#10177)", function() { + var targets = jQuery("#qunit-fixture p"); + + expect(targets.length * 2); + targets.wrap("<div class='wrapper'></div>"); + + targets.each(function() { + var $this = jQuery(this); + + ok( $this.parent().is('.wrapper'), "Check each elements parent is correct (.wrapper)" ); + equal( $this.siblings().length, 0, "Each element should be wrapped individually" ); + }); +}); + +var testWrapAll = function(val) { + expect(8); + var prev = jQuery("#firstp")[0].previousSibling; + var p = jQuery("#firstp,#first")[0].parentNode; + + var result = jQuery("#firstp,#first").wrapAll(val( "<div class='red'><div class='tmp'></div></div>" )); + equal( result.parent().length, 1, "Check for wrapping of on-the-fly html" ); + ok( jQuery("#first").parent().parent().is(".red"), "Check if wrapper has class 'red'" ); + ok( jQuery("#firstp").parent().parent().is(".red"), "Check if wrapper has class 'red'" ); + equal( jQuery("#first").parent().parent()[0].previousSibling, prev, "Correct Previous Sibling" ); + equal( jQuery("#first").parent().parent()[0].parentNode, p, "Correct Parent" ); + + QUnit.reset(); + var prev = jQuery("#firstp")[0].previousSibling; + var p = jQuery("#first")[0].parentNode; + var result = jQuery("#firstp,#first").wrapAll(val( document.getElementById("empty") )); + equal( jQuery("#first").parent()[0], jQuery("#firstp").parent()[0], "Same Parent" ); + equal( jQuery("#first").parent()[0].previousSibling, prev, "Correct Previous Sibling" ); + equal( jQuery("#first").parent()[0].parentNode, p, "Correct Parent" ); +} + +test("wrapAll(String|Element)", function() { + testWrapAll(bareObj); +}); + +var testWrapInner = function(val) { + expect(11); + var num = jQuery("#first").children().length; + var result = jQuery("#first").wrapInner(val("<div class='red'><div id='tmp'></div></div>")); + equal( jQuery("#first").children().length, 1, "Only one child" ); + ok( jQuery("#first").children().is(".red"), "Verify Right Element" ); + equal( jQuery("#first").children().children().children().length, num, "Verify Elements Intact" ); + + QUnit.reset(); + var num = jQuery("#first").html("foo<div>test</div><div>test2</div>").children().length; + var result = jQuery("#first").wrapInner(val("<div class='red'><div id='tmp'></div></div>")); + equal( jQuery("#first").children().length, 1, "Only one child" ); + ok( jQuery("#first").children().is(".red"), "Verify Right Element" ); + equal( jQuery("#first").children().children().children().length, num, "Verify Elements Intact" ); + + QUnit.reset(); + var num = jQuery("#first").children().length; + var result = jQuery("#first").wrapInner(val(document.getElementById("empty"))); + equal( jQuery("#first").children().length, 1, "Only one child" ); + ok( jQuery("#first").children().is("#empty"), "Verify Right Element" ); + equal( jQuery("#first").children().children().length, num, "Verify Elements Intact" ); + + var div = jQuery("<div/>"); + div.wrapInner(val("<span></span>")); + equal(div.children().length, 1, "The contents were wrapped."); + equal(div.children()[0].nodeName.toLowerCase(), "span", "A span was inserted."); +} + +test("wrapInner(String|Element)", function() { + testWrapInner(bareObj); +}); + +test("wrapInner(Function)", function() { + testWrapInner(functionReturningObj) +}); + +test("unwrap()", function() { + expect(9); + + jQuery("body").append(" <div id='unwrap' style='display: none;'> <div id='unwrap1'> <span class='unwrap'>a</span> <span class='unwrap'>b</span> </div> <div id='unwrap2'> <span class='unwrap'>c</span> <span class='unwrap'>d</span> </div> <div id='unwrap3'> <b><span class='unwrap unwrap3'>e</span></b> <b><span class='unwrap unwrap3'>f</span></b> </div> </div>"); + + var abcd = jQuery("#unwrap1 > span, #unwrap2 > span").get(), + abcdef = jQuery("#unwrap span").get(); + + equal( jQuery("#unwrap1 span").add("#unwrap2 span:first").unwrap().length, 3, "make #unwrap1 and #unwrap2 go away" ); + deepEqual( jQuery("#unwrap > span").get(), abcd, "all four spans should still exist" ); + + deepEqual( jQuery("#unwrap3 span").unwrap().get(), jQuery("#unwrap3 > span").get(), "make all b in #unwrap3 go away" ); + + deepEqual( jQuery("#unwrap3 span").unwrap().get(), jQuery("#unwrap > span.unwrap3").get(), "make #unwrap3 go away" ); + + deepEqual( jQuery("#unwrap").children().get(), abcdef, "#unwrap only contains 6 child spans" ); + + deepEqual( jQuery("#unwrap > span").unwrap().get(), jQuery("body > span.unwrap").get(), "make the 6 spans become children of body" ); + + deepEqual( jQuery("body > span.unwrap").unwrap().get(), jQuery("body > span.unwrap").get(), "can't unwrap children of body" ); + deepEqual( jQuery("body > span.unwrap").unwrap().get(), abcdef, "can't unwrap children of body" ); + + deepEqual( jQuery("body > span.unwrap").get(), abcdef, "body contains 6 .unwrap child spans" ); + + jQuery("body > span.unwrap").remove(); +}); + +var testAppend = function(valueObj) { + expect(41); + var defaultText = "Try them out:" + var result = jQuery("#first").append(valueObj("<b>buga</b>")); + equal( result.text(), defaultText + "buga", "Check if text appending works" ); + equal( jQuery("#select3").append(valueObj("<option value='appendTest'>Append Test</option>")).find("option:last-child").attr("value"), "appendTest", "Appending html options to select element"); + + QUnit.reset(); + var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:"; + jQuery("#sap").append(valueObj(document.getElementById("first"))); + equal( jQuery("#sap").text(), expected, "Check for appending of element" ); + + QUnit.reset(); + expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo"; + jQuery("#sap").append(valueObj([document.getElementById("first"), document.getElementById("yahoo")])); + equal( jQuery("#sap").text(), expected, "Check for appending of array of elements" ); + + QUnit.reset(); + expected = "This link has class=\"blog\": Simon Willison's WeblogYahooTry them out:"; + jQuery("#sap").append(valueObj(jQuery("#yahoo, #first"))); + equal( jQuery("#sap").text(), expected, "Check for appending of jQuery object" ); + + QUnit.reset(); + jQuery("#sap").append(valueObj( 5 )); + ok( jQuery("#sap")[0].innerHTML.match( /5$/ ), "Check for appending a number" ); + + QUnit.reset(); + jQuery("#sap").append(valueObj( " text with spaces " )); + ok( jQuery("#sap")[0].innerHTML.match(/ text with spaces $/), "Check for appending text with spaces" ); + + QUnit.reset(); + ok( jQuery("#sap").append(valueObj( [] )), "Check for appending an empty array." ); + ok( jQuery("#sap").append(valueObj( "" )), "Check for appending an empty string." ); + ok( jQuery("#sap").append(valueObj( document.getElementsByTagName("foo") )), "Check for appending an empty nodelist." ); + + QUnit.reset(); + jQuery("form").append(valueObj("<input name='radiotest' type='radio' checked='checked' />")); + jQuery("form input[name=radiotest]").each(function(){ + ok( jQuery(this).is(":checked"), "Append checked radio"); + }).remove(); + + QUnit.reset(); + jQuery("form").append(valueObj("<input name='radiotest' type='radio' checked = 'checked' />")); + jQuery("form input[name=radiotest]").each(function(){ + ok( jQuery(this).is(":checked"), "Append alternately formated checked radio"); + }).remove(); + + QUnit.reset(); + jQuery("form").append(valueObj("<input name='radiotest' type='radio' checked />")); + jQuery("form input[name=radiotest]").each(function(){ + ok( jQuery(this).is(":checked"), "Append HTML5-formated checked radio"); + }).remove(); + + QUnit.reset(); + jQuery("#sap").append(valueObj( document.getElementById("form") )); + equal( jQuery("#sap>form").size(), 1, "Check for appending a form" ); // Bug #910 + + QUnit.reset(); + var pass = true; + try { + var body = jQuery("#iframe")[0].contentWindow.document.body; + + pass = false; + jQuery( body ).append(valueObj( "<div>test</div>" )); + pass = true; + } catch(e) {} + + ok( pass, "Test for appending a DOM node to the contents of an IFrame" ); + + QUnit.reset(); + jQuery("<fieldset/>").appendTo("#form").append(valueObj( "<legend id='legend'>test</legend>" )); + t( "Append legend", "#legend", ["legend"] ); + + QUnit.reset(); + jQuery("#select1").append(valueObj( "<OPTION>Test</OPTION>" )); + equal( jQuery("#select1 option:last").text(), "Test", "Appending <OPTION> (all caps)" ); + + jQuery("#table").append(valueObj( "<colgroup></colgroup>" )); + ok( jQuery("#table colgroup").length, "Append colgroup" ); + + jQuery("#table colgroup").append(valueObj( "<col/>" )); + ok( jQuery("#table colgroup col").length, "Append col" ); + + QUnit.reset(); + jQuery("#table").append(valueObj( "<caption></caption>" )); + ok( jQuery("#table caption").length, "Append caption" ); + + QUnit.reset(); + jQuery("form:last") + .append(valueObj( "<select id='appendSelect1'></select>" )) + .append(valueObj( "<select id='appendSelect2'><option>Test</option></select>" )); + + t( "Append Select", "#appendSelect1, #appendSelect2", ["appendSelect1", "appendSelect2"] ); + + equal( "Two nodes", jQuery("<div />").append("Two", " nodes").text(), "Appending two text nodes (#4011)" ); + + // using contents will get comments regular, text, and comment nodes + var j = jQuery("#nonnodes").contents(); + var d = jQuery("<div/>").appendTo("#nonnodes").append(j); + equal( jQuery("#nonnodes").length, 1, "Check node,textnode,comment append moved leaving just the div" ); + ok( d.contents().length >= 2, "Check node,textnode,comment append works" ); + d.contents().appendTo("#nonnodes"); + d.remove(); + ok( jQuery("#nonnodes").contents().length >= 2, "Check node,textnode,comment append cleanup worked" ); + + QUnit.reset(); + var $input = jQuery("<input />").attr({ "type": "checkbox", "checked": true }).appendTo('#testForm'); + equal( $input[0].checked, true, "A checked checkbox that is appended stays checked" ); + + QUnit.reset(); + var $radios = jQuery("input:radio[name='R1']"), + $radioNot = jQuery("<input type='radio' name='R1' checked='checked'/>").insertAfter( $radios ), + $radio = $radios.eq(1).click(); + $radioNot[0].checked = false; + $radios.parent().wrap("<div></div>"); + equal( $radio[0].checked, true, "Reappending radios uphold which radio is checked" ); + equal( $radioNot[0].checked, false, "Reappending radios uphold not being checked" ); + QUnit.reset(); + + var prev = jQuery("#sap").children().length; + + jQuery("#sap").append( + "<span></span>", + "<span></span>", + "<span></span>" + ); + + equal( jQuery("#sap").children().length, prev + 3, "Make sure that multiple arguments works." ); + QUnit.reset(); +} + +test("append(String|Element|Array<Element>|jQuery)", function() { + testAppend(bareObj); +}); + +test("append(Function)", function() { + testAppend(functionReturningObj); +}); + +test("append(Function) with incoming value", function() { + expect(12); + + var defaultText = "Try them out:", old = jQuery("#first").html(); + + var result = jQuery("#first").append(function(i, val){ + equal( val, old, "Make sure the incoming value is correct." ); + return "<b>buga</b>"; + }); + equal( result.text(), defaultText + "buga", "Check if text appending works" ); + + var select = jQuery("#select3"); + old = select.html(); + + equal( select.append(function(i, val){ + equal( val, old, "Make sure the incoming value is correct." ); + return "<option value='appendTest'>Append Test</option>"; + }).find("option:last-child").attr("value"), "appendTest", "Appending html options to select element"); + + QUnit.reset(); + var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:"; + old = jQuery("#sap").html(); + + jQuery("#sap").append(function(i, val){ + equal( val, old, "Make sure the incoming value is correct." ); + return document.getElementById("first"); + }); + equal( jQuery("#sap").text(), expected, "Check for appending of element" ); + + QUnit.reset(); + expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo"; + old = jQuery("#sap").html(); + + jQuery("#sap").append(function(i, val){ + equal( val, old, "Make sure the incoming value is correct." ); + return [document.getElementById("first"), document.getElementById("yahoo")]; + }); + equal( jQuery("#sap").text(), expected, "Check for appending of array of elements" ); + + QUnit.reset(); + expected = "This link has class=\"blog\": Simon Willison's WeblogYahooTry them out:"; + old = jQuery("#sap").html(); + + jQuery("#sap").append(function(i, val){ + equal( val, old, "Make sure the incoming value is correct." ); + return jQuery("#yahoo, #first"); + }); + equal( jQuery("#sap").text(), expected, "Check for appending of jQuery object" ); + + QUnit.reset(); + old = jQuery("#sap").html(); + + jQuery("#sap").append(function(i, val){ + equal( val, old, "Make sure the incoming value is correct." ); + return 5; + }); + ok( jQuery("#sap")[0].innerHTML.match( /5$/ ), "Check for appending a number" ); + + QUnit.reset(); +}); + +test("append the same fragment with events (Bug #6997, 5566)", function () { + var doExtra = !jQuery.support.noCloneEvent && document.fireEvent; + expect(2 + (doExtra ? 1 : 0)); + stop(); + + var element; + + // This patch modified the way that cloning occurs in IE; we need to make sure that + // native event handlers on the original object don't get disturbed when they are + // modified on the clone + if ( doExtra ) { + element = jQuery("div:first").click(function () { + ok(true, "Event exists on original after being unbound on clone"); + jQuery(this).unbind("click"); + }); + var clone = element.clone(true).unbind("click"); + clone[0].fireEvent("onclick"); + element[0].fireEvent("onclick"); + + // manually clean up detached elements + clone.remove(); + } + + element = jQuery("<a class='test6997'></a>").click(function () { + ok(true, "Append second element events work"); + }); + + jQuery("#listWithTabIndex li").append(element) + .find("a.test6997").eq(1).click(); + + element = jQuery("<li class='test6997'></li>").click(function () { + ok(true, "Before second element events work"); + start(); + }); + + jQuery("#listWithTabIndex li").before(element); + jQuery("#listWithTabIndex li.test6997").eq(1).click(); +}); + +test("append HTML5 sectioning elements (Bug #6485)", function () { + expect(2); + + jQuery("#qunit-fixture").append("<article style='font-size:10px'><section><aside>HTML5 elements</aside></section></article>"); + + var article = jQuery("article"), + aside = jQuery("aside"); + + equal( article.css("fontSize"), "10px", "HTML5 elements are styleable"); + equal( aside.length, 1, "HTML5 elements do not collapse their children") +}); + +test("HTML5 Elements inherit styles from style rules (Bug #10501)", function () { + expect(1); + + jQuery("#qunit-fixture").append("<article id='article'></article>"); + jQuery("#article").append("<section>This section should have a pink background.</section>"); + + // In IE, the missing background color will claim its value is "transparent" + notEqual( jQuery("section").css("background-color"), "transparent", "HTML5 elements inherit styles"); +}); + +test("html5 clone() cannot use the fragment cache in IE (#6485)", function () { + expect(1); + + jQuery("<article><section><aside>HTML5 elements</aside></section></article>").appendTo("#qunit-fixture"); + + var clone = jQuery("article").clone(); + + jQuery("#qunit-fixture").append( clone ); + + equal( jQuery("aside").length, 2, "clone()ing HTML5 elems does not collapse them" ); +}); + +test("html(String) with HTML5 (Bug #6485)", function() { + expect(2); + + jQuery("#qunit-fixture").html("<article><section><aside>HTML5 elements</aside></section></article>"); + equal( jQuery("#qunit-fixture").children().children().length, 1, "Make sure HTML5 article elements can hold children. innerHTML shortcut path" ); + equal( jQuery("#qunit-fixture").children().children().children().length, 1, "Make sure nested HTML5 elements can hold children." ); +}); + +test("append(xml)", function() { + expect( 1 ); + + function createXMLDoc() { + // Initialize DOM based upon latest installed MSXML or Netscape + var elem, + aActiveX = + [ "MSXML6.DomDocument", + "MSXML3.DomDocument", + "MSXML2.DomDocument", + "MSXML.DomDocument", + "Microsoft.XmlDom" ]; + + if ( document.implementation && "createDocument" in document.implementation ) { + return document.implementation.createDocument( "", "", null ); + } else { + // IE + for ( var n = 0, len = aActiveX.length; n < len; n++ ) { + try { + elem = new ActiveXObject( aActiveX[ n ] ); + return elem; + } catch(_){}; + } + } + } + + var xmlDoc = createXMLDoc(), + xml1 = xmlDoc.createElement("head"), + xml2 = xmlDoc.createElement("test"); + + ok( jQuery( xml1 ).append( xml2 ), "Append an xml element to another without raising an exception." ); + +}); + +test("appendTo(String|Element|Array<Element>|jQuery)", function() { + expect(17); + + var defaultText = "Try them out:" + jQuery("<b>buga</b>").appendTo("#first"); + equal( jQuery("#first").text(), defaultText + "buga", "Check if text appending works" ); + equal( jQuery("<option value='appendTest'>Append Test</option>").appendTo("#select3").parent().find("option:last-child").attr("value"), "appendTest", "Appending html options to select element"); + + QUnit.reset(); + var l = jQuery("#first").children().length + 2; + jQuery("<strong>test</strong>"); + jQuery("<strong>test</strong>"); + jQuery([ jQuery("<strong>test</strong>")[0], jQuery("<strong>test</strong>")[0] ]) + .appendTo("#first"); + equal( jQuery("#first").children().length, l, "Make sure the elements were inserted." ); + equal( jQuery("#first").children().last()[0].nodeName.toLowerCase(), "strong", "Verify the last element." ); + + QUnit.reset(); + var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:"; + jQuery(document.getElementById("first")).appendTo("#sap"); + equal( jQuery("#sap").text(), expected, "Check for appending of element" ); + + QUnit.reset(); + expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo"; + jQuery([document.getElementById("first"), document.getElementById("yahoo")]).appendTo("#sap"); + equal( jQuery("#sap").text(), expected, "Check for appending of array of elements" ); + + QUnit.reset(); + ok( jQuery(document.createElement("script")).appendTo("body").length, "Make sure a disconnected script can be appended." ); + + QUnit.reset(); + expected = "This link has class=\"blog\": Simon Willison's WeblogYahooTry them out:"; + jQuery("#yahoo, #first").appendTo("#sap"); + equal( jQuery("#sap").text(), expected, "Check for appending of jQuery object" ); + + QUnit.reset(); + jQuery("#select1").appendTo("#foo"); + t( "Append select", "#foo select", ["select1"] ); + + QUnit.reset(); + var div = jQuery("<div/>").click(function(){ + ok(true, "Running a cloned click."); + }); + div.appendTo("#qunit-fixture, #moretests"); + + jQuery("#qunit-fixture div:last").click(); + jQuery("#moretests div:last").click(); + + QUnit.reset(); + div = jQuery("<div/>").appendTo("#qunit-fixture, #moretests"); + + equal( div.length, 2, "appendTo returns the inserted elements" ); + + div.addClass("test"); + + 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" ); + + QUnit.reset(); + + div = jQuery("<div/>"); + jQuery("<span>a</span><b>b</b>").filter("span").appendTo( div ); + + equal( div.children().length, 1, "Make sure the right number of children were inserted." ); + + div = jQuery("#moretests div"); + + var num = jQuery("#qunit-fixture div").length; + div.remove().appendTo("#qunit-fixture"); + + equal( jQuery("#qunit-fixture div").length, num, "Make sure all the removed divs were inserted." ); + + QUnit.reset(); + + stop(); + jQuery.getScript('data/test.js', function() { + jQuery('script[src*="data\\/test\\.js"]').remove(); + start(); + }); +}); + +var testPrepend = function(val) { + expect(5); + var defaultText = "Try them out:" + var result = jQuery("#first").prepend(val( "<b>buga</b>" )); + equal( result.text(), "buga" + defaultText, "Check if text prepending works" ); + equal( jQuery("#select3").prepend(val( "<option value='prependTest'>Prepend Test</option>" )).find("option:first-child").attr("value"), "prependTest", "Prepending html options to select element"); + + QUnit.reset(); + var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog"; + jQuery("#sap").prepend(val( document.getElementById("first") )); + equal( jQuery("#sap").text(), expected, "Check for prepending of element" ); + + QUnit.reset(); + expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog"; + jQuery("#sap").prepend(val( [document.getElementById("first"), document.getElementById("yahoo")] )); + equal( jQuery("#sap").text(), expected, "Check for prepending of array of elements" ); + + QUnit.reset(); + expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog"; + jQuery("#sap").prepend(val( jQuery("#yahoo, #first") )); + equal( jQuery("#sap").text(), expected, "Check for prepending of jQuery object" ); +}; + +test("prepend(String|Element|Array<Element>|jQuery)", function() { + testPrepend(bareObj); +}); + +test("prepend(Function)", function() { + testPrepend(functionReturningObj); +}); + +test("prepend(Function) with incoming value", function() { + expect(10); + + var defaultText = "Try them out:", old = jQuery("#first").html(); + var result = jQuery("#first").prepend(function(i, val) { + equal( val, old, "Make sure the incoming value is correct." ); + return "<b>buga</b>"; + }); + equal( result.text(), "buga" + defaultText, "Check if text prepending works" ); + + old = jQuery("#select3").html(); + + equal( jQuery("#select3").prepend(function(i, val) { + equal( val, old, "Make sure the incoming value is correct." ); + return "<option value='prependTest'>Prepend Test</option>"; + }).find("option:first-child").attr("value"), "prependTest", "Prepending html options to select element"); + + QUnit.reset(); + var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog"; + old = jQuery("#sap").html(); + + jQuery("#sap").prepend(function(i, val) { + equal( val, old, "Make sure the incoming value is correct." ); + return document.getElementById("first"); + }); + + equal( jQuery("#sap").text(), expected, "Check for prepending of element" ); + + QUnit.reset(); + expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog"; + old = jQuery("#sap").html(); + + jQuery("#sap").prepend(function(i, val) { + equal( val, old, "Make sure the incoming value is correct." ); + return [document.getElementById("first"), document.getElementById("yahoo")]; + }); + + equal( jQuery("#sap").text(), expected, "Check for prepending of array of elements" ); + + QUnit.reset(); + expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog"; + old = jQuery("#sap").html(); + + jQuery("#sap").prepend(function(i, val) { + equal( val, old, "Make sure the incoming value is correct." ); + return jQuery("#yahoo, #first"); + }); + + equal( jQuery("#sap").text(), expected, "Check for prepending of jQuery object" ); +}); + +test("prependTo(String|Element|Array<Element>|jQuery)", function() { + expect(6); + var defaultText = "Try them out:" + jQuery("<b>buga</b>").prependTo("#first"); + equal( jQuery("#first").text(), "buga" + defaultText, "Check if text prepending works" ); + equal( jQuery("<option value='prependTest'>Prepend Test</option>").prependTo("#select3").parent().find("option:first-child").attr("value"), "prependTest", "Prepending html options to select element"); + + QUnit.reset(); + var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog"; + jQuery(document.getElementById("first")).prependTo("#sap"); + equal( jQuery("#sap").text(), expected, "Check for prepending of element" ); + + QUnit.reset(); + expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog"; + jQuery([document.getElementById("first"), document.getElementById("yahoo")]).prependTo("#sap"); + equal( jQuery("#sap").text(), expected, "Check for prepending of array of elements" ); + + QUnit.reset(); + expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog"; + jQuery("#yahoo, #first").prependTo("#sap"); + equal( jQuery("#sap").text(), expected, "Check for prepending of jQuery object" ); + + QUnit.reset(); + jQuery("<select id='prependSelect1'></select>").prependTo("form:last"); + jQuery("<select id='prependSelect2'><option>Test</option></select>").prependTo("form:last"); + + t( "Prepend Select", "#prependSelect2, #prependSelect1", ["prependSelect2", "prependSelect1"] ); +}); + +var testBefore = function(val) { + expect(6); + var expected = "This is a normal link: bugaYahoo"; + jQuery("#yahoo").before(val( "<b>buga</b>" )); + equal( jQuery("#en").text(), expected, "Insert String before" ); + + QUnit.reset(); + expected = "This is a normal link: Try them out:Yahoo"; + jQuery("#yahoo").before(val( document.getElementById("first") )); + equal( jQuery("#en").text(), expected, "Insert element before" ); + + QUnit.reset(); + expected = "This is a normal link: Try them out:diveintomarkYahoo"; + jQuery("#yahoo").before(val( [document.getElementById("first"), document.getElementById("mark")] )); + equal( jQuery("#en").text(), expected, "Insert array of elements before" ); + + QUnit.reset(); + expected = "This is a normal link: diveintomarkTry them out:Yahoo"; + jQuery("#yahoo").before(val( jQuery("#mark, #first") )); + equal( jQuery("#en").text(), expected, "Insert jQuery before" ); + + var set = jQuery("<div/>").before("<span>test</span>"); + equal( set[0].nodeName.toLowerCase(), "span", "Insert the element before the disconnected node." ); + equal( set.length, 2, "Insert the element before the disconnected node." ); +}; + +test("before(String|Element|Array<Element>|jQuery)", function() { + testBefore(bareObj); +}); + +test("before(Function)", function() { + testBefore(functionReturningObj); +}); + +test("before and after w/ empty object (#10812)", function() { + expect(2); + + var res = jQuery( "#notInTheDocument" ).before( "(" ).after( ")" ); + equal( res.length, 2, "didn't choke on empty object" ); + equal( res.wrapAll("<div/>").parent().text(), "()", "correctly appended text" ); +}); + +test("insertBefore(String|Element|Array<Element>|jQuery)", function() { + expect(4); + var expected = "This is a normal link: bugaYahoo"; + jQuery("<b>buga</b>").insertBefore("#yahoo"); + equal( jQuery("#en").text(), expected, "Insert String before" ); + + QUnit.reset(); + expected = "This is a normal link: Try them out:Yahoo"; + jQuery(document.getElementById("first")).insertBefore("#yahoo"); + equal( jQuery("#en").text(), expected, "Insert element before" ); + + QUnit.reset(); + expected = "This is a normal link: Try them out:diveintomarkYahoo"; + jQuery([document.getElementById("first"), document.getElementById("mark")]).insertBefore("#yahoo"); + equal( jQuery("#en").text(), expected, "Insert array of elements before" ); + + QUnit.reset(); + expected = "This is a normal link: diveintomarkTry them out:Yahoo"; + jQuery("#mark, #first").insertBefore("#yahoo"); + equal( jQuery("#en").text(), expected, "Insert jQuery before" ); +}); + +var testAfter = function(val) { + expect(6); + var expected = "This is a normal link: Yahoobuga"; + jQuery("#yahoo").after(val( "<b>buga</b>" )); + equal( jQuery("#en").text(), expected, "Insert String after" ); + + QUnit.reset(); + expected = "This is a normal link: YahooTry them out:"; + jQuery("#yahoo").after(val( document.getElementById("first") )); + equal( jQuery("#en").text(), expected, "Insert element after" ); + + QUnit.reset(); + expected = "This is a normal link: YahooTry them out:diveintomark"; + jQuery("#yahoo").after(val( [document.getElementById("first"), document.getElementById("mark")] )); + equal( jQuery("#en").text(), expected, "Insert array of elements after" ); + + QUnit.reset(); + expected = "This is a normal link: YahoodiveintomarkTry them out:"; + jQuery("#yahoo").after(val( jQuery("#mark, #first") )); + equal( jQuery("#en").text(), expected, "Insert jQuery after" ); + + var set = jQuery("<div/>").after("<span>test</span>"); + equal( set[1].nodeName.toLowerCase(), "span", "Insert the element after the disconnected node." ); + equal( set.length, 2, "Insert the element after the disconnected node." ); +}; + +test("after(String|Element|Array<Element>|jQuery)", function() { + testAfter(bareObj); +}); + +test("after(Function)", function() { + testAfter(functionReturningObj); +}); + +test("insertAfter(String|Element|Array<Element>|jQuery)", function() { + expect(4); + var expected = "This is a normal link: Yahoobuga"; + jQuery("<b>buga</b>").insertAfter("#yahoo"); + equal( jQuery("#en").text(), expected, "Insert String after" ); + + QUnit.reset(); + expected = "This is a normal link: YahooTry them out:"; + jQuery(document.getElementById("first")).insertAfter("#yahoo"); + equal( jQuery("#en").text(), expected, "Insert element after" ); + + QUnit.reset(); + expected = "This is a normal link: YahooTry them out:diveintomark"; + jQuery([document.getElementById("first"), document.getElementById("mark")]).insertAfter("#yahoo"); + equal( jQuery("#en").text(), expected, "Insert array of elements after" ); + + QUnit.reset(); + expected = "This is a normal link: YahoodiveintomarkTry them out:"; + jQuery("#mark, #first").insertAfter("#yahoo"); + equal( jQuery("#en").text(), expected, "Insert jQuery after" ); +}); + +var testReplaceWith = function(val) { + expect(21); + jQuery("#yahoo").replaceWith(val( "<b id='replace'>buga</b>" )); + ok( jQuery("#replace")[0], "Replace element with string" ); + ok( !jQuery("#yahoo")[0], "Verify that original element is gone, after string" ); + + QUnit.reset(); + jQuery("#yahoo").replaceWith(val( document.getElementById("first") )); + ok( jQuery("#first")[0], "Replace element with element" ); + ok( !jQuery("#yahoo")[0], "Verify that original element is gone, after element" ); + + QUnit.reset(); + jQuery("#qunit-fixture").append("<div id='bar'><div id='baz'</div></div>"); + jQuery("#baz").replaceWith("Baz"); + equal( jQuery("#bar").text(),"Baz", "Replace element with text" ); + ok( !jQuery("#baz")[0], "Verify that original element is gone, after element" ); + + QUnit.reset(); + jQuery("#yahoo").replaceWith(val( [document.getElementById("first"), document.getElementById("mark")] )); + ok( jQuery("#first")[0], "Replace element with array of elements" ); + ok( jQuery("#mark")[0], "Replace element with array of elements" ); + ok( !jQuery("#yahoo")[0], "Verify that original element is gone, after array of elements" ); + + QUnit.reset(); + jQuery("#yahoo").replaceWith(val( jQuery("#mark, #first") )); + ok( jQuery("#first")[0], "Replace element with set of elements" ); + ok( jQuery("#mark")[0], "Replace element with set of elements" ); + ok( !jQuery("#yahoo")[0], "Verify that original element is gone, after set of elements" ); + + QUnit.reset(); + var tmp = jQuery("<div/>").appendTo("body").click(function(){ ok(true, "Newly bound click run." ); }); + var y = jQuery("<div/>").appendTo("body").click(function(){ ok(true, "Previously bound click run." ); }); + var child = y.append("<b>test</b>").find("b").click(function(){ ok(true, "Child bound click run." ); return false; }); + + y.replaceWith( tmp ); + + tmp.click(); + y.click(); // Shouldn't be run + child.click(); // Shouldn't be run + + tmp.remove(); + y.remove(); + child.remove(); + + QUnit.reset(); + + y = jQuery("<div/>").appendTo("body").click(function(){ ok(true, "Previously bound click run." ); }); + var child2 = y.append("<u>test</u>").find("u").click(function(){ ok(true, "Child 2 bound click run." ); return false; }); + + y.replaceWith( child2 ); + + child2.click(); + + y.remove(); + child2.remove(); + + QUnit.reset(); + + var set = jQuery("<div/>").replaceWith(val("<span>test</span>")); + equal( set[0].nodeName.toLowerCase(), "span", "Replace the disconnected node." ); + equal( set.length, 1, "Replace the disconnected node." ); + + var non_existant = jQuery("#does-not-exist").replaceWith( val("<b>should not throw an error</b>") ); + equal( non_existant.length, 0, "Length of non existant element." ); + + var $div = jQuery("<div class='replacewith'></div>").appendTo("body"); + // TODO: Work on jQuery(...) inline script execution + //$div.replaceWith("<div class='replacewith'></div><script>" + + //"equal(jQuery('.replacewith').length, 1, 'Check number of elements in page.');" + + //"</script>"); + equal(jQuery(".replacewith").length, 1, "Check number of elements in page."); + jQuery(".replacewith").remove(); + + QUnit.reset(); + + jQuery("#qunit-fixture").append("<div id='replaceWith'></div>"); + equal( jQuery("#qunit-fixture").find("div[id=replaceWith]").length, 1, "Make sure only one div exists." ); + + jQuery("#replaceWith").replaceWith( val("<div id='replaceWith'></div>") ); + equal( jQuery("#qunit-fixture").find("div[id=replaceWith]").length, 1, "Make sure only one div exists." ); + + jQuery("#replaceWith").replaceWith( val("<div id='replaceWith'></div>") ); + equal( jQuery("#qunit-fixture").find("div[id=replaceWith]").length, 1, "Make sure only one div exists." ); +} + +test("replaceWith(String|Element|Array<Element>|jQuery)", function() { + testReplaceWith(bareObj); +}); + +test("replaceWith(Function)", function() { + testReplaceWith(functionReturningObj); + + expect(22); + + var y = jQuery("#yahoo")[0]; + + jQuery(y).replaceWith(function(){ + equal( this, y, "Make sure the context is coming in correctly." ); + }); + + QUnit.reset(); +}); + +test("replaceWith(string) for more than one element", function(){ + expect(3); + + equal(jQuery("#foo p").length, 3, "ensuring that test data has not changed"); + + jQuery("#foo p").replaceWith("<span>bar</span>"); + equal(jQuery("#foo span").length, 3, "verify that all the three original element have been replaced"); + equal(jQuery("#foo p").length, 0, "verify that all the three original element have been replaced"); +}); + +test("replaceAll(String|Element|Array<Element>|jQuery)", function() { + expect(10); + jQuery("<b id='replace'>buga</b>").replaceAll("#yahoo"); + ok( jQuery("#replace")[0], "Replace element with string" ); + ok( !jQuery("#yahoo")[0], "Verify that original element is gone, after string" ); + + QUnit.reset(); + jQuery(document.getElementById("first")).replaceAll("#yahoo"); + ok( jQuery("#first")[0], "Replace element with element" ); + ok( !jQuery("#yahoo")[0], "Verify that original element is gone, after element" ); + + QUnit.reset(); + jQuery([document.getElementById("first"), document.getElementById("mark")]).replaceAll("#yahoo"); + ok( jQuery("#first")[0], "Replace element with array of elements" ); + ok( jQuery("#mark")[0], "Replace element with array of elements" ); + ok( !jQuery("#yahoo")[0], "Verify that original element is gone, after array of elements" ); + + QUnit.reset(); + jQuery("#mark, #first").replaceAll("#yahoo"); + ok( jQuery("#first")[0], "Replace element with set of elements" ); + ok( jQuery("#mark")[0], "Replace element with set of elements" ); + ok( !jQuery("#yahoo")[0], "Verify that original element is gone, after set of elements" ); +}); + +test("jQuery.clone() (#8017)", function() { + + expect(2); + + ok( jQuery.clone && jQuery.isFunction( jQuery.clone ) , "jQuery.clone() utility exists and is a function."); + + var main = jQuery("#qunit-fixture")[0], + clone = jQuery.clone( main ); + + equal( main.childNodes.length, clone.childNodes.length, "Simple child length to ensure a large dom tree copies correctly" ); +}); + +test("clone() (#8070)", function () { + expect(2); + + jQuery("<select class='test8070'></select><select class='test8070'></select>").appendTo("#qunit-fixture"); + var selects = jQuery(".test8070"); + selects.append("<OPTION>1</OPTION><OPTION>2</OPTION>"); + + equal( selects[0].childNodes.length, 2, "First select got two nodes" ); + equal( selects[1].childNodes.length, 2, "Second select got two nodes" ); + + selects.remove(); +}); + +test("clone()", function() { + expect(39); + equal( "This is a normal link: Yahoo", jQuery("#en").text(), "Assert text for #en" ); + var clone = jQuery("#yahoo").clone(); + equal( "Try them out:Yahoo", jQuery("#first").append(clone).text(), "Check for clone" ); + equal( "This is a normal link: Yahoo", jQuery("#en").text(), "Reassert text for #en" ); + + var cloneTags = [ + "<table/>", "<tr/>", "<td/>", "<div/>", + "<button/>", "<ul/>", "<ol/>", "<li/>", + "<input type='checkbox' />", "<select/>", "<option/>", "<textarea/>", + "<tbody/>", "<thead/>", "<tfoot/>", "<iframe/>" + ]; + for (var i = 0; i < cloneTags.length; i++) { + var j = jQuery(cloneTags[i]); + equal( j[0].tagName, j.clone()[0].tagName, "Clone a " + cloneTags[i]); + } + + // using contents will get comments regular, text, and comment nodes + var cl = jQuery("#nonnodes").contents().clone(); + ok( cl.length >= 2, "Check node,textnode,comment clone works (some browsers delete comments on clone)" ); + + var div = jQuery("<div><ul><li>test</li></ul></div>").click(function(){ + ok( true, "Bound event still exists." ); + }); + + clone = div.clone(true); + + // manually clean up detached elements + div.remove(); + + div = clone.clone(true); + + // manually clean up detached elements + clone.remove(); + + equal( div.length, 1, "One element cloned" ); + equal( div[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" ); + div.trigger("click"); + + // manually clean up detached elements + div.remove(); + + div = jQuery("<div/>").append([ document.createElement("table"), document.createElement("table") ]); + div.find("table").click(function(){ + ok( true, "Bound event still exists." ); + }); + + clone = div.clone(true); + equal( clone.length, 1, "One element cloned" ); + equal( clone[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" ); + clone.find("table:last").trigger("click"); + + // manually clean up detached elements + div.remove(); + clone.remove(); + + var divEvt = jQuery("<div><ul><li>test</li></ul></div>").click(function(){ + ok( false, "Bound event still exists after .clone()." ); + }), + cloneEvt = divEvt.clone(); + + // Make sure that doing .clone() doesn't clone events + cloneEvt.trigger("click"); + + cloneEvt.remove(); + divEvt.remove(); + + // Test both html() and clone() for <embed and <object types + div = jQuery("<div/>").html('<embed height="355" width="425" src="http://www.youtube.com/v/3KANI2dpXLw&hl=en"></embed>'); + + clone = div.clone(true); + equal( clone.length, 1, "One element cloned" ); + equal( clone.html(), div.html(), "Element contents cloned" ); + equal( clone[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" ); + + // this is technically an invalid object, but because of the special + // classid instantiation it is the only kind that IE has trouble with, + // so let's test with it too. + div = jQuery("<div/>").html("<object height='355' width='425' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'> <param name='movie' value='http://www.youtube.com/v/3KANI2dpXLw&hl=en'> <param name='wmode' value='transparent'> </object>"); + + clone = div.clone(true); + equal( clone.length, 1, "One element cloned" ); + // equal( clone.html(), div.html(), "Element contents cloned" ); + equal( clone[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" ); + + // and here's a valid one. + div = jQuery("<div/>").html("<object height='355' width='425' type='application/x-shockwave-flash' data='http://www.youtube.com/v/3KANI2dpXLw&hl=en'> <param name='movie' value='http://www.youtube.com/v/3KANI2dpXLw&hl=en'> <param name='wmode' value='transparent'> </object>"); + + clone = div.clone(true); + equal( clone.length, 1, "One element cloned" ); + equal( clone.html(), div.html(), "Element contents cloned" ); + equal( clone[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" ); + + div = jQuery("<div/>").data({ a: true }); + clone = div.clone(true); + equal( clone.data("a"), true, "Data cloned." ); + clone.data("a", false); + equal( clone.data("a"), false, "Ensure cloned element data object was correctly modified" ); + equal( div.data("a"), true, "Ensure cloned element data object is copied, not referenced" ); + + // manually clean up detached elements + div.remove(); + clone.remove(); + + var form = document.createElement("form"); + form.action = "/test/"; + var div = document.createElement("div"); + div.appendChild( document.createTextNode("test") ); + form.appendChild( div ); + + equal( jQuery(form).clone().children().length, 1, "Make sure we just get the form back." ); + + equal( jQuery("body").clone().children()[0].id, "qunit-header", "Make sure cloning body works" ); +}); + +test("clone(form element) (Bug #3879, #6655)", function() { + expect(5); + var element = jQuery("<select><option>Foo</option><option selected>Bar</option></select>"); + + equal( element.clone().find("option:selected").val(), element.find("option:selected").val(), "Selected option cloned correctly" ); + + element = jQuery("<input type='checkbox' value='foo'>").attr("checked", "checked"); + clone = element.clone(); + + equal( clone.is(":checked"), element.is(":checked"), "Checked input cloned correctly" ); + equal( clone[0].defaultValue, "foo", "Checked input defaultValue cloned correctly" ); + + // defaultChecked also gets set now due to setAttribute in attr, is this check still valid? + // equal( clone[0].defaultChecked, !jQuery.support.noCloneChecked, "Checked input defaultChecked cloned correctly" ); + + element = jQuery("<input type='text' value='foo'>"); + clone = element.clone(); + equal( clone[0].defaultValue, "foo", "Text input defaultValue cloned correctly" ); + + element = jQuery("<textarea>foo</textarea>"); + clone = element.clone(); + equal( clone[0].defaultValue, "foo", "Textarea defaultValue cloned correctly" ); +}); + +test("clone(multiple selected options) (Bug #8129)", function() { + expect(1); + var element = jQuery("<select><option>Foo</option><option selected>Bar</option><option selected>Baz</option></select>"); + + equal( element.clone().find("option:selected").length, element.find("option:selected").length, "Multiple selected options cloned correctly" ); + +}); + +if (!isLocal) { +test("clone() on XML nodes", function() { + expect(2); + stop(); + jQuery.get("data/dashboard.xml", function (xml) { + var root = jQuery(xml.documentElement).clone(); + var origTab = jQuery("tab", xml).eq(0); + var cloneTab = jQuery("tab", root).eq(0); + origTab.text("origval"); + cloneTab.text("cloneval"); + equal(origTab.text(), "origval", "Check original XML node was correctly set"); + equal(cloneTab.text(), "cloneval", "Check cloned XML node was correctly set"); + start(); + }); +}); +} + +var testHtml = function(valueObj) { + expect(34); + + jQuery.scriptorder = 0; + + var div = jQuery("#qunit-fixture > div"); + div.html(valueObj("<b>test</b>")); + var pass = true; + for ( var i = 0; i < div.size(); i++ ) { + if ( div.get(i).childNodes.length != 1 ) pass = false; + } + ok( pass, "Set HTML" ); + + div = jQuery("<div/>").html( valueObj("<div id='parent_1'><div id='child_1'/></div><div id='parent_2'/>") ); + + equal( div.children().length, 2, "Make sure two child nodes exist." ); + equal( div.children().children().length, 1, "Make sure that a grandchild exists." ); + + var space = jQuery("<div/>").html(valueObj(" "))[0].innerHTML; + ok( /^\xA0$|^ $/.test( space ), "Make sure entities are passed through correctly." ); + equal( jQuery("<div/>").html(valueObj("&"))[0].innerHTML, "&", "Make sure entities are passed through correctly." ); + + jQuery("#qunit-fixture").html(valueObj("<style>.foobar{color:green;}</style>")); + + equal( jQuery("#qunit-fixture").children().length, 1, "Make sure there is a child element." ); + equal( jQuery("#qunit-fixture").children()[0].nodeName.toUpperCase(), "STYLE", "And that a style element was inserted." ); + + QUnit.reset(); + // using contents will get comments regular, text, and comment nodes + var j = jQuery("#nonnodes").contents(); + j.html(valueObj("<b>bold</b>")); + + // this is needed, or the expando added by jQuery unique will yield a different html + j.find("b").removeData(); + equal( j.html().replace(/ xmlns="[^"]+"/g, "").toLowerCase(), "<b>bold</b>", "Check node,textnode,comment with html()" ); + + jQuery("#qunit-fixture").html(valueObj("<select/>")); + jQuery("#qunit-fixture select").html(valueObj("<option>O1</option><option selected='selected'>O2</option><option>O3</option>")); + equal( jQuery("#qunit-fixture select").val(), "O2", "Selected option correct" ); + + var $div = jQuery("<div />"); + equal( $div.html(valueObj( 5 )).html(), "5", "Setting a number as html" ); + equal( $div.html(valueObj( 0 )).html(), "0", "Setting a zero as html" ); + + var $div2 = jQuery("<div/>"), insert = "<div>hello1</div>"; + equal( $div2.html(insert).html().replace(/>/g, ">"), insert, "Verify escaped insertion." ); + equal( $div2.html("x" + insert).html().replace(/>/g, ">"), "x" + insert, "Verify escaped insertion." ); + equal( $div2.html(" " + insert).html().replace(/>/g, ">"), " " + insert, "Verify escaped insertion." ); + + var map = jQuery("<map/>").html(valueObj("<area id='map01' shape='rect' coords='50,50,150,150' href='http://www.jquery.com/' alt='jQuery'>")); + + equal( map[0].childNodes.length, 1, "The area was inserted." ); + equal( map[0].firstChild.nodeName.toLowerCase(), "area", "The area was inserted." ); + + QUnit.reset(); + + 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("#qunit-fixture").find("script"); + + equal( child.length, 2, "Make sure that two non-JavaScript script tags are left." ); + equal( child[0].type, "something/else", "Verify type of script tag." ); + equal( child[1].type, "something/else", "Verify type of script tag." ); + + jQuery("#qunit-fixture").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("#qunit-fixture").html(valueObj("<script>ok( true, 'Test repeated injection of script.' );</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("#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("#qunit-fixture").html(valueObj("<script>equal(jQuery.scriptorder++, 0, 'Script is executed in order');equal(jQuery('#scriptorder').length, 1,'Execute after html (even though appears before)')<\/script><span id='scriptorder'><script>equal(jQuery.scriptorder++, 1, 'Script (nested) is executed in order');equal(jQuery('#scriptorder').length, 1,'Execute after html')<\/script></span><script>equal(jQuery.scriptorder++, 2, 'Script (unnested) is executed in order');equal(jQuery('#scriptorder').length, 1,'Execute after html')<\/script>")); +} + +test("html(String)", function() { + testHtml(bareObj); +}); + +test("html(Function)", function() { + testHtml(functionReturningObj); + + expect(36); + + QUnit.reset(); + + jQuery("#qunit-fixture").html(function(){ + return jQuery(this).text(); + }); + + ok( !/</.test( jQuery("#qunit-fixture").html() ), "Replace html with text." ); + ok( jQuery("#qunit-fixture").html().length > 0, "Make sure text exists." ); +}); + +test("html(Function) with incoming value", function() { + expect(20); + + var div = jQuery("#qunit-fixture > div"), old = div.map(function(){ return jQuery(this).html() }); + + div.html(function(i, val) { + equal( val, old[i], "Make sure the incoming value is correct." ); + return "<b>test</b>"; + }); + + var pass = true; + div.each(function(){ + if ( this.childNodes.length !== 1 ) { + pass = false; + } + }) + ok( pass, "Set HTML" ); + + QUnit.reset(); + // using contents will get comments regular, text, and comment nodes + var j = jQuery("#nonnodes").contents(); + old = j.map(function(){ return jQuery(this).html(); }); + + j.html(function(i, val) { + equal( val, old[i], "Make sure the incoming value is correct." ); + return "<b>bold</b>"; + }); + + // Handle the case where no comment is in the document + if ( j.length === 2 ) { + equal( null, null, "Make sure the incoming value is correct." ); + } + + j.find("b").removeData(); + equal( j.html().replace(/ xmlns="[^"]+"/g, "").toLowerCase(), "<b>bold</b>", "Check node,textnode,comment with html()" ); + + var $div = jQuery("<div />"); + + equal( $div.html(function(i, val) { + equal( val, "", "Make sure the incoming value is correct." ); + return 5; + }).html(), "5", "Setting a number as html" ); + + equal( $div.html(function(i, val) { + equal( val, "5", "Make sure the incoming value is correct." ); + return 0; + }).html(), "0", "Setting a zero as html" ); + + var $div2 = jQuery("<div/>"), insert = "<div>hello1</div>"; + equal( $div2.html(function(i, val) { + equal( val, "", "Make sure the incoming value is correct." ); + return insert; + }).html().replace(/>/g, ">"), insert, "Verify escaped insertion." ); + + equal( $div2.html(function(i, val) { + equal( val.replace(/>/g, ">"), insert, "Make sure the incoming value is correct." ); + return "x" + insert; + }).html().replace(/>/g, ">"), "x" + insert, "Verify escaped insertion." ); + + equal( $div2.html(function(i, val) { + equal( val.replace(/>/g, ">"), "x" + insert, "Make sure the incoming value is correct." ); + return " " + insert; + }).html().replace(/>/g, ">"), " " + insert, "Verify escaped insertion." ); +}); + +var testRemove = function(method) { + expect(9); + + var first = jQuery("#ap").children(":first"); + first.data("foo", "bar"); + + jQuery("#ap").children()[method](); + ok( jQuery("#ap").text().length > 10, "Check text is not removed" ); + equal( jQuery("#ap").children().length, 0, "Check remove" ); + + equal( first.data("foo"), method == "remove" ? null : "bar" ); + + QUnit.reset(); + jQuery("#ap").children()[method]("a"); + ok( jQuery("#ap").text().length > 10, "Check text is not removed" ); + equal( jQuery("#ap").children().length, 1, "Check filtered remove" ); + + jQuery("#ap").children()[method]("a, code"); + equal( jQuery("#ap").children().length, 0, "Check multi-filtered remove" ); + + // using contents will get comments regular, text, and comment nodes + // Handle the case where no comment is in the document + ok( jQuery("#nonnodes").contents().length >= 2, "Check node,textnode,comment remove works" ); + jQuery("#nonnodes").contents()[method](); + equal( jQuery("#nonnodes").contents().length, 0, "Check node,textnode,comment remove works" ); + + // manually clean up detached elements + if (method === "detach") { + first.remove(); + } + + QUnit.reset(); + + var count = 0; + var first = jQuery("#ap").children(":first"); + var cleanUp = first.click(function() { count++ })[method]().appendTo("#qunit-fixture").click(); + + equal( method == "remove" ? 0 : 1, count ); + + // manually clean up detached elements + cleanUp.remove(); +}; + +test("remove()", function() { + testRemove("remove"); +}); + +test("detach()", function() { + testRemove("detach"); +}); + +test("empty()", function() { + expect(3); + equal( jQuery("#ap").children().empty().text().length, 0, "Check text is removed" ); + equal( jQuery("#ap").children().length, 4, "Check elements are not removed" ); + + // using contents will get comments regular, text, and comment nodes + var j = jQuery("#nonnodes").contents(); + j.empty(); + equal( j.html(), "", "Check node,textnode,comment empty works" ); +}); + +test("jQuery.cleanData", function() { + expect(14); + + var type, pos, div, child; + + type = "remove"; + + // Should trigger 4 remove event + div = getDiv().remove(); + + // Should both do nothing + pos = "Outer"; + div.trigger("click"); + + pos = "Inner"; + div.children().trigger("click"); + + type = "empty"; + div = getDiv(); + child = div.children(); + + // Should trigger 2 remove event + div.empty(); + + // Should trigger 1 + pos = "Outer"; + div.trigger("click"); + + // Should do nothing + pos = "Inner"; + child.trigger("click"); + + // Should trigger 2 + div.remove(); + + type = "html"; + + div = getDiv(); + child = div.children(); + + // Should trigger 2 remove event + div.html("<div></div>"); + + // Should trigger 1 + pos = "Outer"; + div.trigger("click"); + + // Should do nothing + pos = "Inner"; + child.trigger("click"); + + // Should trigger 2 + div.remove(); + + function getDiv() { + var div = jQuery("<div class='outer'><div class='inner'></div></div>").click(function(){ + ok( true, type + " " + pos + " Click event fired." ); + }).focus(function(){ + ok( true, type + " " + pos + " Focus event fired." ); + }).find("div").click(function(){ + ok( false, type + " " + pos + " Click event fired." ); + }).focus(function(){ + ok( false, type + " " + pos + " Focus event fired." ); + }).end().appendTo("body"); + + div[0].detachEvent = div[0].removeEventListener = function(t){ + ok( true, type + " Outer " + t + " event unbound" ); + }; + + div[0].firstChild.detachEvent = div[0].firstChild.removeEventListener = function(t){ + ok( true, type + " Inner " + t + " event unbound" ); + }; + + return div; + } +}); + +test("jQuery.buildFragment - no plain-text caching (Bug #6779)", function() { + expect(1); + + // DOM manipulation fails if added text matches an Object method + var $f = jQuery( "<div />" ).appendTo( "#qunit-fixture" ), + bad = [ "start-", "toString", "hasOwnProperty", "append", "here&there!", "-end" ]; + + for ( var i=0; i < bad.length; i++ ) { + try { + $f.append( bad[i] ); + } + catch(e) {} + } + equal($f.text(), bad.join(""), "Cached strings that match Object properties"); + $f.remove(); +}); + +test( "jQuery.html - execute scripts escaped with html comment or CDATA (#9221)", function() { + expect( 3 ); + jQuery( [ + '<script type="text/javascript">', + '<!--', + 'ok( true, "<!-- handled" );', + '//-->', + '</script>' + ].join ( "\n" ) ).appendTo( "#qunit-fixture" ); + jQuery( [ + '<script type="text/javascript">', + '<![CDATA[', + 'ok( true, "<![CDATA[ handled" );', + '//]]>', + '</script>' + ].join ( "\n" ) ).appendTo( "#qunit-fixture" ); + jQuery( [ + '<script type="text/javascript">', + '<!--//--><![CDATA[//><!--', + 'ok( true, "<!--//--><![CDATA[//><!-- (Drupal case) handled" );', + '//--><!]]>', + '</script>' + ].join ( "\n" ) ).appendTo( "#qunit-fixture" ); +}); + +test("jQuery.buildFragment - plain objects are not a document #8950", function() { + expect(1); + + try { + jQuery('<input type="hidden">', {}); + ok( true, "Does not allow attribute object to be treated like a doc object"); + } catch (e) {} + +}); + +test("jQuery.clone - no exceptions for object elements #9587", function() { + expect(1); + + try { + jQuery("#no-clone-exception").clone(); + ok( true, "cloned with no exceptions" ); + } catch( e ) { + ok( false, e.message ); + } +}); + +test("jQuery(<tag>) & wrap[Inner/All]() handle unknown elems (#10667)", function() { + expect(2); + + var $wraptarget = jQuery( "<div id='wrap-target'>Target</div>" ).appendTo( "#qunit-fixture" ), + $section = jQuery( "<section>" ).appendTo( "#qunit-fixture" ); + + $wraptarget.wrapAll("<aside style='background-color:green'></aside>"); + + notEqual( $wraptarget.parent("aside").css("background-color"), "transparent", "HTML5 elements created with wrapAll inherit styles" ); + notEqual( $section.css("background-color"), "transparent", "HTML5 elements create with jQuery( string ) inherit styles" ); +}); + +test("Cloned, detached HTML5 elems (#10667,10670)", function() { + expect(7); + + var $section = jQuery( "<section>" ).appendTo( "#qunit-fixture" ), + $clone; + + // First clone + $clone = $section.clone(); + + // Infer that the test is being run in IE<=8 + if ( $clone[0].outerHTML && !jQuery.support.opacity ) { + // This branch tests cloning nodes by reading the outerHTML, used only in IE<=8 + equal( $clone[0].outerHTML, "<section></section>", "detached clone outerHTML matches '<section></section>'" ); + } else { + // This branch tests a known behaviour in modern browsers that should never fail. + // Included for expected test count symmetry (expecting 1) + equal( $clone[0].nodeName, "SECTION", "detached clone nodeName matches 'SECTION' in modern browsers" ); + } + + // Bind an event + $section.bind( "click", function( event ) { + ok( true, "clone fired event" ); + }); + + // Second clone (will have an event bound) + $clone = $section.clone( true ); + + // Trigger an event from the first clone + $clone.trigger( "click" ); + $clone.unbind( "click" ); + + // Add a child node with text to the original + $section.append( "<p>Hello</p>" ); + + // Third clone (will have child node and text) + $clone = $section.clone( true ); + + equal( $clone.find("p").text(), "Hello", "Assert text in child of clone" ); + + // Trigger an event from the third clone + $clone.trigger( "click" ); + $clone.unbind( "click" ); + + // Add attributes to copy + $section.attr({ + "class": "foo bar baz", + "title": "This is a title" + }); + + // Fourth clone (will have newly added attributes) + $clone = $section.clone( true ); + + equal( $clone.attr("class"), $section.attr("class"), "clone and element have same class attribute" ); + equal( $clone.attr("title"), $section.attr("title"), "clone and element have same title attribute" ); + + // Remove the original + $section.remove(); + + // Clone the clone + $section = $clone.clone( true ); + + // Remove the clone + $clone.remove(); + + // Trigger an event from the clone of the clone + $section.trigger( "click" ); + + // Unbind any remaining events + $section.unbind( "click" ); + $clone.unbind( "click" ); +}); + +test("jQuery.fragments cache expectations", function() { + + expect( 10 ); + + jQuery.fragments = {}; + + function fragmentCacheSize() { + var n = 0, c; + + for ( c in jQuery.fragments ) { + n++; + } + return n; + } + + jQuery("<li></li>"); + jQuery("<li>?</li>"); + jQuery("<li>whip</li>"); + jQuery("<li>it</li>"); + jQuery("<li>good</li>"); + jQuery("<div></div>"); + jQuery("<div><div><span></span></div></div>"); + jQuery("<tr><td></td></tr>"); + jQuery("<tr><td></tr>"); + jQuery("<li>aaa</li>"); + jQuery("<ul><li>?</li></ul>"); + jQuery("<div><p>arf</p>nnn</div>"); + jQuery("<div><p>dog</p>?</div>"); + jQuery("<span><span>"); + + equal( fragmentCacheSize(), 12, "12 entries exist in jQuery.fragments, 1" ); + + jQuery.each( [ + "<tr><td></td></tr>", + "<ul><li>?</li></ul>", + "<div><p>dog</p>?</div>", + "<span><span>" + ], function( i, frag ) { + + jQuery( frag ); + + equal( jQuery.fragments[ frag ].nodeType, 11, "Second call with " + frag + " creates a cached DocumentFragment, has nodeType 11" ); + ok( jQuery.fragments[ frag ].childNodes.length, "Second call with " + frag + " creates a cached DocumentFragment, has childNodes with length" ); + }); + + equal( fragmentCacheSize(), 12, "12 entries exist in jQuery.fragments, 2" ); +}); diff --git a/npm_assets/node_modules/html5shiv/test/jquery-1.7.1/unit/traversing.js b/npm_assets/node_modules/html5shiv/test/jquery-1.7.1/unit/traversing.js new file mode 100644 index 0000000..bcd3a97 --- /dev/null +++ b/npm_assets/node_modules/html5shiv/test/jquery-1.7.1/unit/traversing.js @@ -0,0 +1,642 @@ +module("traversing", { teardown: moduleTeardown }); + +test("find(String)", function() { + expect(5); + equal( "Yahoo", jQuery("#foo").find(".blogTest").text(), "Check for find" ); + + // using contents will get comments regular, text, and comment nodes + var j = jQuery("#nonnodes").contents(); + equal( j.find("div").length, 0, "Check node,textnode,comment to find zero divs" ); + + deepEqual( jQuery("#qunit-fixture").find("> div").get(), q("foo", "moretests", "tabindex-tests", "liveHandlerOrder", "siblingTest"), "find child elements" ); + deepEqual( jQuery("#qunit-fixture").find("> #foo, > #moretests").get(), q("foo", "moretests"), "find child elements" ); + deepEqual( jQuery("#qunit-fixture").find("> #foo > p").get(), q("sndp", "en", "sap"), "find child elements" ); +}); + +test("find(node|jQuery object)", function() { + expect( 11 ); + + var $foo = jQuery("#foo"), + $blog = jQuery(".blogTest"), + $first = jQuery("#first"), + $two = $blog.add( $first ), + $fooTwo = $foo.add( $blog ); + + equal( $foo.find( $blog ).text(), "Yahoo", "Find with blog jQuery object" ); + equal( $foo.find( $blog[0] ).text(), "Yahoo", "Find with blog node" ); + equal( $foo.find( $first ).length, 0, "#first is not in #foo" ); + equal( $foo.find( $first[0]).length, 0, "#first not in #foo (node)" ); + ok( $foo.find( $two ).is(".blogTest"), "Find returns only nodes within #foo" ); + ok( $fooTwo.find( $blog ).is(".blogTest"), "Blog is part of the collection, but also within foo" ); + ok( $fooTwo.find( $blog[0] ).is(".blogTest"), "Blog is part of the collection, but also within foo(node)" ); + + equal( $two.find( $foo ).length, 0, "Foo is not in two elements" ); + equal( $two.find( $foo[0] ).length, 0, "Foo is not in two elements(node)" ); + equal( $two.find( $first ).length, 0, "first is in the collection and not within two" ); + equal( $two.find( $first ).length, 0, "first is in the collection and not within two(node)" ); + +}); + +test("is(String|undefined)", function() { + expect(29); + ok( jQuery("#form").is("form"), "Check for element: A form must be a form" ); + ok( !jQuery("#form").is("div"), "Check for element: A form is not a div" ); + ok( jQuery("#mark").is(".blog"), "Check for class: Expected class 'blog'" ); + ok( !jQuery("#mark").is(".link"), "Check for class: Did not expect class 'link'" ); + ok( jQuery("#simon").is(".blog.link"), "Check for multiple classes: Expected classes 'blog' and 'link'" ); + ok( !jQuery("#simon").is(".blogTest"), "Check for multiple classes: Expected classes 'blog' and 'link', but not 'blogTest'" ); + ok( jQuery("#en").is("[lang=\"en\"]"), "Check for attribute: Expected attribute lang to be 'en'" ); + ok( !jQuery("#en").is("[lang=\"de\"]"), "Check for attribute: Expected attribute lang to be 'en', not 'de'" ); + ok( jQuery("#text1").is("[type=\"text\"]"), "Check for attribute: Expected attribute type to be 'text'" ); + ok( !jQuery("#text1").is("[type=\"radio\"]"), "Check for attribute: Expected attribute type to be 'text', not 'radio'" ); + ok( jQuery("#text2").is(":disabled"), "Check for pseudoclass: Expected to be disabled" ); + ok( !jQuery("#text1").is(":disabled"), "Check for pseudoclass: Expected not disabled" ); + ok( jQuery("#radio2").is(":checked"), "Check for pseudoclass: Expected to be checked" ); + ok( !jQuery("#radio1").is(":checked"), "Check for pseudoclass: Expected not checked" ); + ok( jQuery("#foo").is(":has(p)"), "Check for child: Expected a child 'p' element" ); + ok( !jQuery("#foo").is(":has(ul)"), "Check for child: Did not expect 'ul' element" ); + ok( jQuery("#foo").is(":has(p):has(a):has(code)"), "Check for childs: Expected 'p', 'a' and 'code' child elements" ); + ok( !jQuery("#foo").is(":has(p):has(a):has(code):has(ol)"), "Check for childs: Expected 'p', 'a' and 'code' child elements, but no 'ol'" ); + + ok( !jQuery("#foo").is(0), "Expected false for an invalid expression - 0" ); + ok( !jQuery("#foo").is(null), "Expected false for an invalid expression - null" ); + ok( !jQuery("#foo").is(""), "Expected false for an invalid expression - \"\"" ); + ok( !jQuery("#foo").is(undefined), "Expected false for an invalid expression - undefined" ); + ok( !jQuery("#foo").is({ plain: "object" }), "Check passing invalid object" ); + + // test is() with comma-seperated expressions + ok( jQuery("#en").is("[lang=\"en\"],[lang=\"de\"]"), "Comma-seperated; Check for lang attribute: Expect en or de" ); + ok( jQuery("#en").is("[lang=\"de\"],[lang=\"en\"]"), "Comma-seperated; Check for lang attribute: Expect en or de" ); + ok( jQuery("#en").is("[lang=\"en\"] , [lang=\"de\"]"), "Comma-seperated; Check for lang attribute: Expect en or de" ); + ok( jQuery("#en").is("[lang=\"de\"] , [lang=\"en\"]"), "Comma-seperated; Check for lang attribute: Expect en or de" ); + + ok( !jQuery(window).is('a'), "Checking is on a window does not throw an exception(#10178)" ); + ok( !jQuery(document).is('a'), "Checking is on a document does not throw an exception(#10178)" ); +}); + +test("is(jQuery)", function() { + expect(21); + ok( jQuery("#form").is( jQuery("form") ), "Check for element: A form is a form" ); + ok( !jQuery("#form").is( jQuery("div") ), "Check for element: A form is not a div" ); + ok( jQuery("#mark").is( jQuery(".blog") ), "Check for class: Expected class 'blog'" ); + ok( !jQuery("#mark").is( jQuery(".link") ), "Check for class: Did not expect class 'link'" ); + ok( jQuery("#simon").is( jQuery(".blog.link") ), "Check for multiple classes: Expected classes 'blog' and 'link'" ); + ok( !jQuery("#simon").is( jQuery(".blogTest") ), "Check for multiple classes: Expected classes 'blog' and 'link', but not 'blogTest'" ); + ok( jQuery("#en").is( jQuery("[lang=\"en\"]") ), "Check for attribute: Expected attribute lang to be 'en'" ); + ok( !jQuery("#en").is( jQuery("[lang=\"de\"]") ), "Check for attribute: Expected attribute lang to be 'en', not 'de'" ); + ok( jQuery("#text1").is( jQuery("[type=\"text\"]") ), "Check for attribute: Expected attribute type to be 'text'" ); + ok( !jQuery("#text1").is( jQuery("[type=\"radio\"]") ), "Check for attribute: Expected attribute type to be 'text', not 'radio'" ); + ok( !jQuery("#text1").is( jQuery("input:disabled") ), "Check for pseudoclass: Expected not disabled" ); + ok( jQuery("#radio2").is( jQuery("input:checked") ), "Check for pseudoclass: Expected to be checked" ); + ok( !jQuery("#radio1").is( jQuery("input:checked") ), "Check for pseudoclass: Expected not checked" ); + ok( jQuery("#foo").is( jQuery("div:has(p)") ), "Check for child: Expected a child 'p' element" ); + ok( !jQuery("#foo").is( jQuery("div:has(ul)") ), "Check for child: Did not expect 'ul' element" ); + + // Some raw elements + ok( jQuery("#form").is( jQuery("form")[0] ), "Check for element: A form is a form" ); + ok( !jQuery("#form").is( jQuery("div")[0] ), "Check for element: A form is not a div" ); + ok( jQuery("#mark").is( jQuery(".blog")[0] ), "Check for class: Expected class 'blog'" ); + ok( !jQuery("#mark").is( jQuery(".link")[0] ), "Check for class: Did not expect class 'link'" ); + ok( jQuery("#simon").is( jQuery(".blog.link")[0] ), "Check for multiple classes: Expected classes 'blog' and 'link'" ); + ok( !jQuery("#simon").is( jQuery(".blogTest")[0] ), "Check for multiple classes: Expected classes 'blog' and 'link', but not 'blogTest'" ); +}); + +test("is() with positional selectors", function() { + expect(23); + + var html = jQuery( + '<p id="posp"><a class="firsta" href="#"><em>first</em></a><a class="seconda" href="#"><b>test</b></a><em></em></p>' + ).appendTo( "body" ), + isit = function(sel, match, expect) { + equal( jQuery( sel ).is( match ), expect, "jQuery( " + sel + " ).is( " + match + " )" ); + }; + + isit( "#posp", "#posp:first", true ); + isit( "#posp", "#posp:eq(2)", false ); + isit( "#posp", "#posp a:first", false ); + + isit( "#posp .firsta", "#posp a:first", true ); + isit( "#posp .firsta", "#posp a:last", false ); + isit( "#posp .firsta", "#posp a:even", true ); + isit( "#posp .firsta", "#posp a:odd", false ); + isit( "#posp .firsta", "#posp a:eq(0)", true ); + isit( "#posp .firsta", "#posp a:eq(9)", false ); + isit( "#posp .firsta", "#posp em:eq(0)", false ); + isit( "#posp .firsta", "#posp em:first", false ); + isit( "#posp .firsta", "#posp:first", false ); + + isit( "#posp .seconda", "#posp a:first", false ); + isit( "#posp .seconda", "#posp a:last", true ); + isit( "#posp .seconda", "#posp a:gt(0)", true ); + isit( "#posp .seconda", "#posp a:lt(5)", true ); + isit( "#posp .seconda", "#posp a:lt(1)", false ); + + isit( "#posp em", "#posp a:eq(0) em", true ); + isit( "#posp em", "#posp a:lt(1) em", true ); + isit( "#posp em", "#posp a:gt(1) em", false ); + isit( "#posp em", "#posp a:first em", true ); + isit( "#posp em", "#posp a em:last", true ); + isit( "#posp em", "#posp a em:eq(2)", false ); + + html.remove(); +}); + +test("index()", function() { + expect( 2 ); + + equal( jQuery("#text2").index(), 2, "Returns the index of a child amongst its siblings" ); + + equal( jQuery("<div/>").index(), -1, "Node without parent returns -1" ); +}); + +test("index(Object|String|undefined)", function() { + expect(16); + + var elements = jQuery([window, document]), + inputElements = jQuery("#radio1,#radio2,#check1,#check2"); + + // Passing a node + equal( elements.index(window), 0, "Check for index of elements" ); + equal( elements.index(document), 1, "Check for index of elements" ); + equal( inputElements.index(document.getElementById("radio1")), 0, "Check for index of elements" ); + equal( inputElements.index(document.getElementById("radio2")), 1, "Check for index of elements" ); + equal( inputElements.index(document.getElementById("check1")), 2, "Check for index of elements" ); + equal( inputElements.index(document.getElementById("check2")), 3, "Check for index of elements" ); + equal( inputElements.index(window), -1, "Check for not found index" ); + equal( inputElements.index(document), -1, "Check for not found index" ); + + // Passing a jQuery object + // enabled since [5500] + equal( elements.index( elements ), 0, "Pass in a jQuery object" ); + equal( elements.index( elements.eq(1) ), 1, "Pass in a jQuery object" ); + equal( jQuery("#form :radio").index( jQuery("#radio2") ), 1, "Pass in a jQuery object" ); + + // Passing a selector or nothing + // enabled since [6330] + equal( jQuery("#text2").index(), 2, "Check for index amongst siblings" ); + equal( jQuery("#form").children().eq(4).index(), 4, "Check for index amongst siblings" ); + equal( jQuery("#radio2").index("#form :radio") , 1, "Check for index within a selector" ); + equal( jQuery("#form :radio").index( jQuery("#radio2") ), 1, "Check for index within a selector" ); + equal( jQuery("#radio2").index("#form :text") , -1, "Check for index not found within a selector" ); +}); + +test("filter(Selector|undefined)", function() { + expect(9); + deepEqual( jQuery("#form input").filter(":checked").get(), q("radio2", "check1"), "filter(String)" ); + deepEqual( jQuery("p").filter("#ap, #sndp").get(), q("ap", "sndp"), "filter('String, String')" ); + deepEqual( jQuery("p").filter("#ap,#sndp").get(), q("ap", "sndp"), "filter('String,String')" ); + + deepEqual( jQuery("p").filter(null).get(), [], "filter(null) should return an empty jQuery object"); + deepEqual( jQuery("p").filter(undefined).get(), [], "filter(undefined) should return an empty jQuery object"); + deepEqual( jQuery("p").filter(0).get(), [], "filter(0) should return an empty jQuery object"); + deepEqual( jQuery("p").filter("").get(), [], "filter('') should return an empty jQuery object"); + + // using contents will get comments regular, text, and comment nodes + var j = jQuery("#nonnodes").contents(); + equal( j.filter("span").length, 1, "Check node,textnode,comment to filter the one span" ); + equal( j.filter("[name]").length, 0, "Check node,textnode,comment to filter the one span" ); +}); + +test("filter(Function)", function() { + expect(2); + + deepEqual( jQuery("#qunit-fixture p").filter(function() { return !jQuery("a", this).length }).get(), q("sndp", "first"), "filter(Function)" ); + + deepEqual( 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() { + expect(1); + + var element = document.getElementById("text1"); + deepEqual( jQuery("#form input").filter(element).get(), q("text1"), "filter(Element)" ); +}); + +test("filter(Array)", function() { + expect(1); + + var elements = [ document.getElementById("text1") ]; + deepEqual( jQuery("#form input").filter(elements).get(), q("text1"), "filter(Element)" ); +}); + +test("filter(jQuery)", function() { + expect(1); + + var elements = jQuery("#text1"); + deepEqual( jQuery("#form input").filter(elements).get(), q("text1"), "filter(Element)" ); +}); + + +test("filter() with positional selectors", function() { + expect(19); + + var html = jQuery('' + + '<p id="posp">' + + '<a class="firsta" href="#">' + + '<em>first</em>' + + '</a>' + + '<a class="seconda" href="#">' + + '<b>test</b>' + + '</a>' + + '<em></em>' + + '</p>').appendTo( "body" ), + filterit = function(sel, filter, length) { + equal( jQuery( sel ).filter( filter ).length, length, "jQuery( " + sel + " ).filter( " + filter + " )" ); + }; + + filterit( "#posp", "#posp:first", 1); + filterit( "#posp", "#posp:eq(2)", 0 ); + filterit( "#posp", "#posp a:first", 0 ); + + // Keep in mind this is within the selection and + // not in relation to other elements (.is() is a different story) + filterit( "#posp .firsta", "#posp a:first", 1 ); + filterit( "#posp .firsta", "#posp a:last", 1 ); + filterit( "#posp .firsta", "#posp a:last-child", 0 ); + filterit( "#posp .firsta", "#posp a:even", 1 ); + filterit( "#posp .firsta", "#posp a:odd", 0 ); + filterit( "#posp .firsta", "#posp a:eq(0)", 1 ); + filterit( "#posp .firsta", "#posp a:eq(9)", 0 ); + filterit( "#posp .firsta", "#posp em:eq(0)", 0 ); + filterit( "#posp .firsta", "#posp em:first", 0 ); + filterit( "#posp .firsta", "#posp:first", 0 ); + + filterit( "#posp .seconda", "#posp a:first", 1 ); + filterit( "#posp .seconda", "#posp em:first", 0 ); + filterit( "#posp .seconda", "#posp a:last", 1 ); + filterit( "#posp .seconda", "#posp a:gt(0)", 0 ); + filterit( "#posp .seconda", "#posp a:lt(5)", 1 ); + filterit( "#posp .seconda", "#posp a:lt(1)", 1 ); + html.remove(); +}); + +test("closest()", function() { + expect(13); + deepEqual( jQuery("body").closest("body").get(), q("body"), "closest(body)" ); + deepEqual( jQuery("body").closest("html").get(), q("html"), "closest(html)" ); + deepEqual( jQuery("body").closest("div").get(), [], "closest(div)" ); + deepEqual( jQuery("#qunit-fixture").closest("span,#html").get(), q("html"), "closest(span,#html)" ); + + deepEqual( jQuery("div:eq(1)").closest("div:first").get(), [], "closest(div:first)" ); + deepEqual( jQuery("div").closest("body:first div:last").get(), q("fx-tests"), "closest(body:first div:last)" ); + + // Test .closest() limited by the context + var jq = jQuery("#nothiddendivchild"); + deepEqual( jq.closest("html", document.body).get(), [], "Context limited." ); + deepEqual( jq.closest("body", document.body).get(), [], "Context limited." ); + deepEqual( jq.closest("#nothiddendiv", document.body).get(), q("nothiddendiv"), "Context not reached." ); + + //Test that .closest() returns unique'd set + equal( jQuery("#qunit-fixture p").closest("#qunit-fixture").length, 1, "Closest should return a unique set" ); + + // Test on disconnected node + equal( jQuery("<div><p></p></div>").find("p").closest("table").length, 0, "Make sure disconnected closest work." ); + + // Bug #7369 + equal( jQuery("<div foo='bar'></div>").closest("[foo]").length, 1, "Disconnected nodes with attribute selector" ); + equal( jQuery("<div>text</div>").closest("[lang]").length, 0, "Disconnected nodes with text and non-existent attribute selector" ); +}); + +test("closest(Array)", function() { + expect(7); + deepEqual( jQuery("body").closest(["body"]), [{selector:"body", elem:document.body, level:1}], "closest([body])" ); + deepEqual( jQuery("body").closest(["html"]), [{selector:"html", elem:document.documentElement, level:2}], "closest([html])" ); + deepEqual( jQuery("body").closest(["div"]), [], "closest([div])" ); + deepEqual( jQuery("#yahoo").closest(["div"]), [{"selector":"div", "elem": document.getElementById("foo"), "level": 3}, { "selector": "div", "elem": document.getElementById("qunit-fixture"), "level": 4 }], "closest([div])" ); + deepEqual( jQuery("#qunit-fixture").closest(["span,#html"]), [{selector:"span,#html", elem:document.documentElement, level:4}], "closest([span,#html])" ); + + deepEqual( jQuery("body").closest(["body","html"]), [{selector:"body", elem:document.body, level:1}, {selector:"html", elem:document.documentElement, level:2}], "closest([body, html])" ); + deepEqual( jQuery("body").closest(["span","html"]), [{selector:"html", elem:document.documentElement, level:2}], "closest([body, html])" ); +}); + +test("closest(jQuery)", function() { + expect(8); + var $child = jQuery("#nothiddendivchild"), + $parent = jQuery("#nothiddendiv"), + $main = jQuery("#qunit-fixture"), + $body = jQuery("body"); + ok( $child.closest( $parent ).is("#nothiddendiv"), "closest( jQuery('#nothiddendiv') )" ); + ok( $child.closest( $parent[0] ).is("#nothiddendiv"), "closest( jQuery('#nothiddendiv') ) :: node" ); + ok( $child.closest( $child ).is("#nothiddendivchild"), "child is included" ); + ok( $child.closest( $child[0] ).is("#nothiddendivchild"), "child is included :: node" ); + equal( $child.closest( document.createElement("div") ).length, 0, "created element is not related" ); + equal( $child.closest( $main ).length, 0, "Main not a parent of child" ); + equal( $child.closest( $main[0] ).length, 0, "Main not a parent of child :: node" ); + ok( $child.closest( $body.add($parent) ).is("#nothiddendiv"), "Closest ancestor retrieved." ); +}); + +test("not(Selector|undefined)", function() { + expect(11); + equal( jQuery("#qunit-fixture > p#ap > a").not("#google").length, 2, "not('selector')" ); + deepEqual( jQuery("p").not(".result").get(), q("firstp", "ap", "sndp", "en", "sap", "first"), "not('.class')" ); + deepEqual( jQuery("p").not("#ap, #sndp, .result").get(), q("firstp", "en", "sap", "first"), "not('selector, selector')" ); + deepEqual( jQuery("#form option").not("option.emptyopt:contains('Nothing'),[selected],[value='1']").get(), q("option1c", "option1d", "option2c", "option3d", "option3e", "option4e","option5b"), "not('complex selector')"); + + deepEqual( jQuery("#ap *").not("code").get(), q("google", "groups", "anchor1", "mark"), "not('tag selector')" ); + deepEqual( jQuery("#ap *").not("code, #mark").get(), q("google", "groups", "anchor1"), "not('tag, ID selector')" ); + deepEqual( jQuery("#ap *").not("#mark, code").get(), q("google", "groups", "anchor1"), "not('ID, tag selector')"); + + var all = jQuery("p").get(); + deepEqual( jQuery("p").not(null).get(), all, "not(null) should have no effect"); + deepEqual( jQuery("p").not(undefined).get(), all, "not(undefined) should have no effect"); + deepEqual( jQuery("p").not(0).get(), all, "not(0) should have no effect"); + deepEqual( jQuery("p").not("").get(), all, "not('') should have no effect"); +}); + +test("not(Element)", function() { + expect(1); + + var selects = jQuery("#form select"); + deepEqual( selects.not( selects[1] ).get(), q("select1", "select3", "select4", "select5"), "filter out DOM element"); +}); + +test("not(Function)", function() { + deepEqual( jQuery("#qunit-fixture p").not(function() { return jQuery("a", this).length }).get(), q("sndp", "first"), "not(Function)" ); +}); + +test("not(Array)", function() { + expect(2); + + equal( jQuery("#qunit-fixture > p#ap > a").not(document.getElementById("google")).length, 2, "not(DOMElement)" ); + equal( jQuery("p").not(document.getElementsByTagName("p")).length, 0, "not(Array-like DOM collection)" ); +}); + +test("not(jQuery)", function() { + expect(1); + + deepEqual( jQuery("p").not(jQuery("#ap, #sndp, .result")).get(), q("firstp", "en", "sap", "first"), "not(jQuery)" ); +}); + +test("has(Element)", function() { + expect(2); + + var obj = jQuery("#qunit-fixture").has(jQuery("#sndp")[0]); + deepEqual( obj.get(), q("qunit-fixture"), "Keeps elements that have the element as a descendant" ); + + var multipleParent = jQuery("#qunit-fixture, #header").has(jQuery("#sndp")[0]); + deepEqual( obj.get(), q("qunit-fixture"), "Does not include elements that do not have the element as a descendant" ); +}); + +test("has(Selector)", function() { + expect(3); + + var obj = jQuery("#qunit-fixture").has("#sndp"); + deepEqual( obj.get(), q("qunit-fixture"), "Keeps elements that have any element matching the selector as a descendant" ); + + var multipleParent = jQuery("#qunit-fixture, #header").has("#sndp"); + deepEqual( obj.get(), q("qunit-fixture"), "Does not include elements that do not have the element as a descendant" ); + + var multipleHas = jQuery("#qunit-fixture").has("#sndp, #first"); + deepEqual( multipleHas.get(), q("qunit-fixture"), "Only adds elements once" ); +}); + +test("has(Arrayish)", function() { + expect(3); + + var simple = jQuery("#qunit-fixture").has(jQuery("#sndp")); + deepEqual( simple.get(), q("qunit-fixture"), "Keeps elements that have any element in the jQuery list as a descendant" ); + + var multipleParent = jQuery("#qunit-fixture, #header").has(jQuery("#sndp")); + deepEqual( 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("#qunit-fixture").has(jQuery("#sndp, #first")); + deepEqual( simple.get(), q("qunit-fixture"), "Only adds elements once" ); +}); + +test("andSelf()", function() { + expect(4); + deepEqual( jQuery("#en").siblings().andSelf().get(), q("sndp", "en", "sap"), "Check for siblings and self" ); + deepEqual( jQuery("#foo").children().andSelf().get(), q("foo", "sndp", "en", "sap"), "Check for children and self" ); + deepEqual( jQuery("#sndp, #en").parent().andSelf().get(), q("foo","sndp","en"), "Check for parent and self" ); + deepEqual( jQuery("#groups").parents("p, div").andSelf().get(), q("qunit-fixture", "ap", "groups"), "Check for parents and self" ); +}); + +test("siblings([String])", function() { + expect(6); + deepEqual( jQuery("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" ); + deepEqual( jQuery("#sndp").siblings(":has(code)").get(), q("sap"), "Check for filtered siblings (has code child element)" ); + deepEqual( jQuery("#sndp").siblings(":has(a)").get(), q("en", "sap"), "Check for filtered siblings (has anchor child element)" ); + deepEqual( jQuery("#foo").siblings("form, b").get(), q("form", "floatTest", "lengthtest", "name-tests", "testForm"), "Check for multiple filters" ); + var set = q("sndp", "en", "sap"); + deepEqual( jQuery("#en, #sndp").siblings().get(), set, "Check for unique results from siblings" ); + deepEqual( jQuery("#option5a").siblings("option[data-attr]").get(), q("option5c"), "Has attribute selector in siblings (#9261)" ); +}); + +test("children([String])", function() { + expect(3); + deepEqual( jQuery("#foo").children().get(), q("sndp", "en", "sap"), "Check for children" ); + deepEqual( jQuery("#foo").children(":has(code)").get(), q("sndp", "sap"), "Check for filtered children" ); + deepEqual( jQuery("#foo").children("#en, #sap").get(), q("en", "sap"), "Check for multiple filters" ); +}); + +test("parent([String])", function() { + expect(5); + equal( jQuery("#groups").parent()[0].id, "ap", "Simple parent check" ); + equal( jQuery("#groups").parent("p")[0].id, "ap", "Filtered parent check" ); + equal( jQuery("#groups").parent("div").length, 0, "Filtered parent check, no match" ); + equal( jQuery("#groups").parent("div, p")[0].id, "ap", "Check for multiple filters" ); + deepEqual( jQuery("#en, #sndp").parent().get(), q("foo"), "Check for unique results from parent" ); +}); + +test("parents([String])", function() { + expect(5); + equal( jQuery("#groups").parents()[0].id, "ap", "Simple parents check" ); + equal( jQuery("#groups").parents("p")[0].id, "ap", "Filtered parents check" ); + equal( jQuery("#groups").parents("div")[0].id, "qunit-fixture", "Filtered parents check2" ); + deepEqual( jQuery("#groups").parents("p, div").get(), q("ap", "qunit-fixture"), "Check for multiple filters" ); + deepEqual( jQuery("#en, #sndp").parents().get(), q("foo", "qunit-fixture", "dl", "body", "html"), "Check for unique results from parents" ); +}); + +test("parentsUntil([String])", function() { + expect(9); + + var parents = jQuery("#groups").parents(); + + deepEqual( jQuery("#groups").parentsUntil().get(), parents.get(), "parentsUntil with no selector (nextAll)" ); + deepEqual( jQuery("#groups").parentsUntil(".foo").get(), parents.get(), "parentsUntil with invalid selector (nextAll)" ); + deepEqual( jQuery("#groups").parentsUntil("#html").get(), parents.not(":last").get(), "Simple parentsUntil check" ); + equal( jQuery("#groups").parentsUntil("#ap").length, 0, "Simple parentsUntil check" ); + deepEqual( jQuery("#groups").parentsUntil("#html, #body").get(), parents.slice( 0, 3 ).get(), "Less simple parentsUntil check" ); + deepEqual( jQuery("#groups").parentsUntil("#html", "div").get(), jQuery("#qunit-fixture").get(), "Filtered parentsUntil check" ); + deepEqual( jQuery("#groups").parentsUntil("#html", "p,div,dl").get(), parents.slice( 0, 3 ).get(), "Multiple-filtered parentsUntil check" ); + equal( jQuery("#groups").parentsUntil("#html", "span").length, 0, "Filtered parentsUntil check, no match" ); + deepEqual( jQuery("#groups, #ap").parentsUntil("#html", "p,div,dl").get(), parents.slice( 0, 3 ).get(), "Multi-source, multiple-filtered parentsUntil check" ); +}); + +test("next([String])", function() { + expect(4); + equal( jQuery("#ap").next()[0].id, "foo", "Simple next check" ); + equal( jQuery("#ap").next("div")[0].id, "foo", "Filtered next check" ); + equal( jQuery("#ap").next("p").length, 0, "Filtered next check, no match" ); + equal( jQuery("#ap").next("div, p")[0].id, "foo", "Multiple filters" ); +}); + +test("prev([String])", function() { + expect(4); + equal( jQuery("#foo").prev()[0].id, "ap", "Simple prev check" ); + equal( jQuery("#foo").prev("p")[0].id, "ap", "Filtered prev check" ); + equal( jQuery("#foo").prev("div").length, 0, "Filtered prev check, no match" ); + equal( jQuery("#foo").prev("p, div")[0].id, "ap", "Multiple filters" ); +}); + +test("nextAll([String])", function() { + expect(4); + + var elems = jQuery("#form").children(); + + deepEqual( jQuery("#label-for").nextAll().get(), elems.not(":first").get(), "Simple nextAll check" ); + deepEqual( jQuery("#label-for").nextAll("input").get(), elems.not(":first").filter("input").get(), "Filtered nextAll check" ); + deepEqual( jQuery("#label-for").nextAll("input,select").get(), elems.not(":first").filter("input,select").get(), "Multiple-filtered nextAll check" ); + deepEqual( jQuery("#label-for, #hidden1").nextAll("input,select").get(), elems.not(":first").filter("input,select").get(), "Multi-source, multiple-filtered nextAll check" ); +}); + +test("prevAll([String])", function() { + expect(4); + + var elems = jQuery( jQuery("#form").children().slice(0, 12).get().reverse() ); + + deepEqual( jQuery("#area1").prevAll().get(), elems.get(), "Simple prevAll check" ); + deepEqual( jQuery("#area1").prevAll("input").get(), elems.filter("input").get(), "Filtered prevAll check" ); + deepEqual( jQuery("#area1").prevAll("input,select").get(), elems.filter("input,select").get(), "Multiple-filtered prevAll check" ); + deepEqual( jQuery("#area1, #hidden1").prevAll("input,select").get(), elems.filter("input,select").get(), "Multi-source, multiple-filtered prevAll check" ); +}); + +test("nextUntil([String])", function() { + expect(11); + + var elems = jQuery("#form").children().slice( 2, 12 ); + + deepEqual( jQuery("#text1").nextUntil().get(), jQuery("#text1").nextAll().get(), "nextUntil with no selector (nextAll)" ); + deepEqual( jQuery("#text1").nextUntil(".foo").get(), jQuery("#text1").nextAll().get(), "nextUntil with invalid selector (nextAll)" ); + deepEqual( jQuery("#text1").nextUntil("#area1").get(), elems.get(), "Simple nextUntil check" ); + equal( jQuery("#text1").nextUntil("#text2").length, 0, "Simple nextUntil check" ); + deepEqual( jQuery("#text1").nextUntil("#area1, #radio1").get(), jQuery("#text1").next().get(), "Less simple nextUntil check" ); + deepEqual( jQuery("#text1").nextUntil("#area1", "input").get(), elems.not("button").get(), "Filtered nextUntil check" ); + deepEqual( jQuery("#text1").nextUntil("#area1", "button").get(), elems.not("input").get(), "Filtered nextUntil check" ); + deepEqual( jQuery("#text1").nextUntil("#area1", "button,input").get(), elems.get(), "Multiple-filtered nextUntil check" ); + equal( jQuery("#text1").nextUntil("#area1", "div").length, 0, "Filtered nextUntil check, no match" ); + deepEqual( jQuery("#text1, #hidden1").nextUntil("#area1", "button,input").get(), elems.get(), "Multi-source, multiple-filtered nextUntil check" ); + + deepEqual( jQuery("#text1").nextUntil("[class=foo]").get(), jQuery("#text1").nextAll().get(), "Non-element nodes must be skipped, since they have no attributes" ); +}); + +test("prevUntil([String])", function() { + expect(10); + + var elems = jQuery("#area1").prevAll(); + + deepEqual( jQuery("#area1").prevUntil().get(), elems.get(), "prevUntil with no selector (prevAll)" ); + deepEqual( jQuery("#area1").prevUntil(".foo").get(), elems.get(), "prevUntil with invalid selector (prevAll)" ); + deepEqual( jQuery("#area1").prevUntil("label").get(), elems.not(":last").get(), "Simple prevUntil check" ); + equal( jQuery("#area1").prevUntil("#button").length, 0, "Simple prevUntil check" ); + deepEqual( jQuery("#area1").prevUntil("label, #search").get(), jQuery("#area1").prev().get(), "Less simple prevUntil check" ); + deepEqual( jQuery("#area1").prevUntil("label", "input").get(), elems.not(":last").not("button").get(), "Filtered prevUntil check" ); + deepEqual( jQuery("#area1").prevUntil("label", "button").get(), elems.not(":last").not("input").get(), "Filtered prevUntil check" ); + deepEqual( jQuery("#area1").prevUntil("label", "button,input").get(), elems.not(":last").get(), "Multiple-filtered prevUntil check" ); + equal( jQuery("#area1").prevUntil("label", "div").length, 0, "Filtered prevUntil check, no match" ); + deepEqual( jQuery("#area1, #hidden1").prevUntil("label", "button,input").get(), elems.not(":last").get(), "Multi-source, multiple-filtered prevUntil check" ); +}); + +test("contents()", function() { + expect(12); + equal( jQuery("#ap").contents().length, 9, "Check element contents" ); + ok( jQuery("#iframe").contents()[0], "Check existance of IFrame document" ); + var ibody = jQuery("#loadediframe").contents()[0].body; + ok( ibody, "Check existance of IFrame body" ); + + equal( jQuery("span", ibody).text(), "span text", "Find span in IFrame and check its text" ); + + jQuery(ibody).append("<div>init text</div>"); + equal( jQuery("div", ibody).length, 2, "Check the original div and the new div are in IFrame" ); + + equal( jQuery("div:last", ibody).text(), "init text", "Add text to div in IFrame" ); + + jQuery("div:last", ibody).text("div text"); + equal( jQuery("div:last", ibody).text(), "div text", "Add text to div in IFrame" ); + + jQuery("div:last", ibody).remove(); + equal( jQuery("div", ibody).length, 1, "Delete the div and check only one div left in IFrame" ); + + equal( jQuery("div", ibody).text(), "span text", "Make sure the correct div is still left after deletion in IFrame" ); + + jQuery("<table/>", ibody).append("<tr><td>cell</td></tr>").appendTo(ibody); + jQuery("table", ibody).remove(); + equal( jQuery("div", ibody).length, 1, "Check for JS error on add and delete of a table in IFrame" ); + + // using contents will get comments regular, text, and comment nodes + var c = jQuery("#nonnodes").contents().contents(); + equal( c.length, 1, "Check node,textnode,comment contents is just one" ); + equal( c[0].nodeValue, "hi", "Check node,textnode,comment contents is just the one from span" ); +}); + +test("add(String|Element|Array|undefined)", function() { + expect(16); + deepEqual( jQuery("#sndp").add("#en").add("#sap").get(), q("sndp", "en", "sap"), "Check elements from document" ); + deepEqual( jQuery("#sndp").add( jQuery("#en")[0] ).add( jQuery("#sap") ).get(), q("sndp", "en", "sap"), "Check elements from document" ); + + // We no longer support .add(form.elements), unfortunately. + // There is no way, in browsers, to reliably determine the difference + // between form.elements and form - and doing .add(form) and having it + // add the form elements is way to unexpected, so this gets the boot. + // ok( jQuery([]).add(jQuery("#form")[0].elements).length >= 13, "Check elements from array" ); + + // For the time being, we're discontinuing support for jQuery(form.elements) since it's ambiguous in IE + // use jQuery([]).add(form.elements) instead. + //equal( 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"); + equal( 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 x = jQuery([]).add(jQuery("<p id='x1'>xxx</p>").appendTo(tmp)).add(jQuery("<p id='x2'>xxx</p>").appendTo(tmp)); + equal( x[0].id, "x1", "Check on-the-fly element1" ); + equal( x[1].id, "x2", "Check on-the-fly element2" ); + + var x = jQuery([]).add(jQuery("<p id='x1'>xxx</p>").appendTo(tmp)[0]).add(jQuery("<p id='x2'>xxx</p>").appendTo(tmp)[0]); + equal( x[0].id, "x1", "Check on-the-fly element1" ); + equal( x[1].id, "x2", "Check on-the-fly element2" ); + + var x = jQuery([]).add(jQuery("<p id='x1'>xxx</p>")).add(jQuery("<p id='x2'>xxx</p>")); + equal( x[0].id, "x1", "Check on-the-fly element1" ); + equal( x[1].id, "x2", "Check on-the-fly element2" ); + + var x = jQuery([]).add("<p id='x1'>xxx</p>").add("<p id='x2'>xxx</p>"); + equal( x[0].id, "x1", "Check on-the-fly element1" ); + equal( x[1].id, "x2", "Check on-the-fly element2" ); + + var notDefined; + equal( jQuery([]).add(notDefined).length, 0, "Check that undefined adds nothing" ); + + equal( jQuery([]).add( document.getElementById("form") ).length, 1, "Add a form" ); + equal( jQuery([]).add( document.getElementById("select1") ).length, 1, "Add a select" ); +}); + +test("add(String, Context)", function() { + expect(6); + + deepEqual( jQuery( "#firstp" ).add( "#ap" ).get(), q( "firstp", "ap" ), "Add selector to selector " ); + deepEqual( jQuery( document.getElementById("firstp") ).add( "#ap" ).get(), q( "firstp", "ap" ), "Add gEBId to selector" ); + deepEqual( jQuery( document.getElementById("firstp") ).add( document.getElementById("ap") ).get(), q( "firstp", "ap" ), "Add gEBId to gEBId" ); + + var ctx = document.getElementById("firstp"); + deepEqual( jQuery( "#firstp" ).add( "#ap", ctx ).get(), q( "firstp" ), "Add selector to selector " ); + deepEqual( jQuery( document.getElementById("firstp") ).add( "#ap", ctx ).get(), q( "firstp" ), "Add gEBId to selector, not in context" ); + deepEqual( jQuery( document.getElementById("firstp") ).add( "#ap", document.getElementsByTagName("body")[0] ).get(), q( "firstp", "ap" ), "Add gEBId to selector, in context" ); +}); + +test("eq('-1') #10616", function() { + expect(3); + var $divs = jQuery( "div" ); + + equal( $divs.eq( -1 ).length, 1, "The number -1 returns a selection that has length 1" ); + equal( $divs.eq( "-1" ).length, 1, "The string '-1' returns a selection that has length 1" ); + deepEqual( $divs.eq( "-1" ), $divs.eq( -1 ), "String and number -1 match" ); +}); + |
