3 test("Basic requirements", function() {
\r
5 ok( Array.prototype.push, "Array.push()" );
\r
6 ok( Function.prototype.apply, "Function.apply()" );
\r
7 ok( document.getElementById, "getElementById" );
\r
8 ok( document.getElementsByTagName, "getElementsByTagName" );
\r
9 ok( RegExp, "RegExp" );
\r
10 ok( jQuery, "jQuery" );
\r
14 test("$()", function() {
\r
17 var main = $("#main");
\r
18 isSet( $("div p", main).get(), q("sndp", "en", "sap"), "Basic selector with jQuery object as context" );
\r
21 // disabled since this test was doing nothing. i tried to fix it but i'm not sure
\r
22 // what the expected behavior should even be. FF returns "\n" for the text node
\r
23 // make sure this is handled
\r
24 var crlfContainer = $('<p>\r\n</p>');
\r
25 var x = crlfContainer.contents().get(0).nodeValue;
\r
26 equals( x, what???, "Check for \\r and \\n in jQuery()" );
\r
29 /* // Disabled until we add this functionality in
\r
32 $("<div>Testing</div>").appendTo(document.getElementById("iframe").contentDocument.body);
\r
36 ok( pass, "$('<tag>') needs optional document parameter to ease cross-frame DOM wrangling, see #968" );*/
\r
38 var code = $("<code/>");
\r
39 equals( code.length, 1, "Correct number of elements generated for code" );
\r
40 var img = $("<img/>");
\r
41 equals( img.length, 1, "Correct number of elements generated for img" );
\r
42 var div = $("<div/><hr/><code/><b/>");
\r
43 equals( div.length, 4, "Correct number of elements generated for div hr code b" );
\r
46 test("browser", function() {
\r
50 "Mozilla/5.0 (Windows; U; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)": "6.0",
\r
51 "Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 5.1; .NET CLR 1.1.4322; InfoPath.1; .NET CLR 2.0.50727)": "7.0",
\r
53 * "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 2.0.50727; .NET CLR 1.1.4322; .NET CLR 3.0.04506.30)": "7.0",
\r
55 //Browsers with Gecko engine
\r
57 "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.12) Gecko/20050915" : "1.7.12",
\r
59 "Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3": "1.8.1.3",
\r
61 "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20070321 Netscape/8.1.3" : "1.7.5",
\r
63 "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.11) Gecko/20070321 Firefox/1.5.0.11 Flock/0.7.12" : "1.8.0.11",
\r
65 "Opera/9.20 (X11; Linux x86_64; U; en)": "9.20",
\r
66 "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; en) Opera 9.20" : "9.20",
\r
67 "Mozilla/5.0 (Windows NT 5.1; U; pl; rv:1.8.0) Gecko/20060728 Firefox/1.5.0 Opera 9.20": "9.20",
\r
69 "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; sv-se) AppleWebKit/418.9 (KHTML, like Gecko) Safari/419.3": "418.9",
\r
70 "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/418.8 (KHTML, like Gecko) Safari/419.3" : "418.8",
\r
71 "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; sv-se) AppleWebKit/312.8 (KHTML, like Gecko) Safari/312.5": "312.8",
\r
72 //Other user agent string
\r
73 "Other browser's user agent 1.0":null
\r
75 for (var i in browsers) {
\r
76 var v = i.toLowerCase().match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ); // RegEx from Core jQuery.browser.version check
\r
77 version = v ? v[1] : null;
\r
78 equals( version, browsers[i], "Checking UA string" );
\r
82 test("noConflict", function() {
\r
86 var newjQuery = jQuery.noConflict();
\r
88 ok( newjQuery == old, "noConflict returned the jQuery object" );
\r
89 ok( jQuery == old, "Make sure jQuery wasn't touched." );
\r
90 ok( $ == "$", "Make sure $ was reverted." );
\r
94 newjQuery = jQuery.noConflict(true);
\r
96 ok( newjQuery == old, "noConflict returned the jQuery object" );
\r
97 ok( jQuery == "jQuery", "Make sure jQuery was reverted." );
\r
98 ok( $ == "$", "Make sure $ was reverted." );
\r
103 test("isFunction", function() {
\r
106 // Make sure that false values return false
\r
107 ok( !jQuery.isFunction(), "No Value" );
\r
108 ok( !jQuery.isFunction( null ), "null Value" );
\r
109 ok( !jQuery.isFunction( undefined ), "undefined Value" );
\r
110 ok( !jQuery.isFunction( "" ), "Empty String Value" );
\r
111 ok( !jQuery.isFunction( 0 ), "0 Value" );
\r
114 // Safari uses "(Internal Function)"
\r
115 ok( jQuery.isFunction(String), "String Function" );
\r
116 ok( jQuery.isFunction(Array), "Array Function" );
\r
117 ok( jQuery.isFunction(Object), "Object Function" );
\r
118 ok( jQuery.isFunction(Function), "Function Function" );
\r
120 // When stringified, this could be misinterpreted
\r
121 var mystr = "function";
\r
122 ok( !jQuery.isFunction(mystr), "Function String" );
\r
124 // When stringified, this could be misinterpreted
\r
125 var myarr = [ "function" ];
\r
126 ok( !jQuery.isFunction(myarr), "Function Array" );
\r
128 // When stringified, this could be misinterpreted
\r
129 var myfunction = { "function": "test" };
\r
130 ok( !jQuery.isFunction(myfunction), "Function Object" );
\r
132 // Make sure normal functions still work
\r
133 var fn = function(){};
\r
134 ok( jQuery.isFunction(fn), "Normal Function" );
\r
136 var obj = document.createElement("object");
\r
138 // Firefox says this is a function
\r
139 ok( !jQuery.isFunction(obj), "Object Element" );
\r
141 // IE says this is an object
\r
142 ok( jQuery.isFunction(obj.getAttribute), "getAttribute Function" );
\r
144 var nodes = document.body.childNodes;
\r
146 // Safari says this is a function
\r
147 ok( !jQuery.isFunction(nodes), "childNodes Property" );
\r
149 var first = document.body.firstChild;
\r
151 // Normal elements are reported ok everywhere
\r
152 ok( !jQuery.isFunction(first), "A normal DOM Element" );
\r
154 var input = document.createElement("input");
\r
155 input.type = "text";
\r
156 document.body.appendChild( input );
\r
158 // IE says this is an object
\r
159 ok( jQuery.isFunction(input.focus), "A default function property" );
\r
161 document.body.removeChild( input );
\r
163 var a = document.createElement("a");
\r
164 a.href = "some-function";
\r
165 document.body.appendChild( a );
\r
167 // This serializes with the word 'function' in it
\r
168 ok( !jQuery.isFunction(a), "Anchor Element" );
\r
170 document.body.removeChild( a );
\r
172 // Recursive function calls have lengths and array-like properties
\r
173 function callme(callback){
\r
174 function fn(response){
\r
175 callback(response);
\r
178 ok( jQuery.isFunction(fn), "Recursive Function Call" );
\r
180 fn({ some: "data" });
\r
184 callme(function(){});
\r
190 test("$('html')", function() {
\r
195 var s = $("<script>var foo='test';</script>")[0];
\r
196 ok( s, "Creating a script" );
\r
197 ok( !foo, "Make sure the script wasn't executed prematurely" );
\r
198 $("body").append(s);
\r
199 ok( foo, "Executing a scripts contents in the right context" );
\r
202 ok( $("<link rel='stylesheet'/>")[0], "Creating a link" );
\r
206 var j = $("<span>hi</span> there <!-- mon ami -->");
\r
207 ok( j.length >= 2, "Check node,textnode,comment creation (some browsers delete comments)" );
\r
209 ok( !$("<option>test</option>")[0].selected, "Make sure that options are auto-selected #2050" );
\r
212 test("$('html', context)", function() {
\r
215 var $div = $("<div/>");
\r
216 var $span = $("<span/>", $div);
\r
217 equals($span.length, 1, "Verify a span created with a div context works, #1763");
\r
221 test("$(selector, xml).text(str) - Loaded via XML document", function() {
\r
224 $.get('data/dashboard.xml', function(xml) {
\r
225 // tests for #1419 where IE was a problem
\r
226 equals( $("tab:first", xml).text(), "blabla", "Verify initial text correct" );
\r
227 $("tab:first", xml).text("newtext");
\r
228 equals( $("tab:first", xml).text(), "newtext", "Verify new text correct" );
\r
234 test("length", function() {
\r
236 ok( $("p").length == 6, "Get Number of Elements Found" );
\r
239 test("size()", function() {
\r
241 ok( $("p").size() == 6, "Get Number of Elements Found" );
\r
244 test("get()", function() {
\r
246 isSet( $("p").get(), q("firstp","ap","sndp","en","sap","first"), "Get All Elements" );
\r
249 test("get(Number)", function() {
\r
251 ok( $("p").get(0) == document.getElementById("firstp"), "Get A Single Element" );
\r
254 test("add(String|Element|Array|undefined)", function() {
\r
256 isSet( $("#sndp").add("#en").add("#sap").get(), q("sndp", "en", "sap"), "Check elements from document" );
\r
257 isSet( $("#sndp").add( $("#en")[0] ).add( $("#sap") ).get(), q("sndp", "en", "sap"), "Check elements from document" );
\r
258 ok( $([]).add($("#form")[0].elements).length >= 13, "Check elements from array" );
\r
260 // For the time being, we're discontinuing support for $(form.elements) since it's ambiguous in IE
\r
261 // use $([]).add(form.elements) instead.
\r
262 //equals( $([]).add($("#form")[0].elements).length, $($("#form")[0].elements).length, "Array in constructor must equals array in add()" );
\r
264 var x = $([]).add($("<p id='x1'>xxx</p>")).add($("<p id='x2'>xxx</p>"));
\r
265 ok( x[0].id == "x1", "Check on-the-fly element1" );
\r
266 ok( x[1].id == "x2", "Check on-the-fly element2" );
\r
268 var x = $([]).add("<p id='x1'>xxx</p>").add("<p id='x2'>xxx</p>");
\r
269 ok( x[0].id == "x1", "Check on-the-fly element1" );
\r
270 ok( x[1].id == "x2", "Check on-the-fly element2" );
\r
273 equals( $([]).add(notDefined).length, 0, "Check that undefined adds nothing." );
\r
276 test("each(Function)", function() {
\r
278 var div = $("div");
\r
279 div.each(function(){this.foo = 'zoo';});
\r
281 for ( var i = 0; i < div.size(); i++ ) {
\r
282 if ( div.get(i).foo != "zoo" ) pass = false;
\r
284 ok( pass, "Execute a function, Relative" );
\r
287 test("index(Object)", function() {
\r
289 ok( $([window, document]).index(window) == 0, "Check for index of elements" );
\r
290 ok( $([window, document]).index(document) == 1, "Check for index of elements" );
\r
291 var inputElements = $('#radio1,#radio2,#check1,#check2');
\r
292 ok( inputElements.index(document.getElementById('radio1')) == 0, "Check for index of elements" );
\r
293 ok( inputElements.index(document.getElementById('radio2')) == 1, "Check for index of elements" );
\r
294 ok( inputElements.index(document.getElementById('check1')) == 2, "Check for index of elements" );
\r
295 ok( inputElements.index(document.getElementById('check2')) == 3, "Check for index of elements" );
\r
296 ok( inputElements.index(window) == -1, "Check for not found index" );
\r
297 ok( inputElements.index(document) == -1, "Check for not found index" );
\r
300 test("attr(String)", function() {
\r
302 ok( $('#text1').attr('value') == "Test", 'Check for value attribute' );
\r
303 ok( $('#text1').attr('value', "Test2").attr('defaultValue') == "Test", 'Check for defaultValue attribute' );
\r
304 ok( $('#text1').attr('type') == "text", 'Check for type attribute' );
\r
305 ok( $('#radio1').attr('type') == "radio", 'Check for type attribute' );
\r
306 ok( $('#check1').attr('type') == "checkbox", 'Check for type attribute' );
\r
307 ok( $('#simon1').attr('rel') == "bookmark", 'Check for rel attribute' );
\r
308 ok( $('#google').attr('title') == "Google!", 'Check for title attribute' );
\r
309 ok( $('#mark').attr('hreflang') == "en", 'Check for hreflang attribute' );
\r
310 ok( $('#en').attr('lang') == "en", 'Check for lang attribute' );
\r
311 ok( $('#simon').attr('class') == "blog link", 'Check for class attribute' );
\r
312 ok( $('#name').attr('name') == "name", 'Check for name attribute' );
\r
313 ok( $('#text1').attr('name') == "action", 'Check for name attribute' );
\r
314 ok( $('#form').attr('action').indexOf("formaction") >= 0, 'Check for action attribute' );
\r
315 ok( $('#text1').attr('maxlength') == '30', 'Check for maxlength attribute' );
\r
316 ok( $('#text1').attr('maxLength') == '30', 'Check for maxLength attribute' );
\r
317 ok( $('#area1').attr('maxLength') == '30', 'Check for maxLength attribute' );
\r
318 ok( $('#select2').attr('selectedIndex') == 3, 'Check for selectedIndex attribute' );
\r
319 ok( $('#foo').attr('nodeName') == 'DIV', 'Check for nodeName attribute' );
\r
320 ok( $('#foo').attr('tagName') == 'DIV', 'Check for tagName attribute' );
\r
322 $('<a id="tAnchor5"></a>').attr('href', '#5').appendTo('#main'); // using innerHTML in IE causes href attribute to be serialized to the full path
\r
323 ok( $('#tAnchor5').attr('href') == "#5", 'Check for non-absolute href (an anchor)' );
\r
327 test("attr(String) in XML Files", function() {
\r
330 $.get("data/dashboard.xml", function(xml) {
\r
331 ok( $("locations", xml).attr("class") == "foo", "Check class attribute in XML document" );
\r
332 ok( $("location", xml).attr("for") == "bar", "Check for attribute in XML document" );
\r
338 test("attr(String, Function)", function() {
\r
340 ok( $('#text1').attr('value', function() { return this.id })[0].value == "text1", "Set value from id" );
\r
341 ok( $('#text1').attr('title', function(i) { return i }).attr('title') == "0", "Set value with an index");
\r
344 test("attr(Hash)", function() {
\r
347 $("div").attr({foo: 'baz', zoo: 'ping'}).each(function(){
\r
348 if ( this.getAttribute('foo') != "baz" && this.getAttribute('zoo') != "ping" ) pass = false;
\r
350 ok( pass, "Set Multiple Attributes" );
\r
353 test("attr(String, Object)", function() {
\r
355 var div = $("div");
\r
356 div.attr("foo", "bar");
\r
358 for ( var i = 0; i < div.size(); i++ ) {
\r
359 if ( div.get(i).getAttribute('foo') != "bar" ) pass = false;
\r
361 ok( pass, "Set Attribute" );
\r
363 ok( $("#foo").attr({"width": null}), "Try to set an attribute to nothing" );
\r
365 $("#name").attr('name', 'something');
\r
366 ok( $("#name").attr('name') == 'something', 'Set name attribute' );
\r
367 $("#check2").attr('checked', true);
\r
368 ok( document.getElementById('check2').checked == true, 'Set checked attribute' );
\r
369 $("#check2").attr('checked', false);
\r
370 ok( document.getElementById('check2').checked == false, 'Set checked attribute' );
\r
371 $("#text1").attr('readonly', true);
\r
372 ok( document.getElementById('text1').readOnly == true, 'Set readonly attribute' );
\r
373 $("#text1").attr('readonly', false);
\r
374 ok( document.getElementById('text1').readOnly == false, 'Set readonly attribute' );
\r
375 $("#name").attr('maxlength', '5');
\r
376 ok( document.getElementById('name').maxLength == '5', 'Set maxlength attribute' );
\r
377 $("#name").attr('maxLength', '10');
\r
378 ok( document.getElementById('name').maxLength == '10', 'Set maxlength attribute' );
\r
381 $("#name").attr('someAttr', '0');
\r
382 equals( $("#name").attr('someAttr'), '0', 'Set attribute to a string of "0"' );
\r
383 $("#name").attr('someAttr', 0);
\r
384 equals( $("#name").attr('someAttr'), 0, 'Set attribute to the number 0' );
\r
385 $("#name").attr('someAttr', 1);
\r
386 equals( $("#name").attr('someAttr'), 1, 'Set attribute to the number 1' );
\r
388 // using contents will get comments regular, text, and comment nodes
\r
389 var j = $("#nonnodes").contents();
\r
391 j.attr("name", "attrvalue");
\r
392 equals( j.attr("name"), "attrvalue", "Check node,textnode,comment for attr" );
\r
393 j.removeAttr("name")
\r
397 var type = $("#check2").attr('type');
\r
398 var thrown = false;
\r
400 $("#check2").attr('type','hidden');
\r
404 ok( thrown, "Exception thrown when trying to change type property" );
\r
405 equals( type, $("#check2").attr('type'), "Verify that you can't change the type of an input element" );
\r
407 var check = document.createElement("input");
\r
410 $(check).attr('type','checkbox');
\r
414 ok( thrown, "Exception thrown when trying to change type property" );
\r
415 equals( "checkbox", $(check).attr('type'), "Verify that you can change the type of an input element that isn't in the DOM" );
\r
419 test("attr(String, Object) - Loaded via XML document", function() {
\r
422 $.get('data/dashboard.xml', function(xml) {
\r
424 $('tab', xml).each(function() {
\r
425 titles.push($(this).attr('title'));
\r
427 equals( titles[0], 'Location', 'attr() in XML context: Check first title' );
\r
428 equals( titles[1], 'Users', 'attr() in XML context: Check second title' );
\r
434 test("css(String|Hash)", function() {
\r
437 ok( $('#main').css("display") == 'none', 'Check for css property "display"');
\r
439 ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
\r
440 $('#foo').css({display: 'none'});
\r
441 ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
\r
442 $('#foo').css({display: 'block'});
\r
443 ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
\r
445 $('#floatTest').css({styleFloat: 'right'});
\r
446 ok( $('#floatTest').css('styleFloat') == 'right', 'Modified CSS float using "styleFloat": Assert float is right');
\r
447 $('#floatTest').css({cssFloat: 'left'});
\r
448 ok( $('#floatTest').css('cssFloat') == 'left', 'Modified CSS float using "cssFloat": Assert float is left');
\r
449 $('#floatTest').css({'float': 'right'});
\r
450 ok( $('#floatTest').css('float') == 'right', 'Modified CSS float using "float": Assert float is right');
\r
451 $('#floatTest').css({'font-size': '30px'});
\r
452 ok( $('#floatTest').css('font-size') == '30px', 'Modified CSS font-size: Assert font-size is 30px');
\r
454 $.each("0,0.25,0.5,0.75,1".split(','), function(i, n) {
\r
455 $('#foo').css({opacity: n});
\r
456 ok( $('#foo').css('opacity') == parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" );
\r
457 $('#foo').css({opacity: parseFloat(n)});
\r
458 ok( $('#foo').css('opacity') == parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" );
\r
460 $('#foo').css({opacity: ''});
\r
461 ok( $('#foo').css('opacity') == '1', "Assert opacity is 1 when set to an empty String" );
\r
464 test("css(String, Object)", function() {
\r
466 ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
\r
467 $('#foo').css('display', 'none');
\r
468 ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
\r
469 $('#foo').css('display', 'block');
\r
470 ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
\r
472 $('#floatTest').css('styleFloat', 'left');
\r
473 ok( $('#floatTest').css('styleFloat') == 'left', 'Modified CSS float using "styleFloat": Assert float is left');
\r
474 $('#floatTest').css('cssFloat', 'right');
\r
475 ok( $('#floatTest').css('cssFloat') == 'right', 'Modified CSS float using "cssFloat": Assert float is right');
\r
476 $('#floatTest').css('float', 'left');
\r
477 ok( $('#floatTest').css('float') == 'left', 'Modified CSS float using "float": Assert float is left');
\r
478 $('#floatTest').css('font-size', '20px');
\r
479 ok( $('#floatTest').css('font-size') == '20px', 'Modified CSS font-size: Assert font-size is 20px');
\r
481 $.each("0,0.25,0.5,0.75,1".split(','), function(i, n) {
\r
482 $('#foo').css('opacity', n);
\r
483 ok( $('#foo').css('opacity') == parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" );
\r
484 $('#foo').css('opacity', parseFloat(n));
\r
485 ok( $('#foo').css('opacity') == parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" );
\r
487 $('#foo').css('opacity', '');
\r
488 ok( $('#foo').css('opacity') == '1', "Assert opacity is 1 when set to an empty String" );
\r
489 // for #1438, IE throws JS error when filter exists but doesn't have opacity in it
\r
490 if (jQuery.browser.msie) {
\r
491 $('#foo').css("filter", "progid:DXImageTransform.Microsoft.Chroma(color='red');");
\r
493 equals( $('#foo').css('opacity'), '1', "Assert opacity is 1 when a different filter is set in IE, #1438" );
\r
495 // using contents will get comments regular, text, and comment nodes
\r
496 var j = $("#nonnodes").contents();
\r
497 j.css("padding-left", "1px");
\r
498 equals( j.css("padding-left"), "1px", "Check node,textnode,comment css works" );
\r
500 // opera sometimes doesn't update 'display' correctly, see #2037
\r
501 $("#t2037")[0].innerHTML = $("#t2037")[0].innerHTML
\r
502 equals( $("#t2037 .hidden").css("display"), "none", "Make sure browser thinks it is hidden" );
\r
505 test("jQuery.css(elem, 'height') doesn't clear radio buttons (bug #1095)", function () {
\r
508 var $checkedtest = $("#checkedtest");
\r
509 // IE6 was clearing "checked" in jQuery.css(elem, "height");
\r
510 jQuery.css($checkedtest[0], "height");
\r
511 ok( !! $(":radio:first", $checkedtest).attr("checked"), "Check first radio still checked." );
\r
512 ok( ! $(":radio:last", $checkedtest).attr("checked"), "Check last radio still NOT checked." );
\r
513 ok( !! $(":checkbox:first", $checkedtest).attr("checked"), "Check first checkbox still checked." );
\r
514 ok( ! $(":checkbox:last", $checkedtest).attr("checked"), "Check last checkbox still NOT checked." );
\r
517 test("width()", function() {
\r
520 var $div = $("#nothiddendiv");
\r
522 equals($div.width(), 30, "Test set to 30 correctly");
\r
523 $div.width(-1); // handle negative numbers by ignoring #1599
\r
524 equals($div.width(), 30, "Test negative width ignored");
\r
525 $div.css("padding", "20px");
\r
526 equals($div.width(), 30, "Test padding specified with pixels");
\r
527 $div.css("border", "2px solid #fff");
\r
528 equals($div.width(), 30, "Test border specified with pixels");
\r
529 $div.css("padding", "2em");
\r
530 equals($div.width(), 30, "Test padding specified with ems");
\r
531 $div.css("border", "1em solid #fff");
\r
532 equals($div.width(), 30, "Test border specified with ems");
\r
533 $div.css("padding", "2%");
\r
534 equals($div.width(), 30, "Test padding specified with percent");
\r
536 equals($div.width(), 30, "Test hidden div");
\r
538 $div.css({ display: "", border: "", padding: "" });
\r
540 $("#nothiddendivchild").css({ padding: "3px", border: "2px solid #fff" });
\r
541 equals($("#nothiddendivchild").width(), 20, "Test child width with border and padding");
\r
542 $("#nothiddendiv, #nothiddendivchild").css({ border: "", padding: "", width: "" });
\r
545 test("height()", function() {
\r
548 var $div = $("#nothiddendiv");
\r
550 equals($div.height(), 30, "Test set to 30 correctly");
\r
551 $div.height(-1); // handle negative numbers by ignoring #1599
\r
552 equals($div.height(), 30, "Test negative height ignored");
\r
553 $div.css("padding", "20px");
\r
554 equals($div.height(), 30, "Test padding specified with pixels");
\r
555 $div.css("border", "2px solid #fff");
\r
556 equals($div.height(), 30, "Test border specified with pixels");
\r
557 $div.css("padding", "2em");
\r
558 equals($div.height(), 30, "Test padding specified with ems");
\r
559 $div.css("border", "1em solid #fff");
\r
560 equals($div.height(), 30, "Test border specified with ems");
\r
561 $div.css("padding", "2%");
\r
562 equals($div.height(), 30, "Test padding specified with percent");
\r
564 equals($div.height(), 30, "Test hidden div");
\r
566 $div.css({ display: "", border: "", padding: "", height: "1px" });
\r
569 test("text()", function() {
\r
571 var expected = "This link has class=\"blog\": Simon Willison's Weblog";
\r
572 ok( $('#sap').text() == expected, 'Check for merged text of more then one element.' );
\r
575 test("wrap(String|Element)", function() {
\r
577 var defaultText = 'Try them out:'
\r
578 var result = $('#first').wrap('<div class="red"><span></span></div>').text();
\r
579 ok( defaultText == result, 'Check for wrapping of on-the-fly html' );
\r
580 ok( $('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
\r
583 var defaultText = 'Try them out:'
\r
584 var result = $('#first').wrap(document.getElementById('empty')).parent();
\r
585 ok( result.is('ol'), 'Check for element wrapping' );
\r
586 ok( result.text() == defaultText, 'Check for element wrapping' );
\r
589 $('#check1').click(function() {
\r
590 var checkbox = this;
\r
591 ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
\r
592 $(checkbox).wrap( '<div id="c1" style="display:none;"></div>' );
\r
593 ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
\r
596 // using contents will get comments regular, text, and comment nodes
\r
597 var j = $("#nonnodes").contents();
\r
599 equals( $("#nonnodes > i").length, 3, "Check node,textnode,comment wraps ok" );
\r
600 equals( $("#nonnodes > i").text(), j.text() + j[1].nodeValue, "Check node,textnode,comment wraps doesn't hurt text" );
\r
603 test("wrapAll(String|Element)", function() {
\r
605 var prev = $("#first")[0].previousSibling;
\r
606 var p = $("#first")[0].parentNode;
\r
607 var result = $('#first,#firstp').wrapAll('<div class="red"><div id="tmp"></div></div>');
\r
608 equals( result.parent().length, 1, 'Check for wrapping of on-the-fly html' );
\r
609 ok( $('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
\r
610 ok( $('#firstp').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
\r
611 equals( $("#first").parent().parent()[0].previousSibling, prev, "Correct Previous Sibling" );
\r
612 equals( $("#first").parent().parent()[0].parentNode, p, "Correct Parent" );
\r
615 var prev = $("#first")[0].previousSibling;
\r
616 var p = $("#first")[0].parentNode;
\r
617 var result = $('#first,#firstp').wrapAll(document.getElementById('empty'));
\r
618 equals( $("#first").parent()[0], $("#firstp").parent()[0], "Same Parent" );
\r
619 equals( $("#first").parent()[0].previousSibling, prev, "Correct Previous Sibling" );
\r
620 equals( $("#first").parent()[0].parentNode, p, "Correct Parent" );
\r
623 test("wrapInner(String|Element)", function() {
\r
625 var num = $("#first").children().length;
\r
626 var result = $('#first').wrapInner('<div class="red"><div id="tmp"></div></div>');
\r
627 equals( $("#first").children().length, 1, "Only one child" );
\r
628 ok( $("#first").children().is(".red"), "Verify Right Element" );
\r
629 equals( $("#first").children().children().children().length, num, "Verify Elements Intact" );
\r
632 var num = $("#first").children().length;
\r
633 var result = $('#first').wrapInner(document.getElementById('empty'));
\r
634 equals( $("#first").children().length, 1, "Only one child" );
\r
635 ok( $("#first").children().is("#empty"), "Verify Right Element" );
\r
636 equals( $("#first").children().children().length, num, "Verify Elements Intact" );
\r
639 test("append(String|Element|Array<Element>|jQuery)", function() {
\r
641 var defaultText = 'Try them out:'
\r
642 var result = $('#first').append('<b>buga</b>');
\r
643 ok( result.text() == defaultText + 'buga', 'Check if text appending works' );
\r
644 ok( $('#select3').append('<option value="appendTest">Append Test</option>').find('option:last-child').attr('value') == 'appendTest', 'Appending html options to select element');
\r
647 var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
\r
648 $('#sap').append(document.getElementById('first'));
\r
649 ok( expected == $('#sap').text(), "Check for appending of element" );
\r
652 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
\r
653 $('#sap').append([document.getElementById('first'), document.getElementById('yahoo')]);
\r
654 ok( expected == $('#sap').text(), "Check for appending of array of elements" );
\r
657 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
\r
658 $('#sap').append($("#first, #yahoo"));
\r
659 ok( expected == $('#sap').text(), "Check for appending of jQuery object" );
\r
662 $("#sap").append( 5 );
\r
663 ok( $("#sap")[0].innerHTML.match( /5$/ ), "Check for appending a number" );
\r
666 $("#sap").append( " text with spaces " );
\r
667 ok( $("#sap")[0].innerHTML.match(/ text with spaces $/), "Check for appending text with spaces" );
\r
670 ok( $("#sap").append([]), "Check for appending an empty array." );
\r
671 ok( $("#sap").append(""), "Check for appending an empty string." );
\r
672 ok( $("#sap").append(document.getElementsByTagName("foo")), "Check for appending an empty nodelist." );
\r
675 $("#sap").append(document.getElementById('form'));
\r
676 ok( $("#sap>form").size() == 1, "Check for appending a form" ); // Bug #910
\r
681 $( $("#iframe")[0].contentWindow.document.body ).append("<div>test</div>");
\r
686 ok( pass, "Test for appending a DOM node to the contents of an IFrame" );
\r
689 $('<fieldset/>').appendTo('#form').append('<legend id="legend">test</legend>');
\r
690 t( 'Append legend', '#legend', ['legend'] );
\r
693 $('#select1').append('<OPTION>Test</OPTION>');
\r
694 ok( $('#select1 option:last').text() == "Test", "Appending <OPTION> (all caps)" );
\r
696 $('#table').append('<colgroup></colgroup>');
\r
697 ok( $('#table colgroup').length, "Append colgroup" );
\r
699 $('#table colgroup').append('<col/>');
\r
700 ok( $('#table colgroup col').length, "Append col" );
\r
703 $('#table').append('<caption></caption>');
\r
704 ok( $('#table caption').length, "Append caption" );
\r
708 .append('<select id="appendSelect1"></select>')
\r
709 .append('<select id="appendSelect2"><option>Test</option></select>');
\r
711 t( "Append Select", "#appendSelect1, #appendSelect2", ["appendSelect1", "appendSelect2"] );
\r
713 // using contents will get comments regular, text, and comment nodes
\r
714 var j = $("#nonnodes").contents();
\r
715 var d = $("<div/>").appendTo("#nonnodes").append(j);
\r
716 equals( $("#nonnodes").length, 1, "Check node,textnode,comment append moved leaving just the div" );
\r
717 ok( d.contents().length >= 2, "Check node,textnode,comment append works" );
\r
718 d.contents().appendTo("#nonnodes");
\r
720 ok( $("#nonnodes").contents().length >= 2, "Check node,textnode,comment append cleanup worked" );
\r
723 test("appendTo(String|Element|Array<Element>|jQuery)", function() {
\r
725 var defaultText = 'Try them out:'
\r
726 $('<b>buga</b>').appendTo('#first');
\r
727 ok( $("#first").text() == defaultText + 'buga', 'Check if text appending works' );
\r
728 ok( $('<option value="appendTest">Append Test</option>').appendTo('#select3').parent().find('option:last-child').attr('value') == 'appendTest', 'Appending html options to select element');
\r
731 var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
\r
732 $(document.getElementById('first')).appendTo('#sap');
\r
733 ok( expected == $('#sap').text(), "Check for appending of element" );
\r
736 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
\r
737 $([document.getElementById('first'), document.getElementById('yahoo')]).appendTo('#sap');
\r
738 ok( expected == $('#sap').text(), "Check for appending of array of elements" );
\r
741 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
\r
742 $("#first, #yahoo").appendTo('#sap');
\r
743 ok( expected == $('#sap').text(), "Check for appending of jQuery object" );
\r
746 $('#select1').appendTo('#foo');
\r
747 t( 'Append select', '#foo select', ['select1'] );
\r
750 test("prepend(String|Element|Array<Element>|jQuery)", function() {
\r
752 var defaultText = 'Try them out:'
\r
753 var result = $('#first').prepend('<b>buga</b>');
\r
754 ok( result.text() == 'buga' + defaultText, 'Check if text prepending works' );
\r
755 ok( $('#select3').prepend('<option value="prependTest">Prepend Test</option>').find('option:first-child').attr('value') == 'prependTest', 'Prepending html options to select element');
\r
758 var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
\r
759 $('#sap').prepend(document.getElementById('first'));
\r
760 ok( expected == $('#sap').text(), "Check for prepending of element" );
\r
763 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
\r
764 $('#sap').prepend([document.getElementById('first'), document.getElementById('yahoo')]);
\r
765 ok( expected == $('#sap').text(), "Check for prepending of array of elements" );
\r
768 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
\r
769 $('#sap').prepend($("#first, #yahoo"));
\r
770 ok( expected == $('#sap').text(), "Check for prepending of jQuery object" );
\r
773 test("prependTo(String|Element|Array<Element>|jQuery)", function() {
\r
775 var defaultText = 'Try them out:'
\r
776 $('<b>buga</b>').prependTo('#first');
\r
777 ok( $('#first').text() == 'buga' + defaultText, 'Check if text prepending works' );
\r
778 ok( $('<option value="prependTest">Prepend Test</option>').prependTo('#select3').parent().find('option:first-child').attr('value') == 'prependTest', 'Prepending html options to select element');
\r
781 var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
\r
782 $(document.getElementById('first')).prependTo('#sap');
\r
783 ok( expected == $('#sap').text(), "Check for prepending of element" );
\r
786 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
\r
787 $([document.getElementById('yahoo'), document.getElementById('first')]).prependTo('#sap');
\r
788 ok( expected == $('#sap').text(), "Check for prepending of array of elements" );
\r
791 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
\r
792 $("#yahoo, #first").prependTo('#sap');
\r
793 ok( expected == $('#sap').text(), "Check for prepending of jQuery object" );
\r
796 $('<select id="prependSelect1"></select>').prependTo('form:last');
\r
797 $('<select id="prependSelect2"><option>Test</option></select>').prependTo('form:last');
\r
799 t( "Prepend Select", "#prependSelect1, #prependSelect2", ["prependSelect1", "prependSelect2"] );
\r
802 test("before(String|Element|Array<Element>|jQuery)", function() {
\r
804 var expected = 'This is a normal link: bugaYahoo';
\r
805 $('#yahoo').before('<b>buga</b>');
\r
806 ok( expected == $('#en').text(), 'Insert String before' );
\r
809 expected = "This is a normal link: Try them out:Yahoo";
\r
810 $('#yahoo').before(document.getElementById('first'));
\r
811 ok( expected == $('#en').text(), "Insert element before" );
\r
814 expected = "This is a normal link: Try them out:diveintomarkYahoo";
\r
815 $('#yahoo').before([document.getElementById('first'), document.getElementById('mark')]);
\r
816 ok( expected == $('#en').text(), "Insert array of elements before" );
\r
819 expected = "This is a normal link: Try them out:diveintomarkYahoo";
\r
820 $('#yahoo').before($("#first, #mark"));
\r
821 ok( expected == $('#en').text(), "Insert jQuery before" );
\r
824 test("insertBefore(String|Element|Array<Element>|jQuery)", function() {
\r
826 var expected = 'This is a normal link: bugaYahoo';
\r
827 $('<b>buga</b>').insertBefore('#yahoo');
\r
828 ok( expected == $('#en').text(), 'Insert String before' );
\r
831 expected = "This is a normal link: Try them out:Yahoo";
\r
832 $(document.getElementById('first')).insertBefore('#yahoo');
\r
833 ok( expected == $('#en').text(), "Insert element before" );
\r
836 expected = "This is a normal link: Try them out:diveintomarkYahoo";
\r
837 $([document.getElementById('first'), document.getElementById('mark')]).insertBefore('#yahoo');
\r
838 ok( expected == $('#en').text(), "Insert array of elements before" );
\r
841 expected = "This is a normal link: Try them out:diveintomarkYahoo";
\r
842 $("#first, #mark").insertBefore('#yahoo');
\r
843 ok( expected == $('#en').text(), "Insert jQuery before" );
\r
846 test("after(String|Element|Array<Element>|jQuery)", function() {
\r
848 var expected = 'This is a normal link: Yahoobuga';
\r
849 $('#yahoo').after('<b>buga</b>');
\r
850 ok( expected == $('#en').text(), 'Insert String after' );
\r
853 expected = "This is a normal link: YahooTry them out:";
\r
854 $('#yahoo').after(document.getElementById('first'));
\r
855 ok( expected == $('#en').text(), "Insert element after" );
\r
858 expected = "This is a normal link: YahooTry them out:diveintomark";
\r
859 $('#yahoo').after([document.getElementById('first'), document.getElementById('mark')]);
\r
860 ok( expected == $('#en').text(), "Insert array of elements after" );
\r
863 expected = "This is a normal link: YahooTry them out:diveintomark";
\r
864 $('#yahoo').after($("#first, #mark"));
\r
865 ok( expected == $('#en').text(), "Insert jQuery after" );
\r
868 test("insertAfter(String|Element|Array<Element>|jQuery)", function() {
\r
870 var expected = 'This is a normal link: Yahoobuga';
\r
871 $('<b>buga</b>').insertAfter('#yahoo');
\r
872 ok( expected == $('#en').text(), 'Insert String after' );
\r
875 expected = "This is a normal link: YahooTry them out:";
\r
876 $(document.getElementById('first')).insertAfter('#yahoo');
\r
877 ok( expected == $('#en').text(), "Insert element after" );
\r
880 expected = "This is a normal link: YahooTry them out:diveintomark";
\r
881 $([document.getElementById('mark'), document.getElementById('first')]).insertAfter('#yahoo');
\r
882 ok( expected == $('#en').text(), "Insert array of elements after" );
\r
885 expected = "This is a normal link: YahooTry them out:diveintomark";
\r
886 $("#mark, #first").insertAfter('#yahoo');
\r
887 ok( expected == $('#en').text(), "Insert jQuery after" );
\r
890 test("replaceWith(String|Element|Array<Element>|jQuery)", function() {
\r
892 $('#yahoo').replaceWith('<b id="replace">buga</b>');
\r
893 ok( $("#replace")[0], 'Replace element with string' );
\r
894 ok( !$("#yahoo")[0], 'Verify that original element is gone, after string' );
\r
897 $('#yahoo').replaceWith(document.getElementById('first'));
\r
898 ok( $("#first")[0], 'Replace element with element' );
\r
899 ok( !$("#yahoo")[0], 'Verify that original element is gone, after element' );
\r
902 $('#yahoo').replaceWith([document.getElementById('first'), document.getElementById('mark')]);
\r
903 ok( $("#first")[0], 'Replace element with array of elements' );
\r
904 ok( $("#mark")[0], 'Replace element with array of elements' );
\r
905 ok( !$("#yahoo")[0], 'Verify that original element is gone, after array of elements' );
\r
908 $('#yahoo').replaceWith($("#first, #mark"));
\r
909 ok( $("#first")[0], 'Replace element with set of elements' );
\r
910 ok( $("#mark")[0], 'Replace element with set of elements' );
\r
911 ok( !$("#yahoo")[0], 'Verify that original element is gone, after set of elements' );
\r
914 test("replaceAll(String|Element|Array<Element>|jQuery)", function() {
\r
916 $('<b id="replace">buga</b>').replaceAll("#yahoo");
\r
917 ok( $("#replace")[0], 'Replace element with string' );
\r
918 ok( !$("#yahoo")[0], 'Verify that original element is gone, after string' );
\r
921 $(document.getElementById('first')).replaceAll("#yahoo");
\r
922 ok( $("#first")[0], 'Replace element with element' );
\r
923 ok( !$("#yahoo")[0], 'Verify that original element is gone, after element' );
\r
926 $([document.getElementById('first'), document.getElementById('mark')]).replaceAll("#yahoo");
\r
927 ok( $("#first")[0], 'Replace element with array of elements' );
\r
928 ok( $("#mark")[0], 'Replace element with array of elements' );
\r
929 ok( !$("#yahoo")[0], 'Verify that original element is gone, after array of elements' );
\r
932 $("#first, #mark").replaceAll("#yahoo");
\r
933 ok( $("#first")[0], 'Replace element with set of elements' );
\r
934 ok( $("#mark")[0], 'Replace element with set of elements' );
\r
935 ok( !$("#yahoo")[0], 'Verify that original element is gone, after set of elements' );
\r
938 test("end()", function() {
\r
940 ok( 'Yahoo' == $('#yahoo').parent().end().text(), 'Check for end' );
\r
941 ok( $('#yahoo').end(), 'Check for end with nothing to end' );
\r
943 var x = $('#yahoo');
\r
945 ok( 'Yahoo' == $('#yahoo').text(), 'Check for non-destructive behaviour' );
\r
948 test("find(String)", function() {
\r
950 ok( 'Yahoo' == $('#foo').find('.blogTest').text(), 'Check for find' );
\r
952 // using contents will get comments regular, text, and comment nodes
\r
953 var j = $("#nonnodes").contents();
\r
954 equals( j.find("div").length, 0, "Check node,textnode,comment to find zero divs" );
\r
957 test("clone()", function() {
\r
959 ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Assert text for #en' );
\r
960 var clone = $('#yahoo').clone();
\r
961 ok( 'Try them out:Yahoo' == $('#first').append(clone).text(), 'Check for clone' );
\r
962 ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Reassert text for #en' );
\r
965 "<table/>", "<tr/>", "<td/>", "<div/>",
\r
966 "<button/>", "<ul/>", "<ol/>", "<li/>",
\r
967 "<input type='checkbox' />", "<select/>", "<option/>", "<textarea/>",
\r
968 "<tbody/>", "<thead/>", "<tfoot/>", "<iframe/>"
\r
970 for (var i = 0; i < cloneTags.length; i++) {
\r
971 var j = $(cloneTags[i]);
\r
972 equals( j[0].tagName, j.clone()[0].tagName, 'Clone a <' + cloneTags[i].substring(1));
\r
975 // using contents will get comments regular, text, and comment nodes
\r
976 var cl = $("#nonnodes").contents().clone();
\r
977 ok( cl.length >= 2, "Check node,textnode,comment clone works (some browsers delete comments on clone)" );
\r
981 test("clone() on XML nodes", function() {
\r
984 $.get("data/dashboard.xml", function (xml) {
\r
985 var root = $(xml.documentElement).clone();
\r
986 $("tab:first", xml).text("origval");
\r
987 $("tab:first", root).text("cloneval");
\r
988 equals($("tab:first", xml).text(), "origval", "Check original XML node was correctly set");
\r
989 equals($("tab:first", root).text(), "cloneval", "Check cloned XML node was correctly set");
\r
995 test("is(String)", function() {
\r
997 ok( $('#form').is('form'), 'Check for element: A form must be a form' );
\r
998 ok( !$('#form').is('div'), 'Check for element: A form is not a div' );
\r
999 ok( $('#mark').is('.blog'), 'Check for class: Expected class "blog"' );
\r
1000 ok( !$('#mark').is('.link'), 'Check for class: Did not expect class "link"' );
\r
1001 ok( $('#simon').is('.blog.link'), 'Check for multiple classes: Expected classes "blog" and "link"' );
\r
1002 ok( !$('#simon').is('.blogTest'), 'Check for multiple classes: Expected classes "blog" and "link", but not "blogTest"' );
\r
1003 ok( $('#en').is('[lang="en"]'), 'Check for attribute: Expected attribute lang to be "en"' );
\r
1004 ok( !$('#en').is('[lang="de"]'), 'Check for attribute: Expected attribute lang to be "en", not "de"' );
\r
1005 ok( $('#text1').is('[type="text"]'), 'Check for attribute: Expected attribute type to be "text"' );
\r
1006 ok( !$('#text1').is('[type="radio"]'), 'Check for attribute: Expected attribute type to be "text", not "radio"' );
\r
1007 ok( $('#text2').is(':disabled'), 'Check for pseudoclass: Expected to be disabled' );
\r
1008 ok( !$('#text1').is(':disabled'), 'Check for pseudoclass: Expected not disabled' );
\r
1009 ok( $('#radio2').is(':checked'), 'Check for pseudoclass: Expected to be checked' );
\r
1010 ok( !$('#radio1').is(':checked'), 'Check for pseudoclass: Expected not checked' );
\r
1011 ok( $('#foo').is(':has(p)'), 'Check for child: Expected a child "p" element' );
\r
1012 ok( !$('#foo').is(':has(ul)'), 'Check for child: Did not expect "ul" element' );
\r
1013 ok( $('#foo').is(':has(p):has(a):has(code)'), 'Check for childs: Expected "p", "a" and "code" child elements' );
\r
1014 ok( !$('#foo').is(':has(p):has(a):has(code):has(ol)'), 'Check for childs: Expected "p", "a" and "code" child elements, but no "ol"' );
\r
1015 ok( !$('#foo').is(0), 'Expected false for an invalid expression - 0' );
\r
1016 ok( !$('#foo').is(null), 'Expected false for an invalid expression - null' );
\r
1017 ok( !$('#foo').is(''), 'Expected false for an invalid expression - ""' );
\r
1018 ok( !$('#foo').is(undefined), 'Expected false for an invalid expression - undefined' );
\r
1020 // test is() with comma-seperated expressions
\r
1021 ok( $('#en').is('[lang="en"],[lang="de"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
\r
1022 ok( $('#en').is('[lang="de"],[lang="en"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
\r
1023 ok( $('#en').is('[lang="en"] , [lang="de"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
\r
1024 ok( $('#en').is('[lang="de"] , [lang="en"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
\r
1027 test("$.extend(Object, Object)", function() {
\r
1030 var settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
\r
1031 options = { xnumber2: 1, xstring2: "x", xxx: "newstring" },
\r
1032 optionsCopy = { xnumber2: 1, xstring2: "x", xxx: "newstring" },
\r
1033 merged = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "x", xxx: "newstring" },
\r
1034 deep1 = { foo: { bar: true } },
\r
1035 deep1copy = { foo: { bar: true } },
\r
1036 deep2 = { foo: { baz: true }, foo2: document },
\r
1037 deep2copy = { foo: { baz: true }, foo2: document },
\r
1038 deepmerged = { foo: { bar: true, baz: true }, foo2: document };
\r
1040 jQuery.extend(settings, options);
\r
1041 isObj( settings, merged, "Check if extended: settings must be extended" );
\r
1042 isObj( options, optionsCopy, "Check if not modified: options must not be modified" );
\r
1044 jQuery.extend(settings, null, options);
\r
1045 isObj( settings, merged, "Check if extended: settings must be extended" );
\r
1046 isObj( options, optionsCopy, "Check if not modified: options must not be modified" );
\r
1048 jQuery.extend(true, deep1, deep2);
\r
1049 isObj( deep1.foo, deepmerged.foo, "Check if foo: settings must be extended" );
\r
1050 isObj( deep2.foo, deep2copy.foo, "Check if not deep2: options must not be modified" );
\r
1051 equals( deep1.foo2, document, "Make sure that a deep clone was not attempted on the document" );
\r
1054 var recursive = { foo:target, bar:5 };
\r
1055 jQuery.extend(true, target, recursive);
\r
1056 isObj( target, { bar:5 }, "Check to make sure a recursive obj doesn't go never-ending loop by not copying it over" );
\r
1058 var ret = jQuery.extend(true, { foo: [] }, { foo: [0] } ); // 1907
\r
1059 ok( ret.foo.length == 1, "Check to make sure a value with coersion 'false' copies over when necessary to fix #1907" );
\r
1061 var ret = jQuery.extend(true, { foo: "1,2,3" }, { foo: [1, 2, 3] } );
\r
1062 ok( typeof ret.foo != "string", "Check to make sure values equal with coersion (but not actually equal) overwrite correctly" );
\r
1064 var ret = jQuery.extend(true, { foo:"bar" }, { foo:null } );
\r
1065 ok( typeof ret.foo !== 'undefined', "Make sure a null value doesn't crash with deep extend, for #1908" );
\r
1067 var obj = { foo:null };
\r
1068 jQuery.extend(true, obj, { foo:"notnull" } );
\r
1069 equals( obj.foo, "notnull", "Make sure a null value can be overwritten" );
\r
1071 function func() {}
\r
1072 jQuery.extend(func, { key: "value" } );
\r
1073 equals( func.key, "value", "Verify a function can be extended" );
\r
1075 var defaults = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
\r
1076 defaultsCopy = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
\r
1077 options1 = { xnumber2: 1, xstring2: "x" },
\r
1078 options1Copy = { xnumber2: 1, xstring2: "x" },
\r
1079 options2 = { xstring2: "xx", xxx: "newstringx" },
\r
1080 options2Copy = { xstring2: "xx", xxx: "newstringx" },
\r
1081 merged2 = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "xx", xxx: "newstringx" };
\r
1083 var settings = jQuery.extend({}, defaults, options1, options2);
\r
1084 isObj( settings, merged2, "Check if extended: settings must be extended" );
\r
1085 isObj( defaults, defaultsCopy, "Check if not modified: options1 must not be modified" );
\r
1086 isObj( options1, options1Copy, "Check if not modified: options1 must not be modified" );
\r
1087 isObj( options2, options2Copy, "Check if not modified: options2 must not be modified" );
\r
1090 test("val()", function() {
\r
1092 ok( $("#text1").val() == "Test", "Check for value of input element" );
\r
1093 ok( !$("#text1").val() == "", "Check for value of input element" );
\r
1094 // ticket #1714 this caused a JS error in IE
\r
1095 ok( $("#first").val() == "", "Check a paragraph element to see if it has a value" );
\r
1096 ok( $([]).val() === undefined, "Check an empty jQuery object will return undefined from val" );
\r
1099 test("val(String)", function() {
\r
1101 document.getElementById('text1').value = "bla";
\r
1102 ok( $("#text1").val() == "bla", "Check for modified value of input element" );
\r
1103 $("#text1").val('test');
\r
1104 ok ( document.getElementById('text1').value == "test", "Check for modified (via val(String)) value of input element" );
\r
1106 $("#select1").val("3");
\r
1107 ok( $("#select1").val() == "3", "Check for modified (via val(String)) value of select element" );
\r
1109 // using contents will get comments regular, text, and comment nodes
\r
1110 var j = $("#nonnodes").contents();
\r
1112 equals( j.val(), "asdf", "Check node,textnode,comment with val()" );
\r
1113 j.removeAttr("value");
\r
1116 var scriptorder = 0;
\r
1118 test("html(String)", function() {
\r
1120 var div = $("#main > div");
\r
1121 div.html("<b>test</b>");
\r
1123 for ( var i = 0; i < div.size(); i++ ) {
\r
1124 if ( div.get(i).childNodes.length != 1 ) pass = false;
\r
1126 ok( pass, "Set HTML" );
\r
1129 // using contents will get comments regular, text, and comment nodes
\r
1130 var j = $("#nonnodes").contents();
\r
1131 j.html("<b>bold</b>");
\r
1132 equals( j.html().toLowerCase(), "<b>bold</b>", "Check node,textnode,comment with html()" );
\r
1134 $("#main").html("<select/>");
\r
1135 $("#main select").html("<option>O1</option><option selected='selected'>O2</option><option>O3</option>");
\r
1136 equals( $("#main select").val(), "O2", "Selected option correct" );
\r
1140 $("#main").html('<script type="text/javascript">ok( true, "$().html().evalScripts() Evals Scripts Twice in Firefox, see #975" );</script>');
\r
1142 $("#main").html('foo <form><script type="text/javascript">ok( true, "$().html().evalScripts() Evals Scripts Twice in Firefox, see #975" );</script></form>');
\r
1144 // it was decided that waiting to execute ALL scripts makes sense since nested ones have to wait anyway so this test case is changed, see #1959
\r
1145 $("#main").html("<script>ok(scriptorder++ == 0, 'Script is executed in order');ok($('#scriptorder').length == 1,'Execute after html (even though appears before)')<\/script><span id='scriptorder'><script>ok(scriptorder++ == 1, 'Script (nested) is executed in order');ok($('#scriptorder').length == 1,'Execute after html')<\/script></span><script>ok(scriptorder++ == 2, 'Script (unnested) is executed in order');ok($('#scriptorder').length == 1,'Execute after html')<\/script>");
\r
1147 setTimeout( start, 100 );
\r
1150 test("filter()", function() {
\r
1152 isSet( $("#form input").filter(":checked").get(), q("radio2", "check1"), "filter(String)" );
\r
1153 isSet( $("p").filter("#ap, #sndp").get(), q("ap", "sndp"), "filter('String, String')" );
\r
1154 isSet( $("p").filter("#ap,#sndp").get(), q("ap", "sndp"), "filter('String,String')" );
\r
1155 isSet( $("p").filter(function() { return !$("a", this).length }).get(), q("sndp", "first"), "filter(Function)" );
\r
1157 // using contents will get comments regular, text, and comment nodes
\r
1158 var j = $("#nonnodes").contents();
\r
1159 equals( j.filter("span").length, 1, "Check node,textnode,comment to filter the one span" );
\r
1160 equals( j.filter("[name]").length, 0, "Check node,textnode,comment to filter the one span" );
\r
1163 test("not()", function() {
\r
1165 ok( $("#main > p#ap > a").not("#google").length == 2, "not('selector')" );
\r
1166 ok( $("#main > p#ap > a").not(document.getElementById("google")).length == 2, "not(DOMElement)" );
\r
1167 isSet( $("p").not(".result").get(), q("firstp", "ap", "sndp", "en", "sap", "first"), "not('.class')" );
\r
1168 isSet( $("p").not("#ap, #sndp, .result").get(), q("firstp", "en", "sap", "first"), "not('selector, selector')" );
\r
1169 isSet( $("p").not($("#ap, #sndp, .result")).get(), q("firstp", "en", "sap", "first"), "not(jQuery)" );
\r
1170 ok( $("p").not(document.getElementsByTagName("p")).length == 0, "not(Array-like DOM collection)" );
\r
1171 isSet( $("#form option").not("option.emptyopt:contains('Nothing'),[selected],[value='1']").get(), q("option1c", "option1d", "option2c", "option3d" ), "not('complex selector')");
\r
1173 var selects = $("#form select");
\r
1174 isSet( selects.not( selects[1] ), q("select1", "select3"), "filter out DOM element");
\r
1177 test("andSelf()", function() {
\r
1179 isSet( $("#en").siblings().andSelf().get(), q("sndp", "sap","en"), "Check for siblings and self" );
\r
1180 isSet( $("#foo").children().andSelf().get(), q("sndp", "en", "sap", "foo"), "Check for children and self" );
\r
1181 isSet( $("#en, #sndp").parent().andSelf().get(), q("foo","en","sndp"), "Check for parent and self" );
\r
1182 isSet( $("#groups").parents("p, div").andSelf().get(), q("ap", "main", "groups"), "Check for parents and self" );
\r
1185 test("siblings([String])", function() {
\r
1187 isSet( $("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" );
\r
1188 isSet( $("#sndp").siblings(":has(code)").get(), q("sap"), "Check for filtered siblings (has code child element)" );
\r
1189 isSet( $("#sndp").siblings(":has(a)").get(), q("en", "sap"), "Check for filtered siblings (has anchor child element)" );
\r
1190 isSet( $("#foo").siblings("form, b").get(), q("form", "lengthtest", "testForm", "floatTest"), "Check for multiple filters" );
\r
1191 isSet( $("#en, #sndp").siblings().get(), q("sndp", "sap", "en"), "Check for unique results from siblings" );
\r
1194 test("children([String])", function() {
\r
1196 isSet( $("#foo").children().get(), q("sndp", "en", "sap"), "Check for children" );
\r
1197 isSet( $("#foo").children(":has(code)").get(), q("sndp", "sap"), "Check for filtered children" );
\r
1198 isSet( $("#foo").children("#en, #sap").get(), q("en", "sap"), "Check for multiple filters" );
\r
1201 test("parent([String])", function() {
\r
1203 ok( $("#groups").parent()[0].id == "ap", "Simple parent check" );
\r
1204 ok( $("#groups").parent("p")[0].id == "ap", "Filtered parent check" );
\r
1205 ok( $("#groups").parent("div").length == 0, "Filtered parent check, no match" );
\r
1206 ok( $("#groups").parent("div, p")[0].id == "ap", "Check for multiple filters" );
\r
1207 isSet( $("#en, #sndp").parent().get(), q("foo"), "Check for unique results from parent" );
\r
1210 test("parents([String])", function() {
\r
1212 ok( $("#groups").parents()[0].id == "ap", "Simple parents check" );
\r
1213 ok( $("#groups").parents("p")[0].id == "ap", "Filtered parents check" );
\r
1214 ok( $("#groups").parents("div")[0].id == "main", "Filtered parents check2" );
\r
1215 isSet( $("#groups").parents("p, div").get(), q("ap", "main"), "Check for multiple filters" );
\r
1216 isSet( $("#en, #sndp").parents().get(), q("foo", "main", "dl", "body", "html"), "Check for unique results from parents" );
\r
1219 test("next([String])", function() {
\r
1221 ok( $("#ap").next()[0].id == "foo", "Simple next check" );
\r
1222 ok( $("#ap").next("div")[0].id == "foo", "Filtered next check" );
\r
1223 ok( $("#ap").next("p").length == 0, "Filtered next check, no match" );
\r
1224 ok( $("#ap").next("div, p")[0].id == "foo", "Multiple filters" );
\r
1227 test("prev([String])", function() {
\r
1229 ok( $("#foo").prev()[0].id == "ap", "Simple prev check" );
\r
1230 ok( $("#foo").prev("p")[0].id == "ap", "Filtered prev check" );
\r
1231 ok( $("#foo").prev("div").length == 0, "Filtered prev check, no match" );
\r
1232 ok( $("#foo").prev("p, div")[0].id == "ap", "Multiple filters" );
\r
1235 test("show()", function() {
\r
1237 var pass = true, div = $("div");
\r
1238 div.show().each(function(){
\r
1239 if ( this.style.display == "none" ) pass = false;
\r
1241 ok( pass, "Show" );
\r
1243 $("#main").append('<div id="show-tests"><div><p><a href="#"></a></p><code></code><pre></pre><span></span></div><table><thead><tr><th></th></tr></thead><tbody><tr><td></td></tr></tbody></table><ul><li></li></ul></div>');
\r
1248 "code" : "inline",
\r
1250 "span" : "inline",
\r
1251 "table" : $.browser.msie ? "block" : "table",
\r
1252 "thead" : $.browser.msie ? "block" : "table-header-group",
\r
1253 "tbody" : $.browser.msie ? "block" : "table-row-group",
\r
1254 "tr" : $.browser.msie ? "block" : "table-row",
\r
1255 "th" : $.browser.msie ? "block" : "table-cell",
\r
1256 "td" : $.browser.msie ? "block" : "table-cell",
\r
1258 "li" : $.browser.msie ? "block" : "list-item"
\r
1261 $.each(test, function(selector, expected) {
\r
1262 var elem = $(selector, "#show-tests").show();
\r
1263 equals( elem.css("display"), expected, "Show using correct display type for " + selector );
\r
1267 test("addClass(String)", function() {
\r
1269 var div = $("div");
\r
1270 div.addClass("test");
\r
1272 for ( var i = 0; i < div.size(); i++ ) {
\r
1273 if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
\r
1275 ok( pass, "Add Class" );
\r
1277 // using contents will get regular, text, and comment nodes
\r
1278 var j = $("#nonnodes").contents();
\r
1279 j.addClass("asdf");
\r
1280 ok( j.hasClass("asdf"), "Check node,textnode,comment for addClass" );
\r
1283 test("removeClass(String) - simple", function() {
\r
1285 var div = $("div").addClass("test").removeClass("test"),
\r
1287 for ( var i = 0; i < div.size(); i++ ) {
\r
1288 if ( div.get(i).className.indexOf("test") != -1 ) pass = false;
\r
1290 ok( pass, "Remove Class" );
\r
1293 var div = $("div").addClass("test").addClass("foo").addClass("bar");
\r
1294 div.removeClass("test").removeClass("bar").removeClass("foo");
\r
1296 for ( var i = 0; i < div.size(); i++ ) {
\r
1297 if ( div.get(i).className.match(/test|bar|foo/) ) pass = false;
\r
1299 ok( pass, "Remove multiple classes" );
\r
1302 var div = $("div:eq(0)").addClass("test").removeClass("");
\r
1303 ok( div.is('.test'), "Empty string passed to removeClass" );
\r
1305 // using contents will get regular, text, and comment nodes
\r
1306 var j = $("#nonnodes").contents();
\r
1307 j.removeClass("asdf");
\r
1308 ok( !j.hasClass("asdf"), "Check node,textnode,comment for removeClass" );
\r
1311 test("toggleClass(String)", function() {
\r
1313 var e = $("#firstp");
\r
1314 ok( !e.is(".test"), "Assert class not present" );
\r
1315 e.toggleClass("test");
\r
1316 ok( e.is(".test"), "Assert class present" );
\r
1317 e.toggleClass("test");
\r
1318 ok( !e.is(".test"), "Assert class not present" );
\r
1321 test("removeAttr(String", function() {
\r
1323 ok( $('#mark').removeAttr("class")[0].className == "", "remove class" );
\r
1326 test("text(String)", function() {
\r
1328 ok( $("#foo").text("<div><b>Hello</b> cruel world!</div>")[0].innerHTML == "<div><b>Hello</b> cruel world!</div>", "Check escaped text" );
\r
1330 // using contents will get comments regular, text, and comment nodes
\r
1331 var j = $("#nonnodes").contents();
\r
1333 equals( $(j[0]).text(), "hi!", "Check node,textnode,comment with text()" );
\r
1334 equals( j[1].nodeValue, " there ", "Check node,textnode,comment with text()" );
\r
1335 equals( j[2].nodeType, 8, "Check node,textnode,comment with text()" );
\r
1338 test("$.each(Object,Function)", function() {
\r
1340 $.each( [0,1,2], function(i, n){
\r
1341 ok( i == n, "Check array iteration" );
\r
1344 $.each( [5,6,7], function(i, n){
\r
1345 ok( i == n - 5, "Check array iteration" );
\r
1348 $.each( { name: "name", lang: "lang" }, function(i, n){
\r
1349 ok( i == n, "Check object iteration" );
\r
1353 jQuery.each([1,2,3], function(i,v){ total += v; });
\r
1354 ok( total == 6, "Looping over an array" );
\r
1356 jQuery.each([1,2,3], function(i,v){ total += v; if ( i == 1 ) return false; });
\r
1357 ok( total == 3, "Looping over an array, with break" );
\r
1359 jQuery.each({"a":1,"b":2,"c":3}, function(i,v){ total += v; });
\r
1360 ok( total == 6, "Looping over an object" );
\r
1362 jQuery.each({"a":3,"b":3,"c":3}, function(i,v){ total += v; return false; });
\r
1363 ok( total == 3, "Looping over an object, with break" );
\r
1366 test("$.prop", function() {
\r
1368 var handle = function() { return this.id };
\r
1369 ok( $.prop($("#ap")[0], handle) == "ap", "Check with Function argument" );
\r
1370 ok( $.prop($("#ap")[0], "value") == "value", "Check with value argument" );
\r
1373 test("$.className", function() {
\r
1375 var x = $("<p>Hi</p>")[0];
\r
1376 var c = $.className;
\r
1378 ok( x.className == "hi", "Check single added class" );
\r
1379 c.add(x, "foo bar");
\r
1380 ok( x.className == "hi foo bar", "Check more added classes" );
\r
1382 ok( x.className == "", "Remove all classes" );
\r
1383 c.add(x, "hi foo bar");
\r
1384 c.remove(x, "foo");
\r
1385 ok( x.className == "hi bar", "Check removal of one class" );
\r
1386 ok( c.has(x, "hi"), "Check has1" );
\r
1387 ok( c.has(x, "bar"), "Check has2" );
\r
1390 test("$.data", function() {
\r
1392 var div = $("#foo")[0];
\r
1393 ok( jQuery.data(div, "test") == undefined, "Check for no data exists" );
\r
1394 jQuery.data(div, "test", "success");
\r
1395 ok( jQuery.data(div, "test") == "success", "Check for added data" );
\r
1396 jQuery.data(div, "test", "overwritten");
\r
1397 ok( jQuery.data(div, "test") == "overwritten", "Check for overwritten data" );
\r
1400 test(".data()", function() {
\r
1402 var div = $("#foo");
\r
1403 ok( div.data("test") == undefined, "Check for no data exists" );
\r
1404 div.data("test", "success");
\r
1405 ok( div.data("test") == "success", "Check for added data" );
\r
1406 div.data("test", "overwritten");
\r
1407 ok( div.data("test") == "overwritten", "Check for overwritten data" );
\r
1409 var hits = {test:0}, gets = {test:0};
\r
1412 .bind("setData",function(e,key,value){ hits[key] += value; })
\r
1413 .bind("setData.foo",function(e,key,value){ hits[key] += value; })
\r
1414 .bind("getData",function(e,key){ gets[key] += 1; })
\r
1415 .bind("getData.foo",function(e,key){ gets[key] += 3; });
\r
1417 div.data("test.foo", 2);
\r
1418 ok( div.data("test") == "overwritten", "Check for original data" );
\r
1419 ok( div.data("test.foo") == 2, "Check for namespaced data" );
\r
1420 ok( div.data("test.bar") == "overwritten", "Check for unmatched namespace" );
\r
1421 equals( hits.test, 2, "Check triggered setter functions" );
\r
1422 equals( gets.test, 5, "Check triggered getter functions" );
\r
1427 div.data("test", 1);
\r
1428 ok( div.data("test") == 1, "Check for original data" );
\r
1429 ok( div.data("test.foo") == 2, "Check for namespaced data" );
\r
1430 ok( div.data("test.bar") == 1, "Check for unmatched namespace" );
\r
1431 equals( hits.test, 1, "Check triggered setter functions" );
\r
1432 equals( gets.test, 5, "Check triggered getter functions" );
\r
1438 .bind("getData",function(e,key){ return key + "root"; })
\r
1439 .bind("getData.foo",function(e,key){ return key + "foo"; });
\r
1441 ok( div.data("test") == "testroot", "Check for original data" );
\r
1442 ok( div.data("test.foo") == "testfoo", "Check for namespaced data" );
\r
1443 ok( div.data("test.bar") == "testroot", "Check for unmatched namespace" );
\r
1446 test("$.removeData", function() {
\r
1448 var div = $("#foo")[0];
\r
1449 jQuery.data(div, "test", "testing");
\r
1450 jQuery.removeData(div, "test");
\r
1451 ok( jQuery.data(div, "test") == undefined, "Check removal of data" );
\r
1454 test(".removeData()", function() {
\r
1456 var div = $("#foo");
\r
1457 div.data("test", "testing");
\r
1458 div.removeData("test");
\r
1459 ok( div.data("test") == undefined, "Check removal of data" );
\r
1461 div.data("test", "testing");
\r
1462 div.data("test.foo", "testing2");
\r
1463 div.removeData("test.bar");
\r
1464 ok( div.data("test.foo") == "testing2", "Make sure data is intact" );
\r
1465 ok( div.data("test") == "testing", "Make sure data is intact" );
\r
1467 div.removeData("test");
\r
1468 ok( div.data("test.foo") == "testing2", "Make sure data is intact" );
\r
1469 ok( div.data("test") == undefined, "Make sure data is intact" );
\r
1471 div.removeData("test.foo");
\r
1472 ok( div.data("test.foo") == undefined, "Make sure data is intact" );
\r
1475 test("remove()", function() {
\r
1477 $("#ap").children().remove();
\r
1478 ok( $("#ap").text().length > 10, "Check text is not removed" );
\r
1479 ok( $("#ap").children().length == 0, "Check remove" );
\r
1482 $("#ap").children().remove("a");
\r
1483 ok( $("#ap").text().length > 10, "Check text is not removed" );
\r
1484 ok( $("#ap").children().length == 1, "Check filtered remove" );
\r
1486 // using contents will get comments regular, text, and comment nodes
\r
1487 equals( $("#nonnodes").contents().length, 3, "Check node,textnode,comment remove works" );
\r
1488 $("#nonnodes").contents().remove();
\r
1489 equals( $("#nonnodes").contents().length, 0, "Check node,textnode,comment remove works" );
\r
1492 test("empty()", function() {
\r
1494 ok( $("#ap").children().empty().text().length == 0, "Check text is removed" );
\r
1495 ok( $("#ap").children().length == 4, "Check elements are not removed" );
\r
1497 // using contents will get comments regular, text, and comment nodes
\r
1498 var j = $("#nonnodes").contents();
\r
1500 equals( j.html(), "", "Check node,textnode,comment empty works" );
\r
1503 test("slice()", function() {
\r
1505 isSet( $("#ap a").slice(1,2), q("groups"), "slice(1,2)" );
\r
1506 isSet( $("#ap a").slice(1), q("groups", "anchor1", "mark"), "slice(1)" );
\r
1507 isSet( $("#ap a").slice(0,3), q("google", "groups", "anchor1"), "slice(0,3)" );
\r
1508 isSet( $("#ap a").slice(-1), q("mark"), "slice(-1)" );
\r
1510 isSet( $("#ap a").eq(1), q("groups"), "eq(1)" );
\r
1513 test("map()", function() {
\r
1514 expect(2);//expect(6);
\r
1517 $("#ap").map(function(){
\r
1518 return $(this).find("a").get();
\r
1520 q("google", "groups", "anchor1", "mark"),
\r
1525 $("#ap > a").map(function(){
\r
1526 return this.parentNode;
\r
1528 q("ap","ap","ap"),
\r
1532 return;//these haven't been accepted yet
\r
1535 var keys = $.map( {a:1,b:2}, function( v, k ){
\r
1539 equals( keys.join(""), "ab", "Map the keys from a hash to an array" );
\r
1541 var values = $.map( {a:1,b:2}, function( v, k ){
\r
1545 equals( values.join(""), "12", "Map the values from a hash to an array" );
\r
1547 var scripts = document.getElementsByTagName("script");
\r
1548 var mapped = $.map( scripts, function( v, k ){
\r
1552 equals( mapped.length, scripts.length, "Map an array(-like) to a hash" );
\r
1554 var flat = $.map( Array(4), function( v, k ){
\r
1555 return k % 2 ? k : [k,k,k];//try mixing array and regular returns
\r
1558 equals( flat.join(""), "00012223", "try the new flatten technique(#2616)" );
\r
1561 test("contents()", function() {
\r
1563 equals( $("#ap").contents().length, 9, "Check element contents" );
\r
1564 ok( $("#iframe").contents()[0], "Check existance of IFrame document" );
\r
1565 var ibody = $("#loadediframe").contents()[0].body;
\r
1566 ok( ibody, "Check existance of IFrame body" );
\r
1568 equals( $("span", ibody).text(), "span text", "Find span in IFrame and check its text" );
\r
1570 $(ibody).append("<div>init text</div>");
\r
1571 equals( $("div", ibody).length, 2, "Check the original div and the new div are in IFrame" );
\r
1573 equals( $("div:last", ibody).text(), "init text", "Add text to div in IFrame" );
\r
1575 $("div:last", ibody).text("div text");
\r
1576 equals( $("div:last", ibody).text(), "div text", "Add text to div in IFrame" );
\r
1578 $("div:last", ibody).remove();
\r
1579 equals( $("div", ibody).length, 1, "Delete the div and check only one div left in IFrame" );
\r
1581 equals( $("div", ibody).text(), "span text", "Make sure the correct div is still left after deletion in IFrame" );
\r
1583 $("<table/>", ibody).append("<tr><td>cell</td></tr>").appendTo(ibody);
\r
1584 $("table", ibody).remove();
\r
1585 equals( $("div", ibody).length, 1, "Check for JS error on add and delete of a table in IFrame" );
\r
1587 // using contents will get comments regular, text, and comment nodes
\r
1588 var c = $("#nonnodes").contents().contents();
\r
1589 equals( c.length, 1, "Check node,textnode,comment contents is just one" );
\r
1590 equals( c[0].nodeValue, "hi", "Check node,textnode,comment contents is just the one from span" );
\r
1593 test("$.makeArray", function(){
\r
1596 equals( $.makeArray($('html>*'))[0].nodeName, "HEAD", "Pass makeArray a jQuery object" );
\r
1598 equals( $.makeArray(document.getElementsByName("PWD")).slice(0,1)[0].name, "PWD", "Pass makeArray a nodelist" );
\r
1600 equals( (function(){ return $.makeArray(arguments); })(1,2).join(""), "12", "Pass makeArray an arguments array" );
\r
1602 equals( $.makeArray([1,2,3]).join(""), "123", "Pass makeArray a real array" );
\r
1604 equals( $.makeArray().length, 0, "Pass nothing to makeArray and expect an empty array" );
\r
1606 equals( $.makeArray( 0 )[0], 0 , "Pass makeArray a number" );
\r
1608 equals( $.makeArray( "foo" )[0], "foo", "Pass makeArray a string" );
\r
1610 equals( $.makeArray( true )[0].constructor, Boolean, "Pass makeArray a boolean" );
\r
1612 equals( $.makeArray( document.createElement("div") )[0].nodeName, "DIV", "Pass makeArray a single node" );
\r
1614 equals( $.makeArray( {length:2, 0:"a", 1:"b"} ).join(""), "ab", "Pass makeArray an array like map (with length)" );
\r
1616 equals( $.makeArray( document.documentElement.childNodes ).slice(0,1)[0].nodeName, "HEAD", "Pass makeArray a childNodes array" );
\r
1618 //function, is tricky as it has length
\r
1619 equals( $.makeArray( function(){ return 1;} )[0](), 1, "Pass makeArray a function" );
\r
1620 //window, also has length
\r
1621 equals( $.makeArray(window)[0], window, "Pass makeArray the window" );
\r
1623 equals( $.makeArray(/a/)[0].constructor, RegExp, "Pass makeArray a regex" );
\r