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("jQuery()", function() {
\r
17 var main = jQuery("#main");
\r
18 isSet( jQuery("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 = jQuery('<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 jQuery("<div>Testing</div>").appendTo(document.getElementById("iframe").contentDocument.body);
\r
36 ok( pass, "jQuery('<tag>') needs optional document parameter to ease cross-frame DOM wrangling, see #968" );*/
\r
38 var code = jQuery("<code/>");
\r
39 equals( code.length, 1, "Correct number of elements generated for code" );
\r
40 var img = jQuery("<img/>");
\r
41 equals( img.length, 1, "Correct number of elements generated for img" );
\r
42 var div = jQuery("<div/><hr/><code/><b/>");
\r
43 equals( div.length, 4, "Correct number of elements generated for div hr code b" );
\r
45 // can actually yield more than one, when iframes are included, the window is an array as well
\r
46 equals( jQuery(window).length, 1, "Correct number of elements generated for window" );
\r
48 equals( jQuery(document).length, 1, "Correct number of elements generated for document" );
\r
50 equals( jQuery([1,2,3]).get(1), 2, "Test passing an array to the factory" );
\r
52 equals( jQuery(document.body).get(0), jQuery('body').get(0), "Test passing an html node to the factory" );
\r
55 test("browser", function() {
\r
59 "Mozilla/5.0 (Windows; U; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)": "6.0",
\r
60 "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
62 * "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
64 //Browsers with Gecko engine
\r
66 "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.12) Gecko/20050915" : "1.7.12",
\r
68 "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
70 "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
72 "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
74 "Opera/9.20 (X11; Linux x86_64; U; en)": "9.20",
\r
75 "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; en) Opera 9.20" : "9.20",
\r
76 "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
78 "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; sv-se) AppleWebKit/418.9 (KHTML, like Gecko) Safari/419.3": "418.9",
\r
79 "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/418.8 (KHTML, like Gecko) Safari/419.3" : "418.8",
\r
80 "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; sv-se) AppleWebKit/312.8 (KHTML, like Gecko) Safari/312.5": "312.8",
\r
81 //Other user agent string
\r
82 "Other browser's user agent 1.0":null
\r
84 for (var i in browsers) {
\r
85 var v = i.toLowerCase().match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ); // RegEx from Core jQuery.browser.version check
\r
86 version = v ? v[1] : null;
\r
87 equals( version, browsers[i], "Checking UA string" );
\r
91 test("noConflict", function() {
\r
96 equals( jQuery, jQuery.noConflict(), "noConflict returned the jQuery object" );
\r
97 equals( jQuery, $$, "Make sure jQuery wasn't touched." );
\r
98 equals( $, original$, "Make sure $ was reverted." );
\r
102 equals( jQuery.noConflict(true), $$, "noConflict returned the jQuery object" );
\r
103 equals( jQuery, originaljQuery, "Make sure jQuery was reverted." );
\r
104 equals( $, original$, "Make sure $ was reverted." );
\r
109 test("isFunction", function() {
\r
112 // Make sure that false values return false
\r
113 ok( !jQuery.isFunction(), "No Value" );
\r
114 ok( !jQuery.isFunction( null ), "null Value" );
\r
115 ok( !jQuery.isFunction( undefined ), "undefined Value" );
\r
116 ok( !jQuery.isFunction( "" ), "Empty String Value" );
\r
117 ok( !jQuery.isFunction( 0 ), "0 Value" );
\r
120 // Safari uses "(Internal Function)"
\r
121 ok( jQuery.isFunction(String), "String Function("+String+")" );
\r
122 ok( jQuery.isFunction(Array), "Array Function("+Array+")" );
\r
123 ok( jQuery.isFunction(Object), "Object Function("+Object+")" );
\r
124 ok( jQuery.isFunction(Function), "Function Function("+Function+")" );
\r
126 // When stringified, this could be misinterpreted
\r
127 var mystr = "function";
\r
128 ok( !jQuery.isFunction(mystr), "Function String" );
\r
130 // When stringified, this could be misinterpreted
\r
131 var myarr = [ "function" ];
\r
132 ok( !jQuery.isFunction(myarr), "Function Array" );
\r
134 // When stringified, this could be misinterpreted
\r
135 var myfunction = { "function": "test" };
\r
136 ok( !jQuery.isFunction(myfunction), "Function Object" );
\r
138 // Make sure normal functions still work
\r
139 var fn = function(){};
\r
140 ok( jQuery.isFunction(fn), "Normal Function" );
\r
142 var obj = document.createElement("object");
\r
144 // Firefox says this is a function
\r
145 ok( !jQuery.isFunction(obj), "Object Element" );
\r
147 // IE says this is an object
\r
148 // Since 1.3, this isn't supported (#2968)
\r
149 //ok( jQuery.isFunction(obj.getAttribute), "getAttribute Function" );
\r
151 var nodes = document.body.childNodes;
\r
153 // Safari says this is a function
\r
154 ok( !jQuery.isFunction(nodes), "childNodes Property" );
\r
156 var first = document.body.firstChild;
\r
158 // Normal elements are reported ok everywhere
\r
159 ok( !jQuery.isFunction(first), "A normal DOM Element" );
\r
161 var input = document.createElement("input");
\r
162 input.type = "text";
\r
163 document.body.appendChild( input );
\r
165 // IE says this is an object
\r
166 // Since 1.3, this isn't supported (#2968)
\r
167 //ok( jQuery.isFunction(input.focus), "A default function property" );
\r
169 document.body.removeChild( input );
\r
171 var a = document.createElement("a");
\r
172 a.href = "some-function";
\r
173 document.body.appendChild( a );
\r
175 // This serializes with the word 'function' in it
\r
176 ok( !jQuery.isFunction(a), "Anchor Element" );
\r
178 document.body.removeChild( a );
\r
180 // Recursive function calls have lengths and array-like properties
\r
181 function callme(callback){
\r
182 function fn(response){
\r
183 callback(response);
\r
186 ok( jQuery.isFunction(fn), "Recursive Function Call" );
\r
188 fn({ some: "data" });
\r
192 callme(function(){});
\r
198 test("jQuery('html')", function() {
\r
203 var s = jQuery("<script>var foo='test';</script>")[0];
\r
204 ok( s, "Creating a script" );
\r
205 ok( !foo, "Make sure the script wasn't executed prematurely" );
\r
206 jQuery("body").append(s);
\r
207 ok( foo, "Executing a scripts contents in the right context" );
\r
210 ok( jQuery("<link rel='stylesheet'/>")[0], "Creating a link" );
\r
214 var j = jQuery("<span>hi</span> there <!-- mon ami -->");
\r
215 ok( j.length >= 2, "Check node,textnode,comment creation (some browsers delete comments)" );
\r
217 ok( !jQuery("<option>test</option>")[0].selected, "Make sure that options are auto-selected #2050" );
\r
220 test("jQuery('html', context)", function() {
\r
223 var $div = jQuery("<div/>");
\r
224 var $span = jQuery("<span/>", $div);
\r
225 equals($span.length, 1, "Verify a span created with a div context works, #1763");
\r
229 test("jQuery(selector, xml).text(str) - Loaded via XML document", function() {
\r
232 jQuery.get('data/dashboard.xml', function(xml) {
\r
233 // tests for #1419 where IE was a problem
\r
234 equals( jQuery("tab:first", xml).text(), "blabla", "Verify initial text correct" );
\r
235 jQuery("tab:first", xml).text("newtext");
\r
236 equals( jQuery("tab:first", xml).text(), "newtext", "Verify new text correct" );
\r
242 test("length", function() {
\r
244 equals( jQuery("p").length, 6, "Get Number of Elements Found" );
\r
247 test("size()", function() {
\r
249 equals( jQuery("p").size(), 6, "Get Number of Elements Found" );
\r
252 test("get()", function() {
\r
254 isSet( jQuery("p").get(), q("firstp","ap","sndp","en","sap","first"), "Get All Elements" );
\r
257 test("get(Number)", function() {
\r
259 equals( jQuery("p").get(0), document.getElementById("firstp"), "Get A Single Element" );
\r
262 test("add(String|Element|Array|undefined)", function() {
\r
264 isSet( jQuery("#sndp").add("#en").add("#sap").get(), q("sndp", "en", "sap"), "Check elements from document" );
\r
265 isSet( jQuery("#sndp").add( jQuery("#en")[0] ).add( jQuery("#sap") ).get(), q("sndp", "en", "sap"), "Check elements from document" );
\r
266 ok( jQuery([]).add(jQuery("#form")[0].elements).length >= 13, "Check elements from array" );
\r
268 // For the time being, we're discontinuing support for jQuery(form.elements) since it's ambiguous in IE
\r
269 // use jQuery([]).add(form.elements) instead.
\r
270 //equals( jQuery([]).add(jQuery("#form")[0].elements).length, jQuery(jQuery("#form")[0].elements).length, "Array in constructor must equals array in add()" );
\r
272 var x = jQuery([]).add(jQuery("<p id='x1'>xxx</p>")).add(jQuery("<p id='x2'>xxx</p>"));
\r
273 equals( x[0].id, "x1", "Check on-the-fly element1" );
\r
274 equals( x[1].id, "x2", "Check on-the-fly element2" );
\r
276 var x = jQuery([]).add("<p id='x1'>xxx</p>").add("<p id='x2'>xxx</p>");
\r
277 equals( x[0].id, "x1", "Check on-the-fly element1" );
\r
278 equals( x[1].id, "x2", "Check on-the-fly element2" );
\r
281 equals( jQuery([]).add(notDefined).length, 0, "Check that undefined adds nothing" );
\r
283 // Added after #2811
\r
284 equals( jQuery([]).add([window,document,document.body,document]).length, 3, "Pass an array" );
\r
285 equals( jQuery(document).add(document).length, 1, "Check duplicated elements" );
\r
286 equals( jQuery(window).add(window).length, 1, "Check duplicated elements using the window" );
\r
287 ok( jQuery([]).add( document.getElementById('form') ).length >= 13, "Add a form (adds the elements)" );
\r
290 test("each(Function)", function() {
\r
292 var div = jQuery("div");
\r
293 div.each(function(){this.foo = 'zoo';});
\r
295 for ( var i = 0; i < div.size(); i++ ) {
\r
296 if ( div.get(i).foo != "zoo" ) pass = false;
\r
298 ok( pass, "Execute a function, Relative" );
\r
301 test("index(Object)", function() {
\r
304 var elements = jQuery([window, document]),
\r
305 inputElements = jQuery('#radio1,#radio2,#check1,#check2');
\r
307 equals( elements.index(window), 0, "Check for index of elements" );
\r
308 equals( elements.index(document), 1, "Check for index of elements" );
\r
309 equals( inputElements.index(document.getElementById('radio1')), 0, "Check for index of elements" );
\r
310 equals( inputElements.index(document.getElementById('radio2')), 1, "Check for index of elements" );
\r
311 equals( inputElements.index(document.getElementById('check1')), 2, "Check for index of elements" );
\r
312 equals( inputElements.index(document.getElementById('check2')), 3, "Check for index of elements" );
\r
313 equals( inputElements.index(window), -1, "Check for not found index" );
\r
314 equals( inputElements.index(document), -1, "Check for not found index" );
\r
316 // enabled since [5500]
\r
317 equals( elements.index( elements ), 0, "Pass in a jQuery object" );
\r
318 equals( elements.index( elements.eq(1) ), 1, "Pass in a jQuery object" );
\r
321 test("attr(String)", function() {
\r
323 equals( jQuery('#text1').attr('value'), "Test", 'Check for value attribute' );
\r
324 equals( jQuery('#text1').attr('value', "Test2").attr('defaultValue'), "Test", 'Check for defaultValue attribute' );
\r
325 equals( jQuery('#text1').attr('type'), "text", 'Check for type attribute' );
\r
326 equals( jQuery('#radio1').attr('type'), "radio", 'Check for type attribute' );
\r
327 equals( jQuery('#check1').attr('type'), "checkbox", 'Check for type attribute' );
\r
328 equals( jQuery('#simon1').attr('rel'), "bookmark", 'Check for rel attribute' );
\r
329 equals( jQuery('#google').attr('title'), "Google!", 'Check for title attribute' );
\r
330 equals( jQuery('#mark').attr('hreflang'), "en", 'Check for hreflang attribute' );
\r
331 equals( jQuery('#en').attr('lang'), "en", 'Check for lang attribute' );
\r
332 equals( jQuery('#simon').attr('class'), "blog link", 'Check for class attribute' );
\r
333 equals( jQuery('#name').attr('name'), "name", 'Check for name attribute' );
\r
334 equals( jQuery('#text1').attr('name'), "action", 'Check for name attribute' );
\r
335 ok( jQuery('#form').attr('action').indexOf("formaction") >= 0, 'Check for action attribute' );
\r
336 equals( jQuery('#text1').attr('maxlength'), '30', 'Check for maxlength attribute' );
\r
337 equals( jQuery('#text1').attr('maxLength'), '30', 'Check for maxLength attribute' );
\r
338 equals( jQuery('#area1').attr('maxLength'), '30', 'Check for maxLength attribute' );
\r
339 equals( jQuery('#select2').attr('selectedIndex'), 3, 'Check for selectedIndex attribute' );
\r
340 equals( jQuery('#foo').attr('nodeName'), 'DIV', 'Check for nodeName attribute' );
\r
341 equals( jQuery('#foo').attr('tagName'), 'DIV', 'Check for tagName attribute' );
\r
343 jQuery('<a id="tAnchor5"></a>').attr('href', '#5').appendTo('#main'); // using innerHTML in IE causes href attribute to be serialized to the full path
\r
344 equals( jQuery('#tAnchor5').attr('href'), "#5", 'Check for non-absolute href (an anchor)' );
\r
347 // Related to [5574] and [5683]
\r
348 var body = document.body, $body = jQuery(body);
\r
350 ok( $body.attr('foo') === undefined, 'Make sure that a non existent attribute returns undefined' );
\r
351 ok( $body.attr('nextSibling') === null, 'Make sure a null expando returns null' );
\r
353 body.setAttribute('foo', 'baz');
\r
354 equals( $body.attr('foo'), 'baz', 'Make sure the dom attribute is retrieved when no expando is found' );
\r
357 equals( $body.attr('foo'), 'bar', 'Make sure the expando is preferred over the dom attribute' );
\r
359 $body.attr('foo','cool');
\r
360 equals( $body.attr('foo'), 'cool', 'Make sure that setting works well when both expando and dom attribute are available' );
\r
362 body.foo = undefined;
\r
363 ok( $body.attr('foo') === undefined, 'Make sure the expando is preferred over the dom attribute, even if undefined' );
\r
365 body.removeAttribute('foo'); // Cleanup
\r
369 test("attr(String) in XML Files", function() {
\r
372 jQuery.get("data/dashboard.xml", function(xml) {
\r
373 equals( jQuery("locations", xml).attr("class"), "foo", "Check class attribute in XML document" );
\r
374 equals( jQuery("location", xml).attr("for"), "bar", "Check for attribute in XML document" );
\r
380 test("attr(String, Function)", function() {
\r
382 equals( jQuery('#text1').attr('value', function() { return this.id })[0].value, "text1", "Set value from id" );
\r
383 equals( jQuery('#text1').attr('title', function(i) { return i }).attr('title'), "0", "Set value with an index");
\r
386 test("attr(Hash)", function() {
\r
389 jQuery("div").attr({foo: 'baz', zoo: 'ping'}).each(function(){
\r
390 if ( this.getAttribute('foo') != "baz" && this.getAttribute('zoo') != "ping" ) pass = false;
\r
392 ok( pass, "Set Multiple Attributes" );
\r
395 test("attr(String, Object)", function() {
\r
397 var div = jQuery("div").attr("foo", "bar");
\r
399 for ( var i = 0; i < div.size(); i++ ) {
\r
400 if ( div.get(i).getAttribute('foo') != "bar" ){
\r
405 equals( fail, false, "Set Attribute, the #"+fail+" element didn't get the attribute 'foo'" );
\r
407 ok( jQuery("#foo").attr({"width": null}), "Try to set an attribute to nothing" );
\r
409 jQuery("#name").attr('name', 'something');
\r
410 equals( jQuery("#name").attr('name'), 'something', 'Set name attribute' );
\r
411 jQuery("#check2").attr('checked', true);
\r
412 equals( document.getElementById('check2').checked, true, 'Set checked attribute' );
\r
413 jQuery("#check2").attr('checked', false);
\r
414 equals( document.getElementById('check2').checked, false, 'Set checked attribute' );
\r
415 jQuery("#text1").attr('readonly', true);
\r
416 equals( document.getElementById('text1').readOnly, true, 'Set readonly attribute' );
\r
417 jQuery("#text1").attr('readonly', false);
\r
418 equals( document.getElementById('text1').readOnly, false, 'Set readonly attribute' );
\r
419 jQuery("#name").attr('maxlength', '5');
\r
420 equals( document.getElementById('name').maxLength, '5', 'Set maxlength attribute' );
\r
421 jQuery("#name").attr('maxLength', '10');
\r
422 equals( document.getElementById('name').maxLength, '10', 'Set maxlength attribute' );
\r
425 jQuery("#name").attr('someAttr', '0');
\r
426 equals( jQuery("#name").attr('someAttr'), '0', 'Set attribute to a string of "0"' );
\r
427 jQuery("#name").attr('someAttr', 0);
\r
428 equals( jQuery("#name").attr('someAttr'), 0, 'Set attribute to the number 0' );
\r
429 jQuery("#name").attr('someAttr', 1);
\r
430 equals( jQuery("#name").attr('someAttr'), 1, 'Set attribute to the number 1' );
\r
432 // using contents will get comments regular, text, and comment nodes
\r
433 var j = jQuery("#nonnodes").contents();
\r
435 j.attr("name", "attrvalue");
\r
436 equals( j.attr("name"), "attrvalue", "Check node,textnode,comment for attr" );
\r
437 j.removeAttr("name");
\r
441 var type = jQuery("#check2").attr('type');
\r
442 var thrown = false;
\r
444 jQuery("#check2").attr('type','hidden');
\r
448 ok( thrown, "Exception thrown when trying to change type property" );
\r
449 equals( type, jQuery("#check2").attr('type'), "Verify that you can't change the type of an input element" );
\r
451 var check = document.createElement("input");
\r
454 jQuery(check).attr('type','checkbox');
\r
458 ok( thrown, "Exception thrown when trying to change type property" );
\r
459 equals( "checkbox", jQuery(check).attr('type'), "Verify that you can change the type of an input element that isn't in the DOM" );
\r
463 test("attr(String, Object) - Loaded via XML document", function() {
\r
466 jQuery.get('data/dashboard.xml', function(xml) {
\r
468 jQuery('tab', xml).each(function() {
\r
469 titles.push(jQuery(this).attr('title'));
\r
471 equals( titles[0], 'Location', 'attr() in XML context: Check first title' );
\r
472 equals( titles[1], 'Users', 'attr() in XML context: Check second title' );
\r
478 test("css(String|Hash)", function() {
\r
481 equals( jQuery('#main').css("display"), 'none', 'Check for css property "display"');
\r
483 ok( jQuery('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
\r
484 jQuery('#foo').css({display: 'none'});
\r
485 ok( !jQuery('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
\r
486 jQuery('#foo').css({display: 'block'});
\r
487 ok( jQuery('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
\r
489 jQuery('#floatTest').css({styleFloat: 'right'});
\r
490 equals( jQuery('#floatTest').css('styleFloat'), 'right', 'Modified CSS float using "styleFloat": Assert float is right');
\r
491 jQuery('#floatTest').css({cssFloat: 'left'});
\r
492 equals( jQuery('#floatTest').css('cssFloat'), 'left', 'Modified CSS float using "cssFloat": Assert float is left');
\r
493 jQuery('#floatTest').css({'float': 'right'});
\r
494 equals( jQuery('#floatTest').css('float'), 'right', 'Modified CSS float using "float": Assert float is right');
\r
495 jQuery('#floatTest').css({'font-size': '30px'});
\r
496 equals( jQuery('#floatTest').css('font-size'), '30px', 'Modified CSS font-size: Assert font-size is 30px');
\r
498 jQuery.each("0,0.25,0.5,0.75,1".split(','), function(i, n) {
\r
499 jQuery('#foo').css({opacity: n});
\r
500 equals( jQuery('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" );
\r
501 jQuery('#foo').css({opacity: parseFloat(n)});
\r
502 equals( jQuery('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" );
\r
504 jQuery('#foo').css({opacity: ''});
\r
505 equals( jQuery('#foo').css('opacity'), '1', "Assert opacity is 1 when set to an empty String" );
\r
508 test("css(String, Object)", function() {
\r
510 ok( jQuery('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
\r
511 jQuery('#foo').css('display', 'none');
\r
512 ok( !jQuery('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
\r
513 jQuery('#foo').css('display', 'block');
\r
514 ok( jQuery('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
\r
516 jQuery('#floatTest').css('styleFloat', 'left');
\r
517 equals( jQuery('#floatTest').css('styleFloat'), 'left', 'Modified CSS float using "styleFloat": Assert float is left');
\r
518 jQuery('#floatTest').css('cssFloat', 'right');
\r
519 equals( jQuery('#floatTest').css('cssFloat'), 'right', 'Modified CSS float using "cssFloat": Assert float is right');
\r
520 jQuery('#floatTest').css('float', 'left');
\r
521 equals( jQuery('#floatTest').css('float'), 'left', 'Modified CSS float using "float": Assert float is left');
\r
522 jQuery('#floatTest').css('font-size', '20px');
\r
523 equals( jQuery('#floatTest').css('font-size'), '20px', 'Modified CSS font-size: Assert font-size is 20px');
\r
525 jQuery.each("0,0.25,0.5,0.75,1".split(','), function(i, n) {
\r
526 jQuery('#foo').css('opacity', n);
\r
527 equals( jQuery('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" );
\r
528 jQuery('#foo').css('opacity', parseFloat(n));
\r
529 equals( jQuery('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" );
\r
531 jQuery('#foo').css('opacity', '');
\r
532 equals( jQuery('#foo').css('opacity'), '1', "Assert opacity is 1 when set to an empty String" );
\r
533 // for #1438, IE throws JS error when filter exists but doesn't have opacity in it
\r
534 if (jQuery.browser.msie) {
\r
535 jQuery('#foo').css("filter", "progid:DXImageTransform.Microsoft.Chroma(color='red');");
\r
537 equals( jQuery('#foo').css('opacity'), '1', "Assert opacity is 1 when a different filter is set in IE, #1438" );
\r
539 // using contents will get comments regular, text, and comment nodes
\r
540 var j = jQuery("#nonnodes").contents();
\r
541 j.css("padding-left", "1px");
\r
542 equals( j.css("padding-left"), "1px", "Check node,textnode,comment css works" );
\r
544 // opera sometimes doesn't update 'display' correctly, see #2037
\r
545 jQuery("#t2037")[0].innerHTML = jQuery("#t2037")[0].innerHTML
\r
546 equals( jQuery("#t2037 .hidden").css("display"), "none", "Make sure browser thinks it is hidden" );
\r
549 test("jQuery.css(elem, 'height') doesn't clear radio buttons (bug #1095)", function () {
\r
552 var $checkedtest = jQuery("#checkedtest");
\r
553 // IE6 was clearing "checked" in jQuery.css(elem, "height");
\r
554 jQuery.css($checkedtest[0], "height");
\r
555 ok( !! jQuery(":radio:first", $checkedtest).attr("checked"), "Check first radio still checked." );
\r
556 ok( ! jQuery(":radio:last", $checkedtest).attr("checked"), "Check last radio still NOT checked." );
\r
557 ok( !! jQuery(":checkbox:first", $checkedtest).attr("checked"), "Check first checkbox still checked." );
\r
558 ok( ! jQuery(":checkbox:last", $checkedtest).attr("checked"), "Check last checkbox still NOT checked." );
\r
561 test("width()", function() {
\r
564 var $div = jQuery("#nothiddendiv");
\r
566 equals($div.width(), 30, "Test set to 30 correctly");
\r
567 $div.width(-1); // handle negative numbers by ignoring #1599
\r
568 equals($div.width(), 30, "Test negative width ignored");
\r
569 $div.css("padding", "20px");
\r
570 equals($div.width(), 30, "Test padding specified with pixels");
\r
571 $div.css("border", "2px solid #fff");
\r
572 equals($div.width(), 30, "Test border specified with pixels");
\r
573 $div.css("padding", "2em");
\r
574 equals($div.width(), 30, "Test padding specified with ems");
\r
575 $div.css("border", "1em solid #fff");
\r
576 equals($div.width(), 30, "Test border specified with ems");
\r
577 $div.css("padding", "2%");
\r
578 equals($div.width(), 30, "Test padding specified with percent");
\r
580 equals($div.width(), 30, "Test hidden div");
\r
582 $div.css({ display: "", border: "", padding: "" });
\r
584 jQuery("#nothiddendivchild").css({ padding: "3px", border: "2px solid #fff" });
\r
585 equals(jQuery("#nothiddendivchild").width(), 20, "Test child width with border and padding");
\r
586 jQuery("#nothiddendiv, #nothiddendivchild").css({ border: "", padding: "", width: "" });
\r
589 test("height()", function() {
\r
592 var $div = jQuery("#nothiddendiv");
\r
594 equals($div.height(), 30, "Test set to 30 correctly");
\r
595 $div.height(-1); // handle negative numbers by ignoring #1599
\r
596 equals($div.height(), 30, "Test negative height ignored");
\r
597 $div.css("padding", "20px");
\r
598 equals($div.height(), 30, "Test padding specified with pixels");
\r
599 $div.css("border", "2px solid #fff");
\r
600 equals($div.height(), 30, "Test border specified with pixels");
\r
601 $div.css("padding", "2em");
\r
602 equals($div.height(), 30, "Test padding specified with ems");
\r
603 $div.css("border", "1em solid #fff");
\r
604 equals($div.height(), 30, "Test border specified with ems");
\r
605 $div.css("padding", "2%");
\r
606 equals($div.height(), 30, "Test padding specified with percent");
\r
608 equals($div.height(), 30, "Test hidden div");
\r
610 $div.css({ display: "", border: "", padding: "", height: "1px" });
\r
613 test("text()", function() {
\r
615 var expected = "This link has class=\"blog\": Simon Willison's Weblog";
\r
616 equals( jQuery('#sap').text(), expected, 'Check for merged text of more then one element.' );
\r
619 test("wrap(String|Element)", function() {
\r
621 var defaultText = 'Try them out:'
\r
622 var result = jQuery('#first').wrap('<div class="red"><span></span></div>').text();
\r
623 equals( defaultText, result, 'Check for wrapping of on-the-fly html' );
\r
624 ok( jQuery('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
\r
627 var defaultText = 'Try them out:'
\r
628 var result = jQuery('#first').wrap(document.getElementById('empty')).parent();
\r
629 ok( result.is('ol'), 'Check for element wrapping' );
\r
630 equals( result.text(), defaultText, 'Check for element wrapping' );
\r
633 jQuery('#check1').click(function() {
\r
634 var checkbox = this;
\r
635 ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
\r
636 jQuery(checkbox).wrap( '<div id="c1" style="display:none;"></div>' );
\r
637 ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
\r
640 // using contents will get comments regular, text, and comment nodes
\r
641 var j = jQuery("#nonnodes").contents();
\r
643 equals( jQuery("#nonnodes > i").length, 3, "Check node,textnode,comment wraps ok" );
\r
644 equals( jQuery("#nonnodes > i").text(), j.text() + j[1].nodeValue, "Check node,textnode,comment wraps doesn't hurt text" );
\r
647 test("wrapAll(String|Element)", function() {
\r
649 var prev = jQuery("#first")[0].previousSibling;
\r
650 var p = jQuery("#first")[0].parentNode;
\r
651 var result = jQuery('#first,#firstp').wrapAll('<div class="red"><div id="tmp"></div></div>');
\r
652 equals( result.parent().length, 1, 'Check for wrapping of on-the-fly html' );
\r
653 ok( jQuery('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
\r
654 ok( jQuery('#firstp').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
\r
655 equals( jQuery("#first").parent().parent()[0].previousSibling, prev, "Correct Previous Sibling" );
\r
656 equals( jQuery("#first").parent().parent()[0].parentNode, p, "Correct Parent" );
\r
659 var prev = jQuery("#first")[0].previousSibling;
\r
660 var p = jQuery("#first")[0].parentNode;
\r
661 var result = jQuery('#first,#firstp').wrapAll(document.getElementById('empty'));
\r
662 equals( jQuery("#first").parent()[0], jQuery("#firstp").parent()[0], "Same Parent" );
\r
663 equals( jQuery("#first").parent()[0].previousSibling, prev, "Correct Previous Sibling" );
\r
664 equals( jQuery("#first").parent()[0].parentNode, p, "Correct Parent" );
\r
667 test("wrapInner(String|Element)", function() {
\r
669 var num = jQuery("#first").children().length;
\r
670 var result = jQuery('#first').wrapInner('<div class="red"><div id="tmp"></div></div>');
\r
671 equals( jQuery("#first").children().length, 1, "Only one child" );
\r
672 ok( jQuery("#first").children().is(".red"), "Verify Right Element" );
\r
673 equals( jQuery("#first").children().children().children().length, num, "Verify Elements Intact" );
\r
676 var num = jQuery("#first").children().length;
\r
677 var result = jQuery('#first').wrapInner(document.getElementById('empty'));
\r
678 equals( jQuery("#first").children().length, 1, "Only one child" );
\r
679 ok( jQuery("#first").children().is("#empty"), "Verify Right Element" );
\r
680 equals( jQuery("#first").children().children().length, num, "Verify Elements Intact" );
\r
683 test("append(String|Element|Array<Element>|jQuery)", function() {
\r
685 var defaultText = 'Try them out:'
\r
686 var result = jQuery('#first').append('<b>buga</b>');
\r
687 equals( result.text(), defaultText + 'buga', 'Check if text appending works' );
\r
688 equals( jQuery('#select3').append('<option value="appendTest">Append Test</option>').find('option:last-child').attr('value'), 'appendTest', 'Appending html options to select element');
\r
691 var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
\r
692 jQuery('#sap').append(document.getElementById('first'));
\r
693 equals( expected, jQuery('#sap').text(), "Check for appending of element" );
\r
696 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
\r
697 jQuery('#sap').append([document.getElementById('first'), document.getElementById('yahoo')]);
\r
698 equals( expected, jQuery('#sap').text(), "Check for appending of array of elements" );
\r
701 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
\r
702 jQuery('#sap').append(jQuery("#first, #yahoo"));
\r
703 equals( expected, jQuery('#sap').text(), "Check for appending of jQuery object" );
\r
706 jQuery("#sap").append( 5 );
\r
707 ok( jQuery("#sap")[0].innerHTML.match( /5$/ ), "Check for appending a number" );
\r
710 jQuery("#sap").append( " text with spaces " );
\r
711 ok( jQuery("#sap")[0].innerHTML.match(/ text with spaces $/), "Check for appending text with spaces" );
\r
714 ok( jQuery("#sap").append([]), "Check for appending an empty array." );
\r
715 ok( jQuery("#sap").append(""), "Check for appending an empty string." );
\r
716 ok( jQuery("#sap").append(document.getElementsByTagName("foo")), "Check for appending an empty nodelist." );
\r
719 jQuery("#sap").append(document.getElementById('form'));
\r
720 equals( jQuery("#sap>form").size(), 1, "Check for appending a form" ); // Bug #910
\r
725 jQuery( jQuery("#iframe")[0].contentWindow.document.body ).append("<div>test</div>");
\r
730 ok( pass, "Test for appending a DOM node to the contents of an IFrame" );
\r
733 jQuery('<fieldset/>').appendTo('#form').append('<legend id="legend">test</legend>');
\r
734 t( 'Append legend', '#legend', ['legend'] );
\r
737 jQuery('#select1').append('<OPTION>Test</OPTION>');
\r
738 equals( jQuery('#select1 option:last').text(), "Test", "Appending <OPTION> (all caps)" );
\r
740 jQuery('#table').append('<colgroup></colgroup>');
\r
741 ok( jQuery('#table colgroup').length, "Append colgroup" );
\r
743 jQuery('#table colgroup').append('<col/>');
\r
744 ok( jQuery('#table colgroup col').length, "Append col" );
\r
747 jQuery('#table').append('<caption></caption>');
\r
748 ok( jQuery('#table caption').length, "Append caption" );
\r
751 jQuery('form:last')
\r
752 .append('<select id="appendSelect1"></select>')
\r
753 .append('<select id="appendSelect2"><option>Test</option></select>');
\r
755 t( "Append Select", "#appendSelect1, #appendSelect2", ["appendSelect1", "appendSelect2"] );
\r
757 // using contents will get comments regular, text, and comment nodes
\r
758 var j = jQuery("#nonnodes").contents();
\r
759 var d = jQuery("<div/>").appendTo("#nonnodes").append(j);
\r
760 equals( jQuery("#nonnodes").length, 1, "Check node,textnode,comment append moved leaving just the div" );
\r
761 ok( d.contents().length >= 2, "Check node,textnode,comment append works" );
\r
762 d.contents().appendTo("#nonnodes");
\r
764 ok( jQuery("#nonnodes").contents().length >= 2, "Check node,textnode,comment append cleanup worked" );
\r
767 test("appendTo(String|Element|Array<Element>|jQuery)", function() {
\r
769 var defaultText = 'Try them out:'
\r
770 jQuery('<b>buga</b>').appendTo('#first');
\r
771 equals( jQuery("#first").text(), defaultText + 'buga', 'Check if text appending works' );
\r
772 equals( jQuery('<option value="appendTest">Append Test</option>').appendTo('#select3').parent().find('option:last-child').attr('value'), 'appendTest', 'Appending html options to select element');
\r
775 var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
\r
776 jQuery(document.getElementById('first')).appendTo('#sap');
\r
777 equals( expected, jQuery('#sap').text(), "Check for appending of element" );
\r
780 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
\r
781 jQuery([document.getElementById('first'), document.getElementById('yahoo')]).appendTo('#sap');
\r
782 equals( expected, jQuery('#sap').text(), "Check for appending of array of elements" );
\r
785 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
\r
786 jQuery("#first, #yahoo").appendTo('#sap');
\r
787 equals( expected, jQuery('#sap').text(), "Check for appending of jQuery object" );
\r
790 jQuery('#select1').appendTo('#foo');
\r
791 t( 'Append select', '#foo select', ['select1'] );
\r
794 test("prepend(String|Element|Array<Element>|jQuery)", function() {
\r
796 var defaultText = 'Try them out:'
\r
797 var result = jQuery('#first').prepend('<b>buga</b>');
\r
798 equals( result.text(), 'buga' + defaultText, 'Check if text prepending works' );
\r
799 equals( jQuery('#select3').prepend('<option value="prependTest">Prepend Test</option>').find('option:first-child').attr('value'), 'prependTest', 'Prepending html options to select element');
\r
802 var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
\r
803 jQuery('#sap').prepend(document.getElementById('first'));
\r
804 equals( expected, jQuery('#sap').text(), "Check for prepending of element" );
\r
807 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
\r
808 jQuery('#sap').prepend([document.getElementById('first'), document.getElementById('yahoo')]);
\r
809 equals( expected, jQuery('#sap').text(), "Check for prepending of array of elements" );
\r
812 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
\r
813 jQuery('#sap').prepend(jQuery("#first, #yahoo"));
\r
814 equals( expected, jQuery('#sap').text(), "Check for prepending of jQuery object" );
\r
817 test("prependTo(String|Element|Array<Element>|jQuery)", function() {
\r
819 var defaultText = 'Try them out:'
\r
820 jQuery('<b>buga</b>').prependTo('#first');
\r
821 equals( jQuery('#first').text(), 'buga' + defaultText, 'Check if text prepending works' );
\r
822 equals( jQuery('<option value="prependTest">Prepend Test</option>').prependTo('#select3').parent().find('option:first-child').attr('value'), 'prependTest', 'Prepending html options to select element');
\r
825 var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
\r
826 jQuery(document.getElementById('first')).prependTo('#sap');
\r
827 equals( expected, jQuery('#sap').text(), "Check for prepending of element" );
\r
830 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
\r
831 jQuery([document.getElementById('yahoo'), document.getElementById('first')]).prependTo('#sap');
\r
832 equals( expected, jQuery('#sap').text(), "Check for prepending of array of elements" );
\r
835 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
\r
836 jQuery("#yahoo, #first").prependTo('#sap');
\r
837 equals( expected, jQuery('#sap').text(), "Check for prepending of jQuery object" );
\r
840 jQuery('<select id="prependSelect1"></select>').prependTo('form:last');
\r
841 jQuery('<select id="prependSelect2"><option>Test</option></select>').prependTo('form:last');
\r
843 t( "Prepend Select", "#prependSelect1, #prependSelect2", ["prependSelect1", "prependSelect2"] );
\r
846 test("before(String|Element|Array<Element>|jQuery)", function() {
\r
848 var expected = 'This is a normal link: bugaYahoo';
\r
849 jQuery('#yahoo').before('<b>buga</b>');
\r
850 equals( expected, jQuery('#en').text(), 'Insert String before' );
\r
853 expected = "This is a normal link: Try them out:Yahoo";
\r
854 jQuery('#yahoo').before(document.getElementById('first'));
\r
855 equals( expected, jQuery('#en').text(), "Insert element before" );
\r
858 expected = "This is a normal link: Try them out:diveintomarkYahoo";
\r
859 jQuery('#yahoo').before([document.getElementById('first'), document.getElementById('mark')]);
\r
860 equals( expected, jQuery('#en').text(), "Insert array of elements before" );
\r
863 expected = "This is a normal link: Try them out:diveintomarkYahoo";
\r
864 jQuery('#yahoo').before(jQuery("#first, #mark"));
\r
865 equals( expected, jQuery('#en').text(), "Insert jQuery before" );
\r
868 test("insertBefore(String|Element|Array<Element>|jQuery)", function() {
\r
870 var expected = 'This is a normal link: bugaYahoo';
\r
871 jQuery('<b>buga</b>').insertBefore('#yahoo');
\r
872 equals( expected, jQuery('#en').text(), 'Insert String before' );
\r
875 expected = "This is a normal link: Try them out:Yahoo";
\r
876 jQuery(document.getElementById('first')).insertBefore('#yahoo');
\r
877 equals( expected, jQuery('#en').text(), "Insert element before" );
\r
880 expected = "This is a normal link: Try them out:diveintomarkYahoo";
\r
881 jQuery([document.getElementById('first'), document.getElementById('mark')]).insertBefore('#yahoo');
\r
882 equals( expected, jQuery('#en').text(), "Insert array of elements before" );
\r
885 expected = "This is a normal link: Try them out:diveintomarkYahoo";
\r
886 jQuery("#first, #mark").insertBefore('#yahoo');
\r
887 equals( expected, jQuery('#en').text(), "Insert jQuery before" );
\r
890 test("after(String|Element|Array<Element>|jQuery)", function() {
\r
892 var expected = 'This is a normal link: Yahoobuga';
\r
893 jQuery('#yahoo').after('<b>buga</b>');
\r
894 equals( expected, jQuery('#en').text(), 'Insert String after' );
\r
897 expected = "This is a normal link: YahooTry them out:";
\r
898 jQuery('#yahoo').after(document.getElementById('first'));
\r
899 equals( expected, jQuery('#en').text(), "Insert element after" );
\r
902 expected = "This is a normal link: YahooTry them out:diveintomark";
\r
903 jQuery('#yahoo').after([document.getElementById('first'), document.getElementById('mark')]);
\r
904 equals( expected, jQuery('#en').text(), "Insert array of elements after" );
\r
907 expected = "This is a normal link: YahooTry them out:diveintomark";
\r
908 jQuery('#yahoo').after(jQuery("#first, #mark"));
\r
909 equals( expected, jQuery('#en').text(), "Insert jQuery after" );
\r
912 test("insertAfter(String|Element|Array<Element>|jQuery)", function() {
\r
914 var expected = 'This is a normal link: Yahoobuga';
\r
915 jQuery('<b>buga</b>').insertAfter('#yahoo');
\r
916 equals( expected, jQuery('#en').text(), 'Insert String after' );
\r
919 expected = "This is a normal link: YahooTry them out:";
\r
920 jQuery(document.getElementById('first')).insertAfter('#yahoo');
\r
921 equals( expected, jQuery('#en').text(), "Insert element after" );
\r
924 expected = "This is a normal link: YahooTry them out:diveintomark";
\r
925 jQuery([document.getElementById('mark'), document.getElementById('first')]).insertAfter('#yahoo');
\r
926 equals( expected, jQuery('#en').text(), "Insert array of elements after" );
\r
929 expected = "This is a normal link: YahooTry them out:diveintomark";
\r
930 jQuery("#mark, #first").insertAfter('#yahoo');
\r
931 equals( expected, jQuery('#en').text(), "Insert jQuery after" );
\r
934 test("replaceWith(String|Element|Array<Element>|jQuery)", function() {
\r
936 jQuery('#yahoo').replaceWith('<b id="replace">buga</b>');
\r
937 ok( jQuery("#replace")[0], 'Replace element with string' );
\r
938 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after string' );
\r
941 jQuery('#yahoo').replaceWith(document.getElementById('first'));
\r
942 ok( jQuery("#first")[0], 'Replace element with element' );
\r
943 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after element' );
\r
946 jQuery('#yahoo').replaceWith([document.getElementById('first'), document.getElementById('mark')]);
\r
947 ok( jQuery("#first")[0], 'Replace element with array of elements' );
\r
948 ok( jQuery("#mark")[0], 'Replace element with array of elements' );
\r
949 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after array of elements' );
\r
952 jQuery('#yahoo').replaceWith(jQuery("#first, #mark"));
\r
953 ok( jQuery("#first")[0], 'Replace element with set of elements' );
\r
954 ok( jQuery("#mark")[0], 'Replace element with set of elements' );
\r
955 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after set of elements' );
\r
958 test("replaceAll(String|Element|Array<Element>|jQuery)", function() {
\r
960 jQuery('<b id="replace">buga</b>').replaceAll("#yahoo");
\r
961 ok( jQuery("#replace")[0], 'Replace element with string' );
\r
962 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after string' );
\r
965 jQuery(document.getElementById('first')).replaceAll("#yahoo");
\r
966 ok( jQuery("#first")[0], 'Replace element with element' );
\r
967 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after element' );
\r
970 jQuery([document.getElementById('first'), document.getElementById('mark')]).replaceAll("#yahoo");
\r
971 ok( jQuery("#first")[0], 'Replace element with array of elements' );
\r
972 ok( jQuery("#mark")[0], 'Replace element with array of elements' );
\r
973 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after array of elements' );
\r
976 jQuery("#first, #mark").replaceAll("#yahoo");
\r
977 ok( jQuery("#first")[0], 'Replace element with set of elements' );
\r
978 ok( jQuery("#mark")[0], 'Replace element with set of elements' );
\r
979 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after set of elements' );
\r
982 test("end()", function() {
\r
984 equals( 'Yahoo', jQuery('#yahoo').parent().end().text(), 'Check for end' );
\r
985 ok( jQuery('#yahoo').end(), 'Check for end with nothing to end' );
\r
987 var x = jQuery('#yahoo');
\r
989 equals( 'Yahoo', jQuery('#yahoo').text(), 'Check for non-destructive behaviour' );
\r
992 test("find(String)", function() {
\r
994 equals( 'Yahoo', jQuery('#foo').find('.blogTest').text(), 'Check for find' );
\r
996 // using contents will get comments regular, text, and comment nodes
\r
997 var j = jQuery("#nonnodes").contents();
\r
998 equals( j.find("div").length, 0, "Check node,textnode,comment to find zero divs" );
\r
1001 test("clone()", function() {
\r
1003 equals( 'This is a normal link: Yahoo', jQuery('#en').text(), 'Assert text for #en' );
\r
1004 var clone = jQuery('#yahoo').clone();
\r
1005 equals( 'Try them out:Yahoo', jQuery('#first').append(clone).text(), 'Check for clone' );
\r
1006 equals( 'This is a normal link: Yahoo', jQuery('#en').text(), 'Reassert text for #en' );
\r
1009 "<table/>", "<tr/>", "<td/>", "<div/>",
\r
1010 "<button/>", "<ul/>", "<ol/>", "<li/>",
\r
1011 "<input type='checkbox' />", "<select/>", "<option/>", "<textarea/>",
\r
1012 "<tbody/>", "<thead/>", "<tfoot/>", "<iframe/>"
\r
1014 for (var i = 0; i < cloneTags.length; i++) {
\r
1015 var j = jQuery(cloneTags[i]);
\r
1016 equals( j[0].tagName, j.clone()[0].tagName, 'Clone a <' + cloneTags[i].substring(1));
\r
1019 // using contents will get comments regular, text, and comment nodes
\r
1020 var cl = jQuery("#nonnodes").contents().clone();
\r
1021 ok( cl.length >= 2, "Check node,textnode,comment clone works (some browsers delete comments on clone)" );
\r
1025 test("clone() on XML nodes", function() {
\r
1028 jQuery.get("data/dashboard.xml", function (xml) {
\r
1029 var root = jQuery(xml.documentElement).clone();
\r
1030 jQuery("tab:first", xml).text("origval");
\r
1031 jQuery("tab:first", root).text("cloneval");
\r
1032 equals(jQuery("tab:first", xml).text(), "origval", "Check original XML node was correctly set");
\r
1033 equals(jQuery("tab:first", root).text(), "cloneval", "Check cloned XML node was correctly set");
\r
1039 test("is(String)", function() {
\r
1041 ok( jQuery('#form').is('form'), 'Check for element: A form must be a form' );
\r
1042 ok( !jQuery('#form').is('div'), 'Check for element: A form is not a div' );
\r
1043 ok( jQuery('#mark').is('.blog'), 'Check for class: Expected class "blog"' );
\r
1044 ok( !jQuery('#mark').is('.link'), 'Check for class: Did not expect class "link"' );
\r
1045 ok( jQuery('#simon').is('.blog.link'), 'Check for multiple classes: Expected classes "blog" and "link"' );
\r
1046 ok( !jQuery('#simon').is('.blogTest'), 'Check for multiple classes: Expected classes "blog" and "link", but not "blogTest"' );
\r
1047 ok( jQuery('#en').is('[lang="en"]'), 'Check for attribute: Expected attribute lang to be "en"' );
\r
1048 ok( !jQuery('#en').is('[lang="de"]'), 'Check for attribute: Expected attribute lang to be "en", not "de"' );
\r
1049 ok( jQuery('#text1').is('[type="text"]'), 'Check for attribute: Expected attribute type to be "text"' );
\r
1050 ok( !jQuery('#text1').is('[type="radio"]'), 'Check for attribute: Expected attribute type to be "text", not "radio"' );
\r
1051 ok( jQuery('#text2').is(':disabled'), 'Check for pseudoclass: Expected to be disabled' );
\r
1052 ok( !jQuery('#text1').is(':disabled'), 'Check for pseudoclass: Expected not disabled' );
\r
1053 ok( jQuery('#radio2').is(':checked'), 'Check for pseudoclass: Expected to be checked' );
\r
1054 ok( !jQuery('#radio1').is(':checked'), 'Check for pseudoclass: Expected not checked' );
\r
1055 ok( jQuery('#foo').is(':has(p)'), 'Check for child: Expected a child "p" element' );
\r
1056 ok( !jQuery('#foo').is(':has(ul)'), 'Check for child: Did not expect "ul" element' );
\r
1057 ok( jQuery('#foo').is(':has(p):has(a):has(code)'), 'Check for childs: Expected "p", "a" and "code" child elements' );
\r
1058 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"' );
\r
1059 ok( !jQuery('#foo').is(0), 'Expected false for an invalid expression - 0' );
\r
1060 ok( !jQuery('#foo').is(null), 'Expected false for an invalid expression - null' );
\r
1061 ok( !jQuery('#foo').is(''), 'Expected false for an invalid expression - ""' );
\r
1062 ok( !jQuery('#foo').is(undefined), 'Expected false for an invalid expression - undefined' );
\r
1064 // test is() with comma-seperated expressions
\r
1065 ok( jQuery('#en').is('[lang="en"],[lang="de"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
\r
1066 ok( jQuery('#en').is('[lang="de"],[lang="en"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
\r
1067 ok( jQuery('#en').is('[lang="en"] , [lang="de"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
\r
1068 ok( jQuery('#en').is('[lang="de"] , [lang="en"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
\r
1071 test("jQuery.extend(Object, Object)", function() {
\r
1074 var settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
\r
1075 options = { xnumber2: 1, xstring2: "x", xxx: "newstring" },
\r
1076 optionsCopy = { xnumber2: 1, xstring2: "x", xxx: "newstring" },
\r
1077 merged = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "x", xxx: "newstring" },
\r
1078 deep1 = { foo: { bar: true } },
\r
1079 deep1copy = { foo: { bar: true } },
\r
1080 deep2 = { foo: { baz: true }, foo2: document },
\r
1081 deep2copy = { foo: { baz: true }, foo2: document },
\r
1082 deepmerged = { foo: { bar: true, baz: true }, foo2: document };
\r
1084 jQuery.extend(settings, options);
\r
1085 isObj( settings, merged, "Check if extended: settings must be extended" );
\r
1086 isObj( options, optionsCopy, "Check if not modified: options must not be modified" );
\r
1088 jQuery.extend(settings, null, options);
\r
1089 isObj( settings, merged, "Check if extended: settings must be extended" );
\r
1090 isObj( options, optionsCopy, "Check if not modified: options must not be modified" );
\r
1092 jQuery.extend(true, deep1, deep2);
\r
1093 isObj( deep1.foo, deepmerged.foo, "Check if foo: settings must be extended" );
\r
1094 isObj( deep2.foo, deep2copy.foo, "Check if not deep2: options must not be modified" );
\r
1095 equals( deep1.foo2, document, "Make sure that a deep clone was not attempted on the document" );
\r
1098 nullUndef = jQuery.extend({}, options, { xnumber2: null });
\r
1099 ok( nullUndef.xnumber2 === null, "Check to make sure null values are copied");
\r
1101 nullUndef = jQuery.extend({}, options, { xnumber2: undefined });
\r
1102 ok( nullUndef.xnumber2 === options.xnumber2, "Check to make sure undefined values are not copied");
\r
1104 nullUndef = jQuery.extend({}, options, { xnumber0: null });
\r
1105 ok( nullUndef.xnumber0 === null, "Check to make sure null values are inserted");
\r
1108 var recursive = { foo:target, bar:5 };
\r
1109 jQuery.extend(true, target, recursive);
\r
1110 isObj( target, { bar:5 }, "Check to make sure a recursive obj doesn't go never-ending loop by not copying it over" );
\r
1112 var ret = jQuery.extend(true, { foo: [] }, { foo: [0] } ); // 1907
\r
1113 equals( ret.foo.length, 1, "Check to make sure a value with coersion 'false' copies over when necessary to fix #1907" );
\r
1115 var ret = jQuery.extend(true, { foo: "1,2,3" }, { foo: [1, 2, 3] } );
\r
1116 ok( typeof ret.foo != "string", "Check to make sure values equal with coersion (but not actually equal) overwrite correctly" );
\r
1118 var ret = jQuery.extend(true, { foo:"bar" }, { foo:null } );
\r
1119 ok( typeof ret.foo !== 'undefined', "Make sure a null value doesn't crash with deep extend, for #1908" );
\r
1121 var obj = { foo:null };
\r
1122 jQuery.extend(true, obj, { foo:"notnull" } );
\r
1123 equals( obj.foo, "notnull", "Make sure a null value can be overwritten" );
\r
1125 function func() {}
\r
1126 jQuery.extend(func, { key: "value" } );
\r
1127 equals( func.key, "value", "Verify a function can be extended" );
\r
1129 var defaults = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
\r
1130 defaultsCopy = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
\r
1131 options1 = { xnumber2: 1, xstring2: "x" },
\r
1132 options1Copy = { xnumber2: 1, xstring2: "x" },
\r
1133 options2 = { xstring2: "xx", xxx: "newstringx" },
\r
1134 options2Copy = { xstring2: "xx", xxx: "newstringx" },
\r
1135 merged2 = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "xx", xxx: "newstringx" };
\r
1137 var settings = jQuery.extend({}, defaults, options1, options2);
\r
1138 isObj( settings, merged2, "Check if extended: settings must be extended" );
\r
1139 isObj( defaults, defaultsCopy, "Check if not modified: options1 must not be modified" );
\r
1140 isObj( options1, options1Copy, "Check if not modified: options1 must not be modified" );
\r
1141 isObj( options2, options2Copy, "Check if not modified: options2 must not be modified" );
\r
1144 test("val()", function() {
\r
1147 equals( jQuery("#text1").val(), "Test", "Check for value of input element" );
\r
1148 // ticket #1714 this caused a JS error in IE
\r
1149 equals( jQuery("#first").val(), "", "Check a paragraph element to see if it has a value" );
\r
1150 ok( jQuery([]).val() === undefined, "Check an empty jQuery object will return undefined from val" );
\r
1152 equals( jQuery('#select2').val(), '3', 'Call val() on a single="single" select' );
\r
1154 isSet( jQuery('#select3').val(), ['1', '2'], 'Call val() on a multiple="multiple" select' );
\r
1156 equals( jQuery('#option3c').val(), '2', 'Call val() on a option element with value' );
\r
1158 equals( jQuery('#option3a').val(), '', 'Call val() on a option element with empty value' );
\r
1160 equals( jQuery('#option3e').val(), 'no value', 'Call val() on a option element with no value attribute' );
\r
1164 test("val(String/Number)", function() {
\r
1166 document.getElementById('text1').value = "bla";
\r
1167 equals( jQuery("#text1").val(), "bla", "Check for modified value of input element" );
\r
1169 jQuery("#text1").val('test');
\r
1170 equals( document.getElementById('text1').value, "test", "Check for modified (via val(String)) value of input element" );
\r
1172 jQuery("#text1").val(67);
\r
1173 equals( document.getElementById('text1').value, "67", "Check for modified (via val(Number)) value of input element" );
\r
1175 jQuery("#select1").val("3");
\r
1176 equals( jQuery("#select1").val(), "3", "Check for modified (via val(String)) value of select element" );
\r
1178 jQuery("#select1").val(2);
\r
1179 equals( jQuery("#select1").val(), "2", "Check for modified (via val(Number)) value of select element" );
\r
1181 // using contents will get comments regular, text, and comment nodes
\r
1182 var j = jQuery("#nonnodes").contents();
\r
1184 equals( j.val(), "asdf", "Check node,textnode,comment with val()" );
\r
1185 j.removeAttr("value");
\r
1188 var scriptorder = 0;
\r
1190 test("html(String)", function() {
\r
1192 var div = jQuery("#main > div");
\r
1193 div.html("<b>test</b>");
\r
1195 for ( var i = 0; i < div.size(); i++ ) {
\r
1196 if ( div.get(i).childNodes.length != 1 ) pass = false;
\r
1198 ok( pass, "Set HTML" );
\r
1201 // using contents will get comments regular, text, and comment nodes
\r
1202 var j = jQuery("#nonnodes").contents();
\r
1203 j.html("<b>bold</b>");
\r
1205 // this is needed, or the expando added by jQuery unique will yield a different html
\r
1206 j.find('b').removeData();
\r
1207 equals( j.html().toLowerCase(), "<b>bold</b>", "Check node,textnode,comment with html()" );
\r
1209 jQuery("#main").html("<select/>");
\r
1210 jQuery("#main select").html("<option>O1</option><option selected='selected'>O2</option><option>O3</option>");
\r
1211 equals( jQuery("#main select").val(), "O2", "Selected option correct" );
\r
1213 var $div = jQuery('<div />');
\r
1214 equals( $div.html( 5 ).html(), '5', 'Setting a number as html' );
\r
1215 equals( $div.html( 0 ).html(), '0', 'Setting a zero as html' );
\r
1219 jQuery("#main").html('<script type="text/javascript">ok( true, "jQuery().html().evalScripts() Evals Scripts Twice in Firefox, see #975" );</script>');
\r
1221 jQuery("#main").html('foo <form><script type="text/javascript">ok( true, "jQuery().html().evalScripts() Evals Scripts Twice in Firefox, see #975" );</script></form>');
\r
1223 // 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
1224 jQuery("#main").html("<script>equals(scriptorder++, 0, 'Script is executed in order');equals(jQuery('#scriptorder').length, 1,'Execute after html (even though appears before)')<\/script><span id='scriptorder'><script>equals(scriptorder++, 1, 'Script (nested) is executed in order');equals(jQuery('#scriptorder').length, 1,'Execute after html')<\/script></span><script>equals(scriptorder++, 2, 'Script (unnested) is executed in order');equals(jQuery('#scriptorder').length, 1,'Execute after html')<\/script>");
\r
1226 setTimeout( start, 100 );
\r
1229 test("filter()", function() {
\r
1231 isSet( jQuery("#form input").filter(":checked").get(), q("radio2", "check1"), "filter(String)" );
\r
1232 isSet( jQuery("p").filter("#ap, #sndp").get(), q("ap", "sndp"), "filter('String, String')" );
\r
1233 isSet( jQuery("p").filter("#ap,#sndp").get(), q("ap", "sndp"), "filter('String,String')" );
\r
1234 isSet( jQuery("p").filter(function() { return !jQuery("a", this).length }).get(), q("sndp", "first"), "filter(Function)" );
\r
1236 // using contents will get comments regular, text, and comment nodes
\r
1237 var j = jQuery("#nonnodes").contents();
\r
1238 equals( j.filter("span").length, 1, "Check node,textnode,comment to filter the one span" );
\r
1239 equals( j.filter("[name]").length, 0, "Check node,textnode,comment to filter the one span" );
\r
1242 test("not()", function() {
\r
1244 equals( jQuery("#main > p#ap > a").not("#google").length, 2, "not('selector')" );
\r
1245 equals( jQuery("#main > p#ap > a").not(document.getElementById("google")).length, 2, "not(DOMElement)" );
\r
1246 isSet( jQuery("p").not(".result").get(), q("firstp", "ap", "sndp", "en", "sap", "first"), "not('.class')" );
\r
1247 isSet( jQuery("p").not("#ap, #sndp, .result").get(), q("firstp", "en", "sap", "first"), "not('selector, selector')" );
\r
1248 isSet( jQuery("p").not(jQuery("#ap, #sndp, .result")).get(), q("firstp", "en", "sap", "first"), "not(jQuery)" );
\r
1249 equals( jQuery("p").not(document.getElementsByTagName("p")).length, 0, "not(Array-like DOM collection)" );
\r
1250 isSet( jQuery("#form option").not("option.emptyopt:contains('Nothing'),[selected],[value='1']").get(), q("option1c", "option1d", "option2c", "option3d", "option3e" ), "not('complex selector')");
\r
1252 var selects = jQuery("#form select");
\r
1253 isSet( selects.not( selects[1] ), q("select1", "select3"), "filter out DOM element");
\r
1256 test("andSelf()", function() {
\r
1258 isSet( jQuery("#en").siblings().andSelf().get(), q("sndp", "sap","en"), "Check for siblings and self" );
\r
1259 isSet( jQuery("#foo").children().andSelf().get(), q("sndp", "en", "sap", "foo"), "Check for children and self" );
\r
1260 isSet( jQuery("#en, #sndp").parent().andSelf().get(), q("foo","en","sndp"), "Check for parent and self" );
\r
1261 isSet( jQuery("#groups").parents("p, div").andSelf().get(), q("ap", "main", "groups"), "Check for parents and self" );
\r
1264 test("siblings([String])", function() {
\r
1266 isSet( jQuery("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" );
\r
1267 isSet( jQuery("#sndp").siblings(":has(code)").get(), q("sap"), "Check for filtered siblings (has code child element)" );
\r
1268 isSet( jQuery("#sndp").siblings(":has(a)").get(), q("en", "sap"), "Check for filtered siblings (has anchor child element)" );
\r
1269 isSet( jQuery("#foo").siblings("form, b").get(), q("form", "lengthtest", "testForm", "floatTest"), "Check for multiple filters" );
\r
1270 isSet( jQuery("#en, #sndp").siblings().get(), q("sndp", "sap", "en"), "Check for unique results from siblings" );
\r
1273 test("children([String])", function() {
\r
1275 isSet( jQuery("#foo").children().get(), q("sndp", "en", "sap"), "Check for children" );
\r
1276 isSet( jQuery("#foo").children(":has(code)").get(), q("sndp", "sap"), "Check for filtered children" );
\r
1277 isSet( jQuery("#foo").children("#en, #sap").get(), q("en", "sap"), "Check for multiple filters" );
\r
1280 test("parent([String])", function() {
\r
1282 equals( jQuery("#groups").parent()[0].id, "ap", "Simple parent check" );
\r
1283 equals( jQuery("#groups").parent("p")[0].id, "ap", "Filtered parent check" );
\r
1284 equals( jQuery("#groups").parent("div").length, 0, "Filtered parent check, no match" );
\r
1285 equals( jQuery("#groups").parent("div, p")[0].id, "ap", "Check for multiple filters" );
\r
1286 isSet( jQuery("#en, #sndp").parent().get(), q("foo"), "Check for unique results from parent" );
\r
1289 test("parents([String])", function() {
\r
1291 equals( jQuery("#groups").parents()[0].id, "ap", "Simple parents check" );
\r
1292 equals( jQuery("#groups").parents("p")[0].id, "ap", "Filtered parents check" );
\r
1293 equals( jQuery("#groups").parents("div")[0].id, "main", "Filtered parents check2" );
\r
1294 isSet( jQuery("#groups").parents("p, div").get(), q("ap", "main"), "Check for multiple filters" );
\r
1295 isSet( jQuery("#en, #sndp").parents().get(), q("foo", "main", "dl", "body", "html"), "Check for unique results from parents" );
\r
1298 test("next([String])", function() {
\r
1300 equals( jQuery("#ap").next()[0].id, "foo", "Simple next check" );
\r
1301 equals( jQuery("#ap").next("div")[0].id, "foo", "Filtered next check" );
\r
1302 equals( jQuery("#ap").next("p").length, 0, "Filtered next check, no match" );
\r
1303 equals( jQuery("#ap").next("div, p")[0].id, "foo", "Multiple filters" );
\r
1306 test("prev([String])", function() {
\r
1308 equals( jQuery("#foo").prev()[0].id, "ap", "Simple prev check" );
\r
1309 equals( jQuery("#foo").prev("p")[0].id, "ap", "Filtered prev check" );
\r
1310 equals( jQuery("#foo").prev("div").length, 0, "Filtered prev check, no match" );
\r
1311 equals( jQuery("#foo").prev("p, div")[0].id, "ap", "Multiple filters" );
\r
1314 test("show()", function() {
\r
1316 var pass = true, div = jQuery("div");
\r
1317 div.show().each(function(){
\r
1318 if ( this.style.display == "none" ) pass = false;
\r
1320 ok( pass, "Show" );
\r
1322 jQuery("#main").append('<div id="show-tests"><div><p><a href="#"></a></p><code></code><pre></pre><span></span></div><table><thead><tr><th></th></tr></thead><tbody><tr><td></td></tr></tbody></table><ul><li></li></ul></div>');
\r
1327 "code" : "inline",
\r
1329 "span" : "inline",
\r
1330 "table" : jQuery.browser.msie ? "block" : "table",
\r
1331 "thead" : jQuery.browser.msie ? "block" : "table-header-group",
\r
1332 "tbody" : jQuery.browser.msie ? "block" : "table-row-group",
\r
1333 "tr" : jQuery.browser.msie ? "block" : "table-row",
\r
1334 "th" : jQuery.browser.msie ? "block" : "table-cell",
\r
1335 "td" : jQuery.browser.msie ? "block" : "table-cell",
\r
1337 "li" : jQuery.browser.msie ? "block" : "list-item"
\r
1340 jQuery.each(test, function(selector, expected) {
\r
1341 var elem = jQuery(selector, "#show-tests").show();
\r
1342 equals( elem.css("display"), expected, "Show using correct display type for " + selector );
\r
1346 test("addClass(String)", function() {
\r
1348 var div = jQuery("div");
\r
1349 div.addClass("test");
\r
1351 for ( var i = 0; i < div.size(); i++ ) {
\r
1352 if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
\r
1354 ok( pass, "Add Class" );
\r
1356 // using contents will get regular, text, and comment nodes
\r
1357 var j = jQuery("#nonnodes").contents();
\r
1358 j.addClass("asdf");
\r
1359 ok( j.hasClass("asdf"), "Check node,textnode,comment for addClass" );
\r
1362 test("removeClass(String) - simple", function() {
\r
1364 var div = jQuery("div").addClass("test").removeClass("test"),
\r
1366 for ( var i = 0; i < div.size(); i++ ) {
\r
1367 if ( div.get(i).className.indexOf("test") != -1 ) pass = false;
\r
1369 ok( pass, "Remove Class" );
\r
1372 var div = jQuery("div").addClass("test").addClass("foo").addClass("bar");
\r
1373 div.removeClass("test").removeClass("bar").removeClass("foo");
\r
1375 for ( var i = 0; i < div.size(); i++ ) {
\r
1376 if ( div.get(i).className.match(/test|bar|foo/) ) pass = false;
\r
1378 ok( pass, "Remove multiple classes" );
\r
1381 var div = jQuery("div:eq(0)").addClass("test").removeClass("");
\r
1382 ok( div.is('.test'), "Empty string passed to removeClass" );
\r
1384 // using contents will get regular, text, and comment nodes
\r
1385 var j = jQuery("#nonnodes").contents();
\r
1386 j.removeClass("asdf");
\r
1387 ok( !j.hasClass("asdf"), "Check node,textnode,comment for removeClass" );
\r
1390 test("toggleClass(String)", function() {
\r
1392 var e = jQuery("#firstp");
\r
1393 ok( !e.is(".test"), "Assert class not present" );
\r
1394 e.toggleClass("test");
\r
1395 ok( e.is(".test"), "Assert class present" );
\r
1396 e.toggleClass("test");
\r
1397 ok( !e.is(".test"), "Assert class not present" );
\r
1400 test("removeAttr(String", function() {
\r
1402 equals( jQuery('#mark').removeAttr("class")[0].className, "", "remove class" );
\r
1405 test("text(String)", function() {
\r
1407 equals( jQuery("#foo").text("<div><b>Hello</b> cruel world!</div>")[0].innerHTML, "<div><b>Hello</b> cruel world!</div>", "Check escaped text" );
\r
1409 // using contents will get comments regular, text, and comment nodes
\r
1410 var j = jQuery("#nonnodes").contents();
\r
1412 equals( jQuery(j[0]).text(), "hi!", "Check node,textnode,comment with text()" );
\r
1413 equals( j[1].nodeValue, " there ", "Check node,textnode,comment with text()" );
\r
1414 equals( j[2].nodeType, 8, "Check node,textnode,comment with text()" );
\r
1417 test("jQuery.each(Object,Function)", function() {
\r
1419 jQuery.each( [0,1,2], function(i, n){
\r
1420 equals( i, n, "Check array iteration" );
\r
1423 jQuery.each( [5,6,7], function(i, n){
\r
1424 equals( i, n - 5, "Check array iteration" );
\r
1427 jQuery.each( { name: "name", lang: "lang" }, function(i, n){
\r
1428 equals( i, n, "Check object iteration" );
\r
1432 jQuery.each([1,2,3], function(i,v){ total += v; });
\r
1433 equals( total, 6, "Looping over an array" );
\r
1435 jQuery.each([1,2,3], function(i,v){ total += v; if ( i == 1 ) return false; });
\r
1436 equals( total, 3, "Looping over an array, with break" );
\r
1438 jQuery.each({"a":1,"b":2,"c":3}, function(i,v){ total += v; });
\r
1439 equals( total, 6, "Looping over an object" );
\r
1441 jQuery.each({"a":3,"b":3,"c":3}, function(i,v){ total += v; return false; });
\r
1442 equals( total, 3, "Looping over an object, with break" );
\r
1445 test("jQuery.prop", function() {
\r
1447 var handle = function() { return this.id };
\r
1448 equals( jQuery.prop(jQuery("#ap")[0], handle), "ap", "Check with Function argument" );
\r
1449 equals( jQuery.prop(jQuery("#ap")[0], "value"), "value", "Check with value argument" );
\r
1452 test("jQuery.className", function() {
\r
1454 var x = jQuery("<p>Hi</p>")[0];
\r
1455 var c = jQuery.className;
\r
1457 equals( x.className, "hi", "Check single added class" );
\r
1458 c.add(x, "foo bar");
\r
1459 equals( x.className, "hi foo bar", "Check more added classes" );
\r
1461 equals( x.className, "", "Remove all classes" );
\r
1462 c.add(x, "hi foo bar");
\r
1463 c.remove(x, "foo");
\r
1464 equals( x.className, "hi bar", "Check removal of one class" );
\r
1465 ok( c.has(x, "hi"), "Check has1" );
\r
1466 ok( c.has(x, "bar"), "Check has2" );
\r
1469 test("jQuery.data", function() {
\r
1471 var div = jQuery("#foo")[0];
\r
1472 equals( jQuery.data(div, "test"), undefined, "Check for no data exists" );
\r
1473 jQuery.data(div, "test", "success");
\r
1474 equals( jQuery.data(div, "test"), "success", "Check for added data" );
\r
1475 jQuery.data(div, "test", "overwritten");
\r
1476 equals( jQuery.data(div, "test"), "overwritten", "Check for overwritten data" );
\r
1477 jQuery.data(div, "test", undefined);
\r
1478 equals( jQuery.data(div, "test"), "overwritten", "Check that data wasn't removed");
\r
1479 jQuery.data(div, "test", null);
\r
1480 ok( jQuery.data(div, "test") === null, "Check for null data");
\r
1483 test(".data()", function() {
\r
1485 var div = jQuery("#foo");
\r
1486 equals( div.data("test"), undefined, "Check for no data exists" );
\r
1487 div.data("test", "success");
\r
1488 equals( div.data("test"), "success", "Check for added data" );
\r
1489 div.data("test", "overwritten");
\r
1490 equals( div.data("test"), "overwritten", "Check for overwritten data" );
\r
1491 div.data("test", undefined);
\r
1492 equals( div.data("test"), "overwritten", "Check that data wasn't removed");
\r
1493 div.data("test", null);
\r
1494 ok( div.data("test") === null, "Check for null data");
\r
1496 div.data("test", "overwritten");
\r
1497 var hits = {test:0}, gets = {test:0};
\r
1500 .bind("setData",function(e,key,value){ hits[key] += value; })
\r
1501 .bind("setData.foo",function(e,key,value){ hits[key] += value; })
\r
1502 .bind("getData",function(e,key){ gets[key] += 1; })
\r
1503 .bind("getData.foo",function(e,key){ gets[key] += 3; });
\r
1505 div.data("test.foo", 2);
\r
1506 equals( div.data("test"), "overwritten", "Check for original data" );
\r
1507 equals( div.data("test.foo"), 2, "Check for namespaced data" );
\r
1508 equals( div.data("test.bar"), "overwritten", "Check for unmatched namespace" );
\r
1509 equals( hits.test, 2, "Check triggered setter functions" );
\r
1510 equals( gets.test, 5, "Check triggered getter functions" );
\r
1515 div.data("test", 1);
\r
1516 equals( div.data("test"), 1, "Check for original data" );
\r
1517 equals( div.data("test.foo"), 2, "Check for namespaced data" );
\r
1518 equals( div.data("test.bar"), 1, "Check for unmatched namespace" );
\r
1519 equals( hits.test, 1, "Check triggered setter functions" );
\r
1520 equals( gets.test, 5, "Check triggered getter functions" );
\r
1526 .bind("getData",function(e,key){ return key + "root"; })
\r
1527 .bind("getData.foo",function(e,key){ return key + "foo"; });
\r
1529 equals( div.data("test"), "testroot", "Check for original data" );
\r
1530 equals( div.data("test.foo"), "testfoo", "Check for namespaced data" );
\r
1531 equals( div.data("test.bar"), "testroot", "Check for unmatched namespace" );
\r
1534 test("jQuery.removeData", function() {
\r
1536 var div = jQuery("#foo")[0];
\r
1537 jQuery.data(div, "test", "testing");
\r
1538 jQuery.removeData(div, "test");
\r
1539 equals( jQuery.data(div, "test"), undefined, "Check removal of data" );
\r
1542 test(".removeData()", function() {
\r
1544 var div = jQuery("#foo");
\r
1545 div.data("test", "testing");
\r
1546 div.removeData("test");
\r
1547 equals( div.data("test"), undefined, "Check removal of data" );
\r
1549 div.data("test", "testing");
\r
1550 div.data("test.foo", "testing2");
\r
1551 div.removeData("test.bar");
\r
1552 equals( div.data("test.foo"), "testing2", "Make sure data is intact" );
\r
1553 equals( div.data("test"), "testing", "Make sure data is intact" );
\r
1555 div.removeData("test");
\r
1556 equals( div.data("test.foo"), "testing2", "Make sure data is intact" );
\r
1557 equals( div.data("test"), undefined, "Make sure data is intact" );
\r
1559 div.removeData("test.foo");
\r
1560 equals( div.data("test.foo"), undefined, "Make sure data is intact" );
\r
1563 test("remove()", function() {
\r
1565 jQuery("#ap").children().remove();
\r
1566 ok( jQuery("#ap").text().length > 10, "Check text is not removed" );
\r
1567 equals( jQuery("#ap").children().length, 0, "Check remove" );
\r
1570 jQuery("#ap").children().remove("a");
\r
1571 ok( jQuery("#ap").text().length > 10, "Check text is not removed" );
\r
1572 equals( jQuery("#ap").children().length, 1, "Check filtered remove" );
\r
1574 // using contents will get comments regular, text, and comment nodes
\r
1575 equals( jQuery("#nonnodes").contents().length, 3, "Check node,textnode,comment remove works" );
\r
1576 jQuery("#nonnodes").contents().remove();
\r
1577 equals( jQuery("#nonnodes").contents().length, 0, "Check node,textnode,comment remove works" );
\r
1580 test("empty()", function() {
\r
1582 equals( jQuery("#ap").children().empty().text().length, 0, "Check text is removed" );
\r
1583 equals( jQuery("#ap").children().length, 4, "Check elements are not removed" );
\r
1585 // using contents will get comments regular, text, and comment nodes
\r
1586 var j = jQuery("#nonnodes").contents();
\r
1588 equals( j.html(), "", "Check node,textnode,comment empty works" );
\r
1591 test("slice()", function() {
\r
1594 var $links = jQuery("#ap a");
\r
1596 isSet( $links.slice(1,2), q("groups"), "slice(1,2)" );
\r
1597 isSet( $links.slice(1), q("groups", "anchor1", "mark"), "slice(1)" );
\r
1598 isSet( $links.slice(0,3), q("google", "groups", "anchor1"), "slice(0,3)" );
\r
1599 isSet( $links.slice(-1), q("mark"), "slice(-1)" );
\r
1601 isSet( $links.eq(1), q("groups"), "eq(1)" );
\r
1603 isSet( $links.eq('2'), q("anchor1"), "eq('2')" );
\r
1606 test("map()", function() {
\r
1607 expect(2);//expect(6);
\r
1610 jQuery("#ap").map(function(){
\r
1611 return jQuery(this).find("a").get();
\r
1613 q("google", "groups", "anchor1", "mark"),
\r
1618 jQuery("#ap > a").map(function(){
\r
1619 return this.parentNode;
\r
1621 q("ap","ap","ap"),
\r
1625 return;//these haven't been accepted yet
\r
1628 var keys = jQuery.map( {a:1,b:2}, function( v, k ){
\r
1632 equals( keys.join(""), "ab", "Map the keys from a hash to an array" );
\r
1634 var values = jQuery.map( {a:1,b:2}, function( v, k ){
\r
1638 equals( values.join(""), "12", "Map the values from a hash to an array" );
\r
1640 var scripts = document.getElementsByTagName("script");
\r
1641 var mapped = jQuery.map( scripts, function( v, k ){
\r
1645 equals( mapped.length, scripts.length, "Map an array(-like) to a hash" );
\r
1647 var flat = jQuery.map( Array(4), function( v, k ){
\r
1648 return k % 2 ? k : [k,k,k];//try mixing array and regular returns
\r
1651 equals( flat.join(""), "00012223", "try the new flatten technique(#2616)" );
\r
1654 test("contents()", function() {
\r
1656 equals( jQuery("#ap").contents().length, 9, "Check element contents" );
\r
1657 ok( jQuery("#iframe").contents()[0], "Check existance of IFrame document" );
\r
1658 var ibody = jQuery("#loadediframe").contents()[0].body;
\r
1659 ok( ibody, "Check existance of IFrame body" );
\r
1661 equals( jQuery("span", ibody).text(), "span text", "Find span in IFrame and check its text" );
\r
1663 jQuery(ibody).append("<div>init text</div>");
\r
1664 equals( jQuery("div", ibody).length, 2, "Check the original div and the new div are in IFrame" );
\r
1666 equals( jQuery("div:last", ibody).text(), "init text", "Add text to div in IFrame" );
\r
1668 jQuery("div:last", ibody).text("div text");
\r
1669 equals( jQuery("div:last", ibody).text(), "div text", "Add text to div in IFrame" );
\r
1671 jQuery("div:last", ibody).remove();
\r
1672 equals( jQuery("div", ibody).length, 1, "Delete the div and check only one div left in IFrame" );
\r
1674 equals( jQuery("div", ibody).text(), "span text", "Make sure the correct div is still left after deletion in IFrame" );
\r
1676 jQuery("<table/>", ibody).append("<tr><td>cell</td></tr>").appendTo(ibody);
\r
1677 jQuery("table", ibody).remove();
\r
1678 equals( jQuery("div", ibody).length, 1, "Check for JS error on add and delete of a table in IFrame" );
\r
1680 // using contents will get comments regular, text, and comment nodes
\r
1681 var c = jQuery("#nonnodes").contents().contents();
\r
1682 equals( c.length, 1, "Check node,textnode,comment contents is just one" );
\r
1683 equals( c[0].nodeValue, "hi", "Check node,textnode,comment contents is just the one from span" );
\r
1686 test("jQuery.makeArray", function(){
\r
1689 equals( jQuery.makeArray(jQuery('html>*'))[0].nodeName, "HEAD", "Pass makeArray a jQuery object" );
\r
1691 equals( jQuery.makeArray(document.getElementsByName("PWD")).slice(0,1)[0].name, "PWD", "Pass makeArray a nodelist" );
\r
1693 equals( (function(){ return jQuery.makeArray(arguments); })(1,2).join(""), "12", "Pass makeArray an arguments array" );
\r
1695 equals( jQuery.makeArray([1,2,3]).join(""), "123", "Pass makeArray a real array" );
\r
1697 equals( jQuery.makeArray().length, 0, "Pass nothing to makeArray and expect an empty array" );
\r
1699 equals( jQuery.makeArray( 0 )[0], 0 , "Pass makeArray a number" );
\r
1701 equals( jQuery.makeArray( "foo" )[0], "foo", "Pass makeArray a string" );
\r
1703 equals( jQuery.makeArray( true )[0].constructor, Boolean, "Pass makeArray a boolean" );
\r
1705 equals( jQuery.makeArray( document.createElement("div") )[0].nodeName, "DIV", "Pass makeArray a single node" );
\r
1707 equals( jQuery.makeArray( {length:2, 0:"a", 1:"b"} ).join(""), "ab", "Pass makeArray an array like map (with length)" );
\r
1709 ok( !!jQuery.makeArray( document.documentElement.childNodes ).slice(0,1)[0].nodeName, "Pass makeArray a childNodes array" );
\r
1711 // function, is tricky as it has length
\r
1712 // NOTE: Due to the conflict with Scriptaculous (http://dev.jquery.com/ticket/3248)
\r
1713 // We remove support for functions since jQuery 1.3
\r
1714 //equals( jQuery.makeArray( function(){ return 1;} )[0](), 1, "Pass makeArray a function" );
\r
1716 //window, also has length
\r
1717 equals( jQuery.makeArray(window)[0], window, "Pass makeArray the window" );
\r
1719 equals( jQuery.makeArray(/a/)[0].constructor, RegExp, "Pass makeArray a regex" );
\r
1721 ok( jQuery.makeArray(document.getElementById('form')).length >= 13, "Pass makeArray a form (treat as elements)" );
\r