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 ok( jQuery.isFunction(obj.getAttribute), "getAttribute Function" );
\r
150 var nodes = document.body.childNodes;
\r
152 // Safari says this is a function
\r
153 ok( !jQuery.isFunction(nodes), "childNodes Property" );
\r
155 var first = document.body.firstChild;
\r
157 // Normal elements are reported ok everywhere
\r
158 ok( !jQuery.isFunction(first), "A normal DOM Element" );
\r
160 var input = document.createElement("input");
\r
161 input.type = "text";
\r
162 document.body.appendChild( input );
\r
164 // IE says this is an object
\r
165 ok( jQuery.isFunction(input.focus), "A default function property" );
\r
167 document.body.removeChild( input );
\r
169 var a = document.createElement("a");
\r
170 a.href = "some-function";
\r
171 document.body.appendChild( a );
\r
173 // This serializes with the word 'function' in it
\r
174 ok( !jQuery.isFunction(a), "Anchor Element" );
\r
176 document.body.removeChild( a );
\r
178 // Recursive function calls have lengths and array-like properties
\r
179 function callme(callback){
\r
180 function fn(response){
\r
181 callback(response);
\r
184 ok( jQuery.isFunction(fn), "Recursive Function Call" );
\r
186 fn({ some: "data" });
\r
190 callme(function(){});
\r
196 test("jQuery('html')", function() {
\r
201 var s = jQuery("<script>var foo='test';</script>")[0];
\r
202 ok( s, "Creating a script" );
\r
203 ok( !foo, "Make sure the script wasn't executed prematurely" );
\r
204 jQuery("body").append(s);
\r
205 ok( foo, "Executing a scripts contents in the right context" );
\r
208 ok( jQuery("<link rel='stylesheet'/>")[0], "Creating a link" );
\r
212 var j = jQuery("<span>hi</span> there <!-- mon ami -->");
\r
213 ok( j.length >= 2, "Check node,textnode,comment creation (some browsers delete comments)" );
\r
215 ok( !jQuery("<option>test</option>")[0].selected, "Make sure that options are auto-selected #2050" );
\r
218 test("jQuery('html', context)", function() {
\r
221 var $div = jQuery("<div/>");
\r
222 var $span = jQuery("<span/>", $div);
\r
223 equals($span.length, 1, "Verify a span created with a div context works, #1763");
\r
227 test("jQuery(selector, xml).text(str) - Loaded via XML document", function() {
\r
230 jQuery.get('data/dashboard.xml', function(xml) {
\r
231 // tests for #1419 where IE was a problem
\r
232 equals( jQuery("tab:first", xml).text(), "blabla", "Verify initial text correct" );
\r
233 jQuery("tab:first", xml).text("newtext");
\r
234 equals( jQuery("tab:first", xml).text(), "newtext", "Verify new text correct" );
\r
240 test("length", function() {
\r
242 equals( jQuery("p").length, 6, "Get Number of Elements Found" );
\r
245 test("size()", function() {
\r
247 equals( jQuery("p").size(), 6, "Get Number of Elements Found" );
\r
250 test("get()", function() {
\r
252 isSet( jQuery("p").get(), q("firstp","ap","sndp","en","sap","first"), "Get All Elements" );
\r
255 test("get(Number)", function() {
\r
257 equals( jQuery("p").get(0), document.getElementById("firstp"), "Get A Single Element" );
\r
260 test("add(String|Element|Array|undefined)", function() {
\r
262 isSet( jQuery("#sndp").add("#en").add("#sap").get(), q("sndp", "en", "sap"), "Check elements from document" );
\r
263 isSet( jQuery("#sndp").add( jQuery("#en")[0] ).add( jQuery("#sap") ).get(), q("sndp", "en", "sap"), "Check elements from document" );
\r
264 ok( jQuery([]).add(jQuery("#form")[0].elements).length >= 13, "Check elements from array" );
\r
266 // For the time being, we're discontinuing support for jQuery(form.elements) since it's ambiguous in IE
\r
267 // use jQuery([]).add(form.elements) instead.
\r
268 //equals( jQuery([]).add(jQuery("#form")[0].elements).length, jQuery(jQuery("#form")[0].elements).length, "Array in constructor must equals array in add()" );
\r
270 var x = jQuery([]).add(jQuery("<p id='x1'>xxx</p>")).add(jQuery("<p id='x2'>xxx</p>"));
\r
271 equals( x[0].id, "x1", "Check on-the-fly element1" );
\r
272 equals( x[1].id, "x2", "Check on-the-fly element2" );
\r
274 var x = jQuery([]).add("<p id='x1'>xxx</p>").add("<p id='x2'>xxx</p>");
\r
275 equals( x[0].id, "x1", "Check on-the-fly element1" );
\r
276 equals( x[1].id, "x2", "Check on-the-fly element2" );
\r
279 equals( jQuery([]).add(notDefined).length, 0, "Check that undefined adds nothing" );
\r
281 // Added after #2811
\r
282 equals( jQuery([]).add([window,document,document.body,document]).length, 3, "Pass an array" );
\r
283 equals( jQuery(document).add(document).length, 1, "Check duplicated elements" );
\r
284 equals( jQuery(window).add(window).length, 1, "Check duplicated elements using the window" );
\r
285 ok( jQuery([]).add( document.getElementById('form') ).length >= 13, "Add a form (adds the elements)" );
\r
288 test("each(Function)", function() {
\r
290 var div = jQuery("div");
\r
291 div.each(function(){this.foo = 'zoo';});
\r
293 for ( var i = 0; i < div.size(); i++ ) {
\r
294 if ( div.get(i).foo != "zoo" ) pass = false;
\r
296 ok( pass, "Execute a function, Relative" );
\r
299 test("index(Object)", function() {
\r
302 var elements = jQuery([window, document]),
\r
303 inputElements = jQuery('#radio1,#radio2,#check1,#check2');
\r
305 equals( elements.index(window), 0, "Check for index of elements" );
\r
306 equals( elements.index(document), 1, "Check for index of elements" );
\r
307 equals( inputElements.index(document.getElementById('radio1')), 0, "Check for index of elements" );
\r
308 equals( inputElements.index(document.getElementById('radio2')), 1, "Check for index of elements" );
\r
309 equals( inputElements.index(document.getElementById('check1')), 2, "Check for index of elements" );
\r
310 equals( inputElements.index(document.getElementById('check2')), 3, "Check for index of elements" );
\r
311 equals( inputElements.index(window), -1, "Check for not found index" );
\r
312 equals( inputElements.index(document), -1, "Check for not found index" );
\r
314 // enabled since [5500]
\r
315 equals( elements.index( elements ), 0, "Pass in a jQuery object" );
\r
316 equals( elements.index( elements.eq(1) ), 1, "Pass in a jQuery object" );
\r
319 test("attr(String)", function() {
\r
321 equals( jQuery('#text1').attr('value'), "Test", 'Check for value attribute' );
\r
322 equals( jQuery('#text1').attr('value', "Test2").attr('defaultValue'), "Test", 'Check for defaultValue attribute' );
\r
323 equals( jQuery('#text1').attr('type'), "text", 'Check for type attribute' );
\r
324 equals( jQuery('#radio1').attr('type'), "radio", 'Check for type attribute' );
\r
325 equals( jQuery('#check1').attr('type'), "checkbox", 'Check for type attribute' );
\r
326 equals( jQuery('#simon1').attr('rel'), "bookmark", 'Check for rel attribute' );
\r
327 equals( jQuery('#google').attr('title'), "Google!", 'Check for title attribute' );
\r
328 equals( jQuery('#mark').attr('hreflang'), "en", 'Check for hreflang attribute' );
\r
329 equals( jQuery('#en').attr('lang'), "en", 'Check for lang attribute' );
\r
330 equals( jQuery('#simon').attr('class'), "blog link", 'Check for class attribute' );
\r
331 equals( jQuery('#name').attr('name'), "name", 'Check for name attribute' );
\r
332 equals( jQuery('#text1').attr('name'), "action", 'Check for name attribute' );
\r
333 ok( jQuery('#form').attr('action').indexOf("formaction") >= 0, 'Check for action attribute' );
\r
334 equals( jQuery('#text1').attr('maxlength'), '30', 'Check for maxlength attribute' );
\r
335 equals( jQuery('#text1').attr('maxLength'), '30', 'Check for maxLength attribute' );
\r
336 equals( jQuery('#area1').attr('maxLength'), '30', 'Check for maxLength attribute' );
\r
337 equals( jQuery('#select2').attr('selectedIndex'), 3, 'Check for selectedIndex attribute' );
\r
338 equals( jQuery('#foo').attr('nodeName'), 'DIV', 'Check for nodeName attribute' );
\r
339 equals( jQuery('#foo').attr('tagName'), 'DIV', 'Check for tagName attribute' );
\r
341 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
342 equals( jQuery('#tAnchor5').attr('href'), "#5", 'Check for non-absolute href (an anchor)' );
\r
345 // Related to [5574] and [5683]
\r
346 var body = document.body, $body = jQuery(body);
\r
348 ok( $body.attr('foo') === undefined, 'Make sure that a non existent attribute returns undefined' );
\r
349 ok( $body.attr('nextSibling') === null, 'Make sure a null expando returns null' );
\r
351 body.setAttribute('foo', 'baz');
\r
352 equals( $body.attr('foo'), 'baz', 'Make sure the dom attribute is retrieved when no expando is found' );
\r
355 equals( $body.attr('foo'), 'bar', 'Make sure the expando is preferred over the dom attribute' );
\r
357 $body.attr('foo','cool');
\r
358 equals( $body.attr('foo'), 'cool', 'Make sure that setting works well when both expando and dom attribute are available' );
\r
360 body.foo = undefined;
\r
361 ok( $body.attr('foo') === undefined, 'Make sure the expando is preferred over the dom attribute, even if undefined' );
\r
363 body.removeAttribute('foo'); // Cleanup
\r
367 test("attr(String) in XML Files", function() {
\r
370 jQuery.get("data/dashboard.xml", function(xml) {
\r
371 equals( jQuery("locations", xml).attr("class"), "foo", "Check class attribute in XML document" );
\r
372 equals( jQuery("location", xml).attr("for"), "bar", "Check for attribute in XML document" );
\r
378 test("attr(String, Function)", function() {
\r
380 equals( jQuery('#text1').attr('value', function() { return this.id })[0].value, "text1", "Set value from id" );
\r
381 equals( jQuery('#text1').attr('title', function(i) { return i }).attr('title'), "0", "Set value with an index");
\r
384 test("attr(Hash)", function() {
\r
387 jQuery("div").attr({foo: 'baz', zoo: 'ping'}).each(function(){
\r
388 if ( this.getAttribute('foo') != "baz" && this.getAttribute('zoo') != "ping" ) pass = false;
\r
390 ok( pass, "Set Multiple Attributes" );
\r
393 test("attr(String, Object)", function() {
\r
395 var div = jQuery("div").attr("foo", "bar");
\r
397 for ( var i = 0; i < div.size(); i++ ) {
\r
398 if ( div.get(i).getAttribute('foo') != "bar" ){
\r
403 equals( fail, false, "Set Attribute, the #"+fail+" element didn't get the attribute 'foo'" );
\r
405 ok( jQuery("#foo").attr({"width": null}), "Try to set an attribute to nothing" );
\r
407 jQuery("#name").attr('name', 'something');
\r
408 equals( jQuery("#name").attr('name'), 'something', 'Set name attribute' );
\r
409 jQuery("#check2").attr('checked', true);
\r
410 equals( document.getElementById('check2').checked, true, 'Set checked attribute' );
\r
411 jQuery("#check2").attr('checked', false);
\r
412 equals( document.getElementById('check2').checked, false, 'Set checked attribute' );
\r
413 jQuery("#text1").attr('readonly', true);
\r
414 equals( document.getElementById('text1').readOnly, true, 'Set readonly attribute' );
\r
415 jQuery("#text1").attr('readonly', false);
\r
416 equals( document.getElementById('text1').readOnly, false, 'Set readonly attribute' );
\r
417 jQuery("#name").attr('maxlength', '5');
\r
418 equals( document.getElementById('name').maxLength, '5', 'Set maxlength attribute' );
\r
419 jQuery("#name").attr('maxLength', '10');
\r
420 equals( document.getElementById('name').maxLength, '10', 'Set maxlength attribute' );
\r
423 jQuery("#name").attr('someAttr', '0');
\r
424 equals( jQuery("#name").attr('someAttr'), '0', 'Set attribute to a string of "0"' );
\r
425 jQuery("#name").attr('someAttr', 0);
\r
426 equals( jQuery("#name").attr('someAttr'), 0, 'Set attribute to the number 0' );
\r
427 jQuery("#name").attr('someAttr', 1);
\r
428 equals( jQuery("#name").attr('someAttr'), 1, 'Set attribute to the number 1' );
\r
430 // using contents will get comments regular, text, and comment nodes
\r
431 var j = jQuery("#nonnodes").contents();
\r
433 j.attr("name", "attrvalue");
\r
434 equals( j.attr("name"), "attrvalue", "Check node,textnode,comment for attr" );
\r
435 j.removeAttr("name");
\r
439 var type = jQuery("#check2").attr('type');
\r
440 var thrown = false;
\r
442 jQuery("#check2").attr('type','hidden');
\r
446 ok( thrown, "Exception thrown when trying to change type property" );
\r
447 equals( type, jQuery("#check2").attr('type'), "Verify that you can't change the type of an input element" );
\r
449 var check = document.createElement("input");
\r
452 jQuery(check).attr('type','checkbox');
\r
456 ok( thrown, "Exception thrown when trying to change type property" );
\r
457 equals( "checkbox", jQuery(check).attr('type'), "Verify that you can change the type of an input element that isn't in the DOM" );
\r
461 test("attr(String, Object) - Loaded via XML document", function() {
\r
464 jQuery.get('data/dashboard.xml', function(xml) {
\r
466 jQuery('tab', xml).each(function() {
\r
467 titles.push(jQuery(this).attr('title'));
\r
469 equals( titles[0], 'Location', 'attr() in XML context: Check first title' );
\r
470 equals( titles[1], 'Users', 'attr() in XML context: Check second title' );
\r
476 test("css(String|Hash)", function() {
\r
479 equals( jQuery('#main').css("display"), 'none', 'Check for css property "display"');
\r
481 ok( jQuery('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
\r
482 jQuery('#foo').css({display: 'none'});
\r
483 ok( !jQuery('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
\r
484 jQuery('#foo').css({display: 'block'});
\r
485 ok( jQuery('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
\r
487 jQuery('#floatTest').css({styleFloat: 'right'});
\r
488 equals( jQuery('#floatTest').css('styleFloat'), 'right', 'Modified CSS float using "styleFloat": Assert float is right');
\r
489 jQuery('#floatTest').css({cssFloat: 'left'});
\r
490 equals( jQuery('#floatTest').css('cssFloat'), 'left', 'Modified CSS float using "cssFloat": Assert float is left');
\r
491 jQuery('#floatTest').css({'float': 'right'});
\r
492 equals( jQuery('#floatTest').css('float'), 'right', 'Modified CSS float using "float": Assert float is right');
\r
493 jQuery('#floatTest').css({'font-size': '30px'});
\r
494 equals( jQuery('#floatTest').css('font-size'), '30px', 'Modified CSS font-size: Assert font-size is 30px');
\r
496 jQuery.each("0,0.25,0.5,0.75,1".split(','), function(i, n) {
\r
497 jQuery('#foo').css({opacity: n});
\r
498 equals( jQuery('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" );
\r
499 jQuery('#foo').css({opacity: parseFloat(n)});
\r
500 equals( jQuery('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" );
\r
502 jQuery('#foo').css({opacity: ''});
\r
503 equals( jQuery('#foo').css('opacity'), '1', "Assert opacity is 1 when set to an empty String" );
\r
506 test("css(String, Object)", function() {
\r
508 ok( jQuery('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
\r
509 jQuery('#foo').css('display', 'none');
\r
510 ok( !jQuery('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
\r
511 jQuery('#foo').css('display', 'block');
\r
512 ok( jQuery('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
\r
514 jQuery('#floatTest').css('styleFloat', 'left');
\r
515 equals( jQuery('#floatTest').css('styleFloat'), 'left', 'Modified CSS float using "styleFloat": Assert float is left');
\r
516 jQuery('#floatTest').css('cssFloat', 'right');
\r
517 equals( jQuery('#floatTest').css('cssFloat'), 'right', 'Modified CSS float using "cssFloat": Assert float is right');
\r
518 jQuery('#floatTest').css('float', 'left');
\r
519 equals( jQuery('#floatTest').css('float'), 'left', 'Modified CSS float using "float": Assert float is left');
\r
520 jQuery('#floatTest').css('font-size', '20px');
\r
521 equals( jQuery('#floatTest').css('font-size'), '20px', 'Modified CSS font-size: Assert font-size is 20px');
\r
523 jQuery.each("0,0.25,0.5,0.75,1".split(','), function(i, n) {
\r
524 jQuery('#foo').css('opacity', n);
\r
525 equals( jQuery('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" );
\r
526 jQuery('#foo').css('opacity', parseFloat(n));
\r
527 equals( jQuery('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" );
\r
529 jQuery('#foo').css('opacity', '');
\r
530 equals( jQuery('#foo').css('opacity'), '1', "Assert opacity is 1 when set to an empty String" );
\r
531 // for #1438, IE throws JS error when filter exists but doesn't have opacity in it
\r
532 if (jQuery.browser.msie) {
\r
533 jQuery('#foo').css("filter", "progid:DXImageTransform.Microsoft.Chroma(color='red');");
\r
535 equals( jQuery('#foo').css('opacity'), '1', "Assert opacity is 1 when a different filter is set in IE, #1438" );
\r
537 // using contents will get comments regular, text, and comment nodes
\r
538 var j = jQuery("#nonnodes").contents();
\r
539 j.css("padding-left", "1px");
\r
540 equals( j.css("padding-left"), "1px", "Check node,textnode,comment css works" );
\r
542 // opera sometimes doesn't update 'display' correctly, see #2037
\r
543 jQuery("#t2037")[0].innerHTML = jQuery("#t2037")[0].innerHTML
\r
544 equals( jQuery("#t2037 .hidden").css("display"), "none", "Make sure browser thinks it is hidden" );
\r
547 test("jQuery.css(elem, 'height') doesn't clear radio buttons (bug #1095)", function () {
\r
550 var $checkedtest = jQuery("#checkedtest");
\r
551 // IE6 was clearing "checked" in jQuery.css(elem, "height");
\r
552 jQuery.css($checkedtest[0], "height");
\r
553 ok( !! jQuery(":radio:first", $checkedtest).attr("checked"), "Check first radio still checked." );
\r
554 ok( ! jQuery(":radio:last", $checkedtest).attr("checked"), "Check last radio still NOT checked." );
\r
555 ok( !! jQuery(":checkbox:first", $checkedtest).attr("checked"), "Check first checkbox still checked." );
\r
556 ok( ! jQuery(":checkbox:last", $checkedtest).attr("checked"), "Check last checkbox still NOT checked." );
\r
559 test("width()", function() {
\r
562 var $div = jQuery("#nothiddendiv");
\r
564 equals($div.width(), 30, "Test set to 30 correctly");
\r
565 $div.width(-1); // handle negative numbers by ignoring #1599
\r
566 equals($div.width(), 30, "Test negative width ignored");
\r
567 $div.css("padding", "20px");
\r
568 equals($div.width(), 30, "Test padding specified with pixels");
\r
569 $div.css("border", "2px solid #fff");
\r
570 equals($div.width(), 30, "Test border specified with pixels");
\r
571 $div.css("padding", "2em");
\r
572 equals($div.width(), 30, "Test padding specified with ems");
\r
573 $div.css("border", "1em solid #fff");
\r
574 equals($div.width(), 30, "Test border specified with ems");
\r
575 $div.css("padding", "2%");
\r
576 equals($div.width(), 30, "Test padding specified with percent");
\r
578 equals($div.width(), 30, "Test hidden div");
\r
580 $div.css({ display: "", border: "", padding: "" });
\r
582 jQuery("#nothiddendivchild").css({ padding: "3px", border: "2px solid #fff" });
\r
583 equals(jQuery("#nothiddendivchild").width(), 20, "Test child width with border and padding");
\r
584 jQuery("#nothiddendiv, #nothiddendivchild").css({ border: "", padding: "", width: "" });
\r
587 test("height()", function() {
\r
590 var $div = jQuery("#nothiddendiv");
\r
592 equals($div.height(), 30, "Test set to 30 correctly");
\r
593 $div.height(-1); // handle negative numbers by ignoring #1599
\r
594 equals($div.height(), 30, "Test negative height ignored");
\r
595 $div.css("padding", "20px");
\r
596 equals($div.height(), 30, "Test padding specified with pixels");
\r
597 $div.css("border", "2px solid #fff");
\r
598 equals($div.height(), 30, "Test border specified with pixels");
\r
599 $div.css("padding", "2em");
\r
600 equals($div.height(), 30, "Test padding specified with ems");
\r
601 $div.css("border", "1em solid #fff");
\r
602 equals($div.height(), 30, "Test border specified with ems");
\r
603 $div.css("padding", "2%");
\r
604 equals($div.height(), 30, "Test padding specified with percent");
\r
606 equals($div.height(), 30, "Test hidden div");
\r
608 $div.css({ display: "", border: "", padding: "", height: "1px" });
\r
611 test("text()", function() {
\r
613 var expected = "This link has class=\"blog\": Simon Willison's Weblog";
\r
614 equals( jQuery('#sap').text(), expected, 'Check for merged text of more then one element.' );
\r
617 test("wrap(String|Element)", function() {
\r
619 var defaultText = 'Try them out:'
\r
620 var result = jQuery('#first').wrap('<div class="red"><span></span></div>').text();
\r
621 equals( defaultText, result, 'Check for wrapping of on-the-fly html' );
\r
622 ok( jQuery('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
\r
625 var defaultText = 'Try them out:'
\r
626 var result = jQuery('#first').wrap(document.getElementById('empty')).parent();
\r
627 ok( result.is('ol'), 'Check for element wrapping' );
\r
628 equals( result.text(), defaultText, 'Check for element wrapping' );
\r
631 jQuery('#check1').click(function() {
\r
632 var checkbox = this;
\r
633 ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
\r
634 jQuery(checkbox).wrap( '<div id="c1" style="display:none;"></div>' );
\r
635 ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
\r
638 // using contents will get comments regular, text, and comment nodes
\r
639 var j = jQuery("#nonnodes").contents();
\r
641 equals( jQuery("#nonnodes > i").length, 3, "Check node,textnode,comment wraps ok" );
\r
642 equals( jQuery("#nonnodes > i").text(), j.text() + j[1].nodeValue, "Check node,textnode,comment wraps doesn't hurt text" );
\r
645 test("wrapAll(String|Element)", function() {
\r
647 var prev = jQuery("#first")[0].previousSibling;
\r
648 var p = jQuery("#first")[0].parentNode;
\r
649 var result = jQuery('#first,#firstp').wrapAll('<div class="red"><div id="tmp"></div></div>');
\r
650 equals( result.parent().length, 1, 'Check for wrapping of on-the-fly html' );
\r
651 ok( jQuery('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
\r
652 ok( jQuery('#firstp').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
\r
653 equals( jQuery("#first").parent().parent()[0].previousSibling, prev, "Correct Previous Sibling" );
\r
654 equals( jQuery("#first").parent().parent()[0].parentNode, p, "Correct Parent" );
\r
657 var prev = jQuery("#first")[0].previousSibling;
\r
658 var p = jQuery("#first")[0].parentNode;
\r
659 var result = jQuery('#first,#firstp').wrapAll(document.getElementById('empty'));
\r
660 equals( jQuery("#first").parent()[0], jQuery("#firstp").parent()[0], "Same Parent" );
\r
661 equals( jQuery("#first").parent()[0].previousSibling, prev, "Correct Previous Sibling" );
\r
662 equals( jQuery("#first").parent()[0].parentNode, p, "Correct Parent" );
\r
665 test("wrapInner(String|Element)", function() {
\r
667 var num = jQuery("#first").children().length;
\r
668 var result = jQuery('#first').wrapInner('<div class="red"><div id="tmp"></div></div>');
\r
669 equals( jQuery("#first").children().length, 1, "Only one child" );
\r
670 ok( jQuery("#first").children().is(".red"), "Verify Right Element" );
\r
671 equals( jQuery("#first").children().children().children().length, num, "Verify Elements Intact" );
\r
674 var num = jQuery("#first").children().length;
\r
675 var result = jQuery('#first').wrapInner(document.getElementById('empty'));
\r
676 equals( jQuery("#first").children().length, 1, "Only one child" );
\r
677 ok( jQuery("#first").children().is("#empty"), "Verify Right Element" );
\r
678 equals( jQuery("#first").children().children().length, num, "Verify Elements Intact" );
\r
681 test("append(String|Element|Array<Element>|jQuery)", function() {
\r
683 var defaultText = 'Try them out:'
\r
684 var result = jQuery('#first').append('<b>buga</b>');
\r
685 equals( result.text(), defaultText + 'buga', 'Check if text appending works' );
\r
686 equals( jQuery('#select3').append('<option value="appendTest">Append Test</option>').find('option:last-child').attr('value'), 'appendTest', 'Appending html options to select element');
\r
689 var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
\r
690 jQuery('#sap').append(document.getElementById('first'));
\r
691 equals( expected, jQuery('#sap').text(), "Check for appending of element" );
\r
694 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
\r
695 jQuery('#sap').append([document.getElementById('first'), document.getElementById('yahoo')]);
\r
696 equals( expected, jQuery('#sap').text(), "Check for appending of array of elements" );
\r
699 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
\r
700 jQuery('#sap').append(jQuery("#first, #yahoo"));
\r
701 equals( expected, jQuery('#sap').text(), "Check for appending of jQuery object" );
\r
704 jQuery("#sap").append( 5 );
\r
705 ok( jQuery("#sap")[0].innerHTML.match( /5$/ ), "Check for appending a number" );
\r
708 jQuery("#sap").append( " text with spaces " );
\r
709 ok( jQuery("#sap")[0].innerHTML.match(/ text with spaces $/), "Check for appending text with spaces" );
\r
712 ok( jQuery("#sap").append([]), "Check for appending an empty array." );
\r
713 ok( jQuery("#sap").append(""), "Check for appending an empty string." );
\r
714 ok( jQuery("#sap").append(document.getElementsByTagName("foo")), "Check for appending an empty nodelist." );
\r
717 jQuery("#sap").append(document.getElementById('form'));
\r
718 equals( jQuery("#sap>form").size(), 1, "Check for appending a form" ); // Bug #910
\r
723 jQuery( jQuery("#iframe")[0].contentWindow.document.body ).append("<div>test</div>");
\r
728 ok( pass, "Test for appending a DOM node to the contents of an IFrame" );
\r
731 jQuery('<fieldset/>').appendTo('#form').append('<legend id="legend">test</legend>');
\r
732 t( 'Append legend', '#legend', ['legend'] );
\r
735 jQuery('#select1').append('<OPTION>Test</OPTION>');
\r
736 equals( jQuery('#select1 option:last').text(), "Test", "Appending <OPTION> (all caps)" );
\r
738 jQuery('#table').append('<colgroup></colgroup>');
\r
739 ok( jQuery('#table colgroup').length, "Append colgroup" );
\r
741 jQuery('#table colgroup').append('<col/>');
\r
742 ok( jQuery('#table colgroup col').length, "Append col" );
\r
745 jQuery('#table').append('<caption></caption>');
\r
746 ok( jQuery('#table caption').length, "Append caption" );
\r
749 jQuery('form:last')
\r
750 .append('<select id="appendSelect1"></select>')
\r
751 .append('<select id="appendSelect2"><option>Test</option></select>');
\r
753 t( "Append Select", "#appendSelect1, #appendSelect2", ["appendSelect1", "appendSelect2"] );
\r
755 // using contents will get comments regular, text, and comment nodes
\r
756 var j = jQuery("#nonnodes").contents();
\r
757 var d = jQuery("<div/>").appendTo("#nonnodes").append(j);
\r
758 equals( jQuery("#nonnodes").length, 1, "Check node,textnode,comment append moved leaving just the div" );
\r
759 ok( d.contents().length >= 2, "Check node,textnode,comment append works" );
\r
760 d.contents().appendTo("#nonnodes");
\r
762 ok( jQuery("#nonnodes").contents().length >= 2, "Check node,textnode,comment append cleanup worked" );
\r
765 test("appendTo(String|Element|Array<Element>|jQuery)", function() {
\r
767 var defaultText = 'Try them out:'
\r
768 jQuery('<b>buga</b>').appendTo('#first');
\r
769 equals( jQuery("#first").text(), defaultText + 'buga', 'Check if text appending works' );
\r
770 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
773 var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
\r
774 jQuery(document.getElementById('first')).appendTo('#sap');
\r
775 equals( expected, jQuery('#sap').text(), "Check for appending of element" );
\r
778 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
\r
779 jQuery([document.getElementById('first'), document.getElementById('yahoo')]).appendTo('#sap');
\r
780 equals( expected, jQuery('#sap').text(), "Check for appending of array of elements" );
\r
783 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
\r
784 jQuery("#first, #yahoo").appendTo('#sap');
\r
785 equals( expected, jQuery('#sap').text(), "Check for appending of jQuery object" );
\r
788 jQuery('#select1').appendTo('#foo');
\r
789 t( 'Append select', '#foo select', ['select1'] );
\r
792 test("prepend(String|Element|Array<Element>|jQuery)", function() {
\r
794 var defaultText = 'Try them out:'
\r
795 var result = jQuery('#first').prepend('<b>buga</b>');
\r
796 equals( result.text(), 'buga' + defaultText, 'Check if text prepending works' );
\r
797 equals( jQuery('#select3').prepend('<option value="prependTest">Prepend Test</option>').find('option:first-child').attr('value'), 'prependTest', 'Prepending html options to select element');
\r
800 var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
\r
801 jQuery('#sap').prepend(document.getElementById('first'));
\r
802 equals( expected, jQuery('#sap').text(), "Check for prepending of element" );
\r
805 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
\r
806 jQuery('#sap').prepend([document.getElementById('first'), document.getElementById('yahoo')]);
\r
807 equals( expected, jQuery('#sap').text(), "Check for prepending of array of elements" );
\r
810 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
\r
811 jQuery('#sap').prepend(jQuery("#first, #yahoo"));
\r
812 equals( expected, jQuery('#sap').text(), "Check for prepending of jQuery object" );
\r
815 test("prependTo(String|Element|Array<Element>|jQuery)", function() {
\r
817 var defaultText = 'Try them out:'
\r
818 jQuery('<b>buga</b>').prependTo('#first');
\r
819 equals( jQuery('#first').text(), 'buga' + defaultText, 'Check if text prepending works' );
\r
820 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
823 var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
\r
824 jQuery(document.getElementById('first')).prependTo('#sap');
\r
825 equals( expected, jQuery('#sap').text(), "Check for prepending of element" );
\r
828 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
\r
829 jQuery([document.getElementById('yahoo'), document.getElementById('first')]).prependTo('#sap');
\r
830 equals( expected, jQuery('#sap').text(), "Check for prepending of array of elements" );
\r
833 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
\r
834 jQuery("#yahoo, #first").prependTo('#sap');
\r
835 equals( expected, jQuery('#sap').text(), "Check for prepending of jQuery object" );
\r
838 jQuery('<select id="prependSelect1"></select>').prependTo('form:last');
\r
839 jQuery('<select id="prependSelect2"><option>Test</option></select>').prependTo('form:last');
\r
841 t( "Prepend Select", "#prependSelect1, #prependSelect2", ["prependSelect1", "prependSelect2"] );
\r
844 test("before(String|Element|Array<Element>|jQuery)", function() {
\r
846 var expected = 'This is a normal link: bugaYahoo';
\r
847 jQuery('#yahoo').before('<b>buga</b>');
\r
848 equals( expected, jQuery('#en').text(), 'Insert String before' );
\r
851 expected = "This is a normal link: Try them out:Yahoo";
\r
852 jQuery('#yahoo').before(document.getElementById('first'));
\r
853 equals( expected, jQuery('#en').text(), "Insert element before" );
\r
856 expected = "This is a normal link: Try them out:diveintomarkYahoo";
\r
857 jQuery('#yahoo').before([document.getElementById('first'), document.getElementById('mark')]);
\r
858 equals( expected, jQuery('#en').text(), "Insert array of elements before" );
\r
861 expected = "This is a normal link: Try them out:diveintomarkYahoo";
\r
862 jQuery('#yahoo').before(jQuery("#first, #mark"));
\r
863 equals( expected, jQuery('#en').text(), "Insert jQuery before" );
\r
866 test("insertBefore(String|Element|Array<Element>|jQuery)", function() {
\r
868 var expected = 'This is a normal link: bugaYahoo';
\r
869 jQuery('<b>buga</b>').insertBefore('#yahoo');
\r
870 equals( expected, jQuery('#en').text(), 'Insert String before' );
\r
873 expected = "This is a normal link: Try them out:Yahoo";
\r
874 jQuery(document.getElementById('first')).insertBefore('#yahoo');
\r
875 equals( expected, jQuery('#en').text(), "Insert element before" );
\r
878 expected = "This is a normal link: Try them out:diveintomarkYahoo";
\r
879 jQuery([document.getElementById('first'), document.getElementById('mark')]).insertBefore('#yahoo');
\r
880 equals( expected, jQuery('#en').text(), "Insert array of elements before" );
\r
883 expected = "This is a normal link: Try them out:diveintomarkYahoo";
\r
884 jQuery("#first, #mark").insertBefore('#yahoo');
\r
885 equals( expected, jQuery('#en').text(), "Insert jQuery before" );
\r
888 test("after(String|Element|Array<Element>|jQuery)", function() {
\r
890 var expected = 'This is a normal link: Yahoobuga';
\r
891 jQuery('#yahoo').after('<b>buga</b>');
\r
892 equals( expected, jQuery('#en').text(), 'Insert String after' );
\r
895 expected = "This is a normal link: YahooTry them out:";
\r
896 jQuery('#yahoo').after(document.getElementById('first'));
\r
897 equals( expected, jQuery('#en').text(), "Insert element after" );
\r
900 expected = "This is a normal link: YahooTry them out:diveintomark";
\r
901 jQuery('#yahoo').after([document.getElementById('first'), document.getElementById('mark')]);
\r
902 equals( expected, jQuery('#en').text(), "Insert array of elements after" );
\r
905 expected = "This is a normal link: YahooTry them out:diveintomark";
\r
906 jQuery('#yahoo').after(jQuery("#first, #mark"));
\r
907 equals( expected, jQuery('#en').text(), "Insert jQuery after" );
\r
910 test("insertAfter(String|Element|Array<Element>|jQuery)", function() {
\r
912 var expected = 'This is a normal link: Yahoobuga';
\r
913 jQuery('<b>buga</b>').insertAfter('#yahoo');
\r
914 equals( expected, jQuery('#en').text(), 'Insert String after' );
\r
917 expected = "This is a normal link: YahooTry them out:";
\r
918 jQuery(document.getElementById('first')).insertAfter('#yahoo');
\r
919 equals( expected, jQuery('#en').text(), "Insert element after" );
\r
922 expected = "This is a normal link: YahooTry them out:diveintomark";
\r
923 jQuery([document.getElementById('mark'), document.getElementById('first')]).insertAfter('#yahoo');
\r
924 equals( expected, jQuery('#en').text(), "Insert array of elements after" );
\r
927 expected = "This is a normal link: YahooTry them out:diveintomark";
\r
928 jQuery("#mark, #first").insertAfter('#yahoo');
\r
929 equals( expected, jQuery('#en').text(), "Insert jQuery after" );
\r
932 test("replaceWith(String|Element|Array<Element>|jQuery)", function() {
\r
934 jQuery('#yahoo').replaceWith('<b id="replace">buga</b>');
\r
935 ok( jQuery("#replace")[0], 'Replace element with string' );
\r
936 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after string' );
\r
939 jQuery('#yahoo').replaceWith(document.getElementById('first'));
\r
940 ok( jQuery("#first")[0], 'Replace element with element' );
\r
941 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after element' );
\r
944 jQuery('#yahoo').replaceWith([document.getElementById('first'), document.getElementById('mark')]);
\r
945 ok( jQuery("#first")[0], 'Replace element with array of elements' );
\r
946 ok( jQuery("#mark")[0], 'Replace element with array of elements' );
\r
947 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after array of elements' );
\r
950 jQuery('#yahoo').replaceWith(jQuery("#first, #mark"));
\r
951 ok( jQuery("#first")[0], 'Replace element with set of elements' );
\r
952 ok( jQuery("#mark")[0], 'Replace element with set of elements' );
\r
953 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after set of elements' );
\r
956 test("replaceAll(String|Element|Array<Element>|jQuery)", function() {
\r
958 jQuery('<b id="replace">buga</b>').replaceAll("#yahoo");
\r
959 ok( jQuery("#replace")[0], 'Replace element with string' );
\r
960 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after string' );
\r
963 jQuery(document.getElementById('first')).replaceAll("#yahoo");
\r
964 ok( jQuery("#first")[0], 'Replace element with element' );
\r
965 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after element' );
\r
968 jQuery([document.getElementById('first'), document.getElementById('mark')]).replaceAll("#yahoo");
\r
969 ok( jQuery("#first")[0], 'Replace element with array of elements' );
\r
970 ok( jQuery("#mark")[0], 'Replace element with array of elements' );
\r
971 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after array of elements' );
\r
974 jQuery("#first, #mark").replaceAll("#yahoo");
\r
975 ok( jQuery("#first")[0], 'Replace element with set of elements' );
\r
976 ok( jQuery("#mark")[0], 'Replace element with set of elements' );
\r
977 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after set of elements' );
\r
980 test("end()", function() {
\r
982 equals( 'Yahoo', jQuery('#yahoo').parent().end().text(), 'Check for end' );
\r
983 ok( jQuery('#yahoo').end(), 'Check for end with nothing to end' );
\r
985 var x = jQuery('#yahoo');
\r
987 equals( 'Yahoo', jQuery('#yahoo').text(), 'Check for non-destructive behaviour' );
\r
990 test("find(String)", function() {
\r
992 equals( 'Yahoo', jQuery('#foo').find('.blogTest').text(), 'Check for find' );
\r
994 // using contents will get comments regular, text, and comment nodes
\r
995 var j = jQuery("#nonnodes").contents();
\r
996 equals( j.find("div").length, 0, "Check node,textnode,comment to find zero divs" );
\r
999 test("clone()", function() {
\r
1001 equals( 'This is a normal link: Yahoo', jQuery('#en').text(), 'Assert text for #en' );
\r
1002 var clone = jQuery('#yahoo').clone();
\r
1003 equals( 'Try them out:Yahoo', jQuery('#first').append(clone).text(), 'Check for clone' );
\r
1004 equals( 'This is a normal link: Yahoo', jQuery('#en').text(), 'Reassert text for #en' );
\r
1007 "<table/>", "<tr/>", "<td/>", "<div/>",
\r
1008 "<button/>", "<ul/>", "<ol/>", "<li/>",
\r
1009 "<input type='checkbox' />", "<select/>", "<option/>", "<textarea/>",
\r
1010 "<tbody/>", "<thead/>", "<tfoot/>", "<iframe/>"
\r
1012 for (var i = 0; i < cloneTags.length; i++) {
\r
1013 var j = jQuery(cloneTags[i]);
\r
1014 equals( j[0].tagName, j.clone()[0].tagName, 'Clone a <' + cloneTags[i].substring(1));
\r
1017 // using contents will get comments regular, text, and comment nodes
\r
1018 var cl = jQuery("#nonnodes").contents().clone();
\r
1019 ok( cl.length >= 2, "Check node,textnode,comment clone works (some browsers delete comments on clone)" );
\r
1023 test("clone() on XML nodes", function() {
\r
1026 jQuery.get("data/dashboard.xml", function (xml) {
\r
1027 var root = jQuery(xml.documentElement).clone();
\r
1028 jQuery("tab:first", xml).text("origval");
\r
1029 jQuery("tab:first", root).text("cloneval");
\r
1030 equals(jQuery("tab:first", xml).text(), "origval", "Check original XML node was correctly set");
\r
1031 equals(jQuery("tab:first", root).text(), "cloneval", "Check cloned XML node was correctly set");
\r
1037 test("is(String)", function() {
\r
1039 ok( jQuery('#form').is('form'), 'Check for element: A form must be a form' );
\r
1040 ok( !jQuery('#form').is('div'), 'Check for element: A form is not a div' );
\r
1041 ok( jQuery('#mark').is('.blog'), 'Check for class: Expected class "blog"' );
\r
1042 ok( !jQuery('#mark').is('.link'), 'Check for class: Did not expect class "link"' );
\r
1043 ok( jQuery('#simon').is('.blog.link'), 'Check for multiple classes: Expected classes "blog" and "link"' );
\r
1044 ok( !jQuery('#simon').is('.blogTest'), 'Check for multiple classes: Expected classes "blog" and "link", but not "blogTest"' );
\r
1045 ok( jQuery('#en').is('[lang="en"]'), 'Check for attribute: Expected attribute lang to be "en"' );
\r
1046 ok( !jQuery('#en').is('[lang="de"]'), 'Check for attribute: Expected attribute lang to be "en", not "de"' );
\r
1047 ok( jQuery('#text1').is('[type="text"]'), 'Check for attribute: Expected attribute type to be "text"' );
\r
1048 ok( !jQuery('#text1').is('[type="radio"]'), 'Check for attribute: Expected attribute type to be "text", not "radio"' );
\r
1049 ok( jQuery('#text2').is(':disabled'), 'Check for pseudoclass: Expected to be disabled' );
\r
1050 ok( !jQuery('#text1').is(':disabled'), 'Check for pseudoclass: Expected not disabled' );
\r
1051 ok( jQuery('#radio2').is(':checked'), 'Check for pseudoclass: Expected to be checked' );
\r
1052 ok( !jQuery('#radio1').is(':checked'), 'Check for pseudoclass: Expected not checked' );
\r
1053 ok( jQuery('#foo').is(':has(p)'), 'Check for child: Expected a child "p" element' );
\r
1054 ok( !jQuery('#foo').is(':has(ul)'), 'Check for child: Did not expect "ul" element' );
\r
1055 ok( jQuery('#foo').is(':has(p):has(a):has(code)'), 'Check for childs: Expected "p", "a" and "code" child elements' );
\r
1056 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
1057 ok( !jQuery('#foo').is(0), 'Expected false for an invalid expression - 0' );
\r
1058 ok( !jQuery('#foo').is(null), 'Expected false for an invalid expression - null' );
\r
1059 ok( !jQuery('#foo').is(''), 'Expected false for an invalid expression - ""' );
\r
1060 ok( !jQuery('#foo').is(undefined), 'Expected false for an invalid expression - undefined' );
\r
1062 // test is() with comma-seperated expressions
\r
1063 ok( jQuery('#en').is('[lang="en"],[lang="de"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
\r
1064 ok( jQuery('#en').is('[lang="de"],[lang="en"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
\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
1069 test("jQuery.extend(Object, Object)", function() {
\r
1072 var settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
\r
1073 options = { xnumber2: 1, xstring2: "x", xxx: "newstring" },
\r
1074 optionsCopy = { xnumber2: 1, xstring2: "x", xxx: "newstring" },
\r
1075 merged = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "x", xxx: "newstring" },
\r
1076 deep1 = { foo: { bar: true } },
\r
1077 deep1copy = { foo: { bar: true } },
\r
1078 deep2 = { foo: { baz: true }, foo2: document },
\r
1079 deep2copy = { foo: { baz: true }, foo2: document },
\r
1080 deepmerged = { foo: { bar: true, baz: true }, foo2: document };
\r
1082 jQuery.extend(settings, options);
\r
1083 isObj( settings, merged, "Check if extended: settings must be extended" );
\r
1084 isObj( options, optionsCopy, "Check if not modified: options must not be modified" );
\r
1086 jQuery.extend(settings, null, options);
\r
1087 isObj( settings, merged, "Check if extended: settings must be extended" );
\r
1088 isObj( options, optionsCopy, "Check if not modified: options must not be modified" );
\r
1090 jQuery.extend(true, deep1, deep2);
\r
1091 isObj( deep1.foo, deepmerged.foo, "Check if foo: settings must be extended" );
\r
1092 isObj( deep2.foo, deep2copy.foo, "Check if not deep2: options must not be modified" );
\r
1093 equals( deep1.foo2, document, "Make sure that a deep clone was not attempted on the document" );
\r
1096 nullUndef = jQuery.extend({}, options, { xnumber2: null });
\r
1097 ok( nullUndef.xnumber2 === null, "Check to make sure null values are copied");
\r
1099 nullUndef = jQuery.extend({}, options, { xnumber2: undefined });
\r
1100 ok( nullUndef.xnumber2 === options.xnumber2, "Check to make sure undefined values are not copied");
\r
1102 nullUndef = jQuery.extend({}, options, { xnumber0: null });
\r
1103 ok( nullUndef.xnumber0 === null, "Check to make sure null values are inserted");
\r
1106 var recursive = { foo:target, bar:5 };
\r
1107 jQuery.extend(true, target, recursive);
\r
1108 isObj( target, { bar:5 }, "Check to make sure a recursive obj doesn't go never-ending loop by not copying it over" );
\r
1110 var ret = jQuery.extend(true, { foo: [] }, { foo: [0] } ); // 1907
\r
1111 equals( ret.foo.length, 1, "Check to make sure a value with coersion 'false' copies over when necessary to fix #1907" );
\r
1113 var ret = jQuery.extend(true, { foo: "1,2,3" }, { foo: [1, 2, 3] } );
\r
1114 ok( typeof ret.foo != "string", "Check to make sure values equal with coersion (but not actually equal) overwrite correctly" );
\r
1116 var ret = jQuery.extend(true, { foo:"bar" }, { foo:null } );
\r
1117 ok( typeof ret.foo !== 'undefined', "Make sure a null value doesn't crash with deep extend, for #1908" );
\r
1119 var obj = { foo:null };
\r
1120 jQuery.extend(true, obj, { foo:"notnull" } );
\r
1121 equals( obj.foo, "notnull", "Make sure a null value can be overwritten" );
\r
1123 function func() {}
\r
1124 jQuery.extend(func, { key: "value" } );
\r
1125 equals( func.key, "value", "Verify a function can be extended" );
\r
1127 var defaults = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
\r
1128 defaultsCopy = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
\r
1129 options1 = { xnumber2: 1, xstring2: "x" },
\r
1130 options1Copy = { xnumber2: 1, xstring2: "x" },
\r
1131 options2 = { xstring2: "xx", xxx: "newstringx" },
\r
1132 options2Copy = { xstring2: "xx", xxx: "newstringx" },
\r
1133 merged2 = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "xx", xxx: "newstringx" };
\r
1135 var settings = jQuery.extend({}, defaults, options1, options2);
\r
1136 isObj( settings, merged2, "Check if extended: settings must be extended" );
\r
1137 isObj( defaults, defaultsCopy, "Check if not modified: options1 must not be modified" );
\r
1138 isObj( options1, options1Copy, "Check if not modified: options1 must not be modified" );
\r
1139 isObj( options2, options2Copy, "Check if not modified: options2 must not be modified" );
\r
1142 test("val()", function() {
\r
1144 equals( jQuery("#text1").val(), "Test", "Check for value of input element" );
\r
1145 // ticket #1714 this caused a JS error in IE
\r
1146 equals( jQuery("#first").val(), "", "Check a paragraph element to see if it has a value" );
\r
1147 ok( jQuery([]).val() === undefined, "Check an empty jQuery object will return undefined from val" );
\r
1150 test("val(String/Number)", function() {
\r
1152 document.getElementById('text1').value = "bla";
\r
1153 equals( jQuery("#text1").val(), "bla", "Check for modified value of input element" );
\r
1155 jQuery("#text1").val('test');
\r
1156 equals( document.getElementById('text1').value, "test", "Check for modified (via val(String)) value of input element" );
\r
1158 jQuery("#text1").val(67);
\r
1159 equals( document.getElementById('text1').value, "67", "Check for modified (via val(Number)) value of input element" );
\r
1161 jQuery("#select1").val("3");
\r
1162 equals( jQuery("#select1").val(), "3", "Check for modified (via val(String)) value of select element" );
\r
1164 jQuery("#select1").val(2);
\r
1165 equals( jQuery("#select1").val(), "2", "Check for modified (via val(Number)) value of select element" );
\r
1167 // using contents will get comments regular, text, and comment nodes
\r
1168 var j = jQuery("#nonnodes").contents();
\r
1170 equals( j.val(), "asdf", "Check node,textnode,comment with val()" );
\r
1171 j.removeAttr("value");
\r
1174 var scriptorder = 0;
\r
1176 test("html(String)", function() {
\r
1178 var div = jQuery("#main > div");
\r
1179 div.html("<b>test</b>");
\r
1181 for ( var i = 0; i < div.size(); i++ ) {
\r
1182 if ( div.get(i).childNodes.length != 1 ) pass = false;
\r
1184 ok( pass, "Set HTML" );
\r
1187 // using contents will get comments regular, text, and comment nodes
\r
1188 var j = jQuery("#nonnodes").contents();
\r
1189 j.html("<b>bold</b>");
\r
1191 // this is needed, or the expando added by jQuery unique will yield a different html
\r
1192 j.find('b').removeData();
\r
1193 equals( j.html().toLowerCase(), "<b>bold</b>", "Check node,textnode,comment with html()" );
\r
1195 jQuery("#main").html("<select/>");
\r
1196 jQuery("#main select").html("<option>O1</option><option selected='selected'>O2</option><option>O3</option>");
\r
1197 equals( jQuery("#main select").val(), "O2", "Selected option correct" );
\r
1199 var $div = jQuery('<div />');
\r
1200 equals( $div.html( 5 ).html(), '5', 'Setting a number as html' );
\r
1201 equals( $div.html( 0 ).html(), '0', 'Setting a zero as html' );
\r
1205 jQuery("#main").html('<script type="text/javascript">ok( true, "jQuery().html().evalScripts() Evals Scripts Twice in Firefox, see #975" );</script>');
\r
1207 jQuery("#main").html('foo <form><script type="text/javascript">ok( true, "jQuery().html().evalScripts() Evals Scripts Twice in Firefox, see #975" );</script></form>');
\r
1209 // 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
1210 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
1212 setTimeout( start, 100 );
\r
1215 test("filter()", function() {
\r
1217 isSet( jQuery("#form input").filter(":checked").get(), q("radio2", "check1"), "filter(String)" );
\r
1218 isSet( jQuery("p").filter("#ap, #sndp").get(), q("ap", "sndp"), "filter('String, String')" );
\r
1219 isSet( jQuery("p").filter("#ap,#sndp").get(), q("ap", "sndp"), "filter('String,String')" );
\r
1220 isSet( jQuery("p").filter(function() { return !jQuery("a", this).length }).get(), q("sndp", "first"), "filter(Function)" );
\r
1222 // using contents will get comments regular, text, and comment nodes
\r
1223 var j = jQuery("#nonnodes").contents();
\r
1224 equals( j.filter("span").length, 1, "Check node,textnode,comment to filter the one span" );
\r
1225 equals( j.filter("[name]").length, 0, "Check node,textnode,comment to filter the one span" );
\r
1228 test("not()", function() {
\r
1230 equals( jQuery("#main > p#ap > a").not("#google").length, 2, "not('selector')" );
\r
1231 equals( jQuery("#main > p#ap > a").not(document.getElementById("google")).length, 2, "not(DOMElement)" );
\r
1232 isSet( jQuery("p").not(".result").get(), q("firstp", "ap", "sndp", "en", "sap", "first"), "not('.class')" );
\r
1233 isSet( jQuery("p").not("#ap, #sndp, .result").get(), q("firstp", "en", "sap", "first"), "not('selector, selector')" );
\r
1234 isSet( jQuery("p").not(jQuery("#ap, #sndp, .result")).get(), q("firstp", "en", "sap", "first"), "not(jQuery)" );
\r
1235 equals( jQuery("p").not(document.getElementsByTagName("p")).length, 0, "not(Array-like DOM collection)" );
\r
1236 isSet( jQuery("#form option").not("option.emptyopt:contains('Nothing'),[selected],[value='1']").get(), q("option1c", "option1d", "option2c", "option3d" ), "not('complex selector')");
\r
1238 var selects = jQuery("#form select");
\r
1239 isSet( selects.not( selects[1] ), q("select1", "select3"), "filter out DOM element");
\r
1242 test("andSelf()", function() {
\r
1244 isSet( jQuery("#en").siblings().andSelf().get(), q("sndp", "sap","en"), "Check for siblings and self" );
\r
1245 isSet( jQuery("#foo").children().andSelf().get(), q("sndp", "en", "sap", "foo"), "Check for children and self" );
\r
1246 isSet( jQuery("#en, #sndp").parent().andSelf().get(), q("foo","en","sndp"), "Check for parent and self" );
\r
1247 isSet( jQuery("#groups").parents("p, div").andSelf().get(), q("ap", "main", "groups"), "Check for parents and self" );
\r
1250 test("siblings([String])", function() {
\r
1252 isSet( jQuery("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" );
\r
1253 isSet( jQuery("#sndp").siblings(":has(code)").get(), q("sap"), "Check for filtered siblings (has code child element)" );
\r
1254 isSet( jQuery("#sndp").siblings(":has(a)").get(), q("en", "sap"), "Check for filtered siblings (has anchor child element)" );
\r
1255 isSet( jQuery("#foo").siblings("form, b").get(), q("form", "lengthtest", "testForm", "floatTest"), "Check for multiple filters" );
\r
1256 isSet( jQuery("#en, #sndp").siblings().get(), q("sndp", "sap", "en"), "Check for unique results from siblings" );
\r
1259 test("children([String])", function() {
\r
1261 isSet( jQuery("#foo").children().get(), q("sndp", "en", "sap"), "Check for children" );
\r
1262 isSet( jQuery("#foo").children(":has(code)").get(), q("sndp", "sap"), "Check for filtered children" );
\r
1263 isSet( jQuery("#foo").children("#en, #sap").get(), q("en", "sap"), "Check for multiple filters" );
\r
1266 test("parent([String])", function() {
\r
1268 equals( jQuery("#groups").parent()[0].id, "ap", "Simple parent check" );
\r
1269 equals( jQuery("#groups").parent("p")[0].id, "ap", "Filtered parent check" );
\r
1270 equals( jQuery("#groups").parent("div").length, 0, "Filtered parent check, no match" );
\r
1271 equals( jQuery("#groups").parent("div, p")[0].id, "ap", "Check for multiple filters" );
\r
1272 isSet( jQuery("#en, #sndp").parent().get(), q("foo"), "Check for unique results from parent" );
\r
1275 test("parents([String])", function() {
\r
1277 equals( jQuery("#groups").parents()[0].id, "ap", "Simple parents check" );
\r
1278 equals( jQuery("#groups").parents("p")[0].id, "ap", "Filtered parents check" );
\r
1279 equals( jQuery("#groups").parents("div")[0].id, "main", "Filtered parents check2" );
\r
1280 isSet( jQuery("#groups").parents("p, div").get(), q("ap", "main"), "Check for multiple filters" );
\r
1281 isSet( jQuery("#en, #sndp").parents().get(), q("foo", "main", "dl", "body", "html"), "Check for unique results from parents" );
\r
1284 test("next([String])", function() {
\r
1286 equals( jQuery("#ap").next()[0].id, "foo", "Simple next check" );
\r
1287 equals( jQuery("#ap").next("div")[0].id, "foo", "Filtered next check" );
\r
1288 equals( jQuery("#ap").next("p").length, 0, "Filtered next check, no match" );
\r
1289 equals( jQuery("#ap").next("div, p")[0].id, "foo", "Multiple filters" );
\r
1292 test("prev([String])", function() {
\r
1294 equals( jQuery("#foo").prev()[0].id, "ap", "Simple prev check" );
\r
1295 equals( jQuery("#foo").prev("p")[0].id, "ap", "Filtered prev check" );
\r
1296 equals( jQuery("#foo").prev("div").length, 0, "Filtered prev check, no match" );
\r
1297 equals( jQuery("#foo").prev("p, div")[0].id, "ap", "Multiple filters" );
\r
1300 test("show()", function() {
\r
1302 var pass = true, div = jQuery("div");
\r
1303 div.show().each(function(){
\r
1304 if ( this.style.display == "none" ) pass = false;
\r
1306 ok( pass, "Show" );
\r
1308 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
1313 "code" : "inline",
\r
1315 "span" : "inline",
\r
1316 "table" : jQuery.browser.msie ? "block" : "table",
\r
1317 "thead" : jQuery.browser.msie ? "block" : "table-header-group",
\r
1318 "tbody" : jQuery.browser.msie ? "block" : "table-row-group",
\r
1319 "tr" : jQuery.browser.msie ? "block" : "table-row",
\r
1320 "th" : jQuery.browser.msie ? "block" : "table-cell",
\r
1321 "td" : jQuery.browser.msie ? "block" : "table-cell",
\r
1323 "li" : jQuery.browser.msie ? "block" : "list-item"
\r
1326 jQuery.each(test, function(selector, expected) {
\r
1327 var elem = jQuery(selector, "#show-tests").show();
\r
1328 equals( elem.css("display"), expected, "Show using correct display type for " + selector );
\r
1332 test("addClass(String)", function() {
\r
1334 var div = jQuery("div");
\r
1335 div.addClass("test");
\r
1337 for ( var i = 0; i < div.size(); i++ ) {
\r
1338 if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
\r
1340 ok( pass, "Add Class" );
\r
1342 // using contents will get regular, text, and comment nodes
\r
1343 var j = jQuery("#nonnodes").contents();
\r
1344 j.addClass("asdf");
\r
1345 ok( j.hasClass("asdf"), "Check node,textnode,comment for addClass" );
\r
1348 test("removeClass(String) - simple", function() {
\r
1350 var div = jQuery("div").addClass("test").removeClass("test"),
\r
1352 for ( var i = 0; i < div.size(); i++ ) {
\r
1353 if ( div.get(i).className.indexOf("test") != -1 ) pass = false;
\r
1355 ok( pass, "Remove Class" );
\r
1358 var div = jQuery("div").addClass("test").addClass("foo").addClass("bar");
\r
1359 div.removeClass("test").removeClass("bar").removeClass("foo");
\r
1361 for ( var i = 0; i < div.size(); i++ ) {
\r
1362 if ( div.get(i).className.match(/test|bar|foo/) ) pass = false;
\r
1364 ok( pass, "Remove multiple classes" );
\r
1367 var div = jQuery("div:eq(0)").addClass("test").removeClass("");
\r
1368 ok( div.is('.test'), "Empty string passed to removeClass" );
\r
1370 // using contents will get regular, text, and comment nodes
\r
1371 var j = jQuery("#nonnodes").contents();
\r
1372 j.removeClass("asdf");
\r
1373 ok( !j.hasClass("asdf"), "Check node,textnode,comment for removeClass" );
\r
1376 test("toggleClass(String)", function() {
\r
1378 var e = jQuery("#firstp");
\r
1379 ok( !e.is(".test"), "Assert class not present" );
\r
1380 e.toggleClass("test");
\r
1381 ok( e.is(".test"), "Assert class present" );
\r
1382 e.toggleClass("test");
\r
1383 ok( !e.is(".test"), "Assert class not present" );
\r
1386 test("removeAttr(String", function() {
\r
1388 equals( jQuery('#mark').removeAttr("class")[0].className, "", "remove class" );
\r
1391 test("text(String)", function() {
\r
1393 equals( jQuery("#foo").text("<div><b>Hello</b> cruel world!</div>")[0].innerHTML, "<div><b>Hello</b> cruel world!</div>", "Check escaped text" );
\r
1395 // using contents will get comments regular, text, and comment nodes
\r
1396 var j = jQuery("#nonnodes").contents();
\r
1398 equals( jQuery(j[0]).text(), "hi!", "Check node,textnode,comment with text()" );
\r
1399 equals( j[1].nodeValue, " there ", "Check node,textnode,comment with text()" );
\r
1400 equals( j[2].nodeType, 8, "Check node,textnode,comment with text()" );
\r
1403 test("jQuery.each(Object,Function)", function() {
\r
1405 jQuery.each( [0,1,2], function(i, n){
\r
1406 equals( i, n, "Check array iteration" );
\r
1409 jQuery.each( [5,6,7], function(i, n){
\r
1410 equals( i, n - 5, "Check array iteration" );
\r
1413 jQuery.each( { name: "name", lang: "lang" }, function(i, n){
\r
1414 equals( i, n, "Check object iteration" );
\r
1418 jQuery.each([1,2,3], function(i,v){ total += v; });
\r
1419 equals( total, 6, "Looping over an array" );
\r
1421 jQuery.each([1,2,3], function(i,v){ total += v; if ( i == 1 ) return false; });
\r
1422 equals( total, 3, "Looping over an array, with break" );
\r
1424 jQuery.each({"a":1,"b":2,"c":3}, function(i,v){ total += v; });
\r
1425 equals( total, 6, "Looping over an object" );
\r
1427 jQuery.each({"a":3,"b":3,"c":3}, function(i,v){ total += v; return false; });
\r
1428 equals( total, 3, "Looping over an object, with break" );
\r
1431 test("jQuery.prop", function() {
\r
1433 var handle = function() { return this.id };
\r
1434 equals( jQuery.prop(jQuery("#ap")[0], handle), "ap", "Check with Function argument" );
\r
1435 equals( jQuery.prop(jQuery("#ap")[0], "value"), "value", "Check with value argument" );
\r
1438 test("jQuery.className", function() {
\r
1440 var x = jQuery("<p>Hi</p>")[0];
\r
1441 var c = jQuery.className;
\r
1443 equals( x.className, "hi", "Check single added class" );
\r
1444 c.add(x, "foo bar");
\r
1445 equals( x.className, "hi foo bar", "Check more added classes" );
\r
1447 equals( x.className, "", "Remove all classes" );
\r
1448 c.add(x, "hi foo bar");
\r
1449 c.remove(x, "foo");
\r
1450 equals( x.className, "hi bar", "Check removal of one class" );
\r
1451 ok( c.has(x, "hi"), "Check has1" );
\r
1452 ok( c.has(x, "bar"), "Check has2" );
\r
1455 test("jQuery.data", function() {
\r
1457 var div = jQuery("#foo")[0];
\r
1458 equals( jQuery.data(div, "test"), undefined, "Check for no data exists" );
\r
1459 jQuery.data(div, "test", "success");
\r
1460 equals( jQuery.data(div, "test"), "success", "Check for added data" );
\r
1461 jQuery.data(div, "test", "overwritten");
\r
1462 equals( jQuery.data(div, "test"), "overwritten", "Check for overwritten data" );
\r
1463 jQuery.data(div, "test", undefined);
\r
1464 equals( jQuery.data(div, "test"), "overwritten", "Check that data wasn't removed");
\r
1465 jQuery.data(div, "test", null);
\r
1466 ok( jQuery.data(div, "test") === null, "Check for null data");
\r
1469 test(".data()", function() {
\r
1471 var div = jQuery("#foo");
\r
1472 equals( div.data("test"), undefined, "Check for no data exists" );
\r
1473 div.data("test", "success");
\r
1474 equals( div.data("test"), "success", "Check for added data" );
\r
1475 div.data("test", "overwritten");
\r
1476 equals( div.data("test"), "overwritten", "Check for overwritten data" );
\r
1477 div.data("test", undefined);
\r
1478 equals( div.data("test"), "overwritten", "Check that data wasn't removed");
\r
1479 div.data("test", null);
\r
1480 ok( div.data("test") === null, "Check for null data");
\r
1482 div.data("test", "overwritten");
\r
1483 var hits = {test:0}, gets = {test:0};
\r
1486 .bind("setData",function(e,key,value){ hits[key] += value; })
\r
1487 .bind("setData.foo",function(e,key,value){ hits[key] += value; })
\r
1488 .bind("getData",function(e,key){ gets[key] += 1; })
\r
1489 .bind("getData.foo",function(e,key){ gets[key] += 3; });
\r
1491 div.data("test.foo", 2);
\r
1492 equals( div.data("test"), "overwritten", "Check for original data" );
\r
1493 equals( div.data("test.foo"), 2, "Check for namespaced data" );
\r
1494 equals( div.data("test.bar"), "overwritten", "Check for unmatched namespace" );
\r
1495 equals( hits.test, 2, "Check triggered setter functions" );
\r
1496 equals( gets.test, 5, "Check triggered getter functions" );
\r
1501 div.data("test", 1);
\r
1502 equals( div.data("test"), 1, "Check for original data" );
\r
1503 equals( div.data("test.foo"), 2, "Check for namespaced data" );
\r
1504 equals( div.data("test.bar"), 1, "Check for unmatched namespace" );
\r
1505 equals( hits.test, 1, "Check triggered setter functions" );
\r
1506 equals( gets.test, 5, "Check triggered getter functions" );
\r
1512 .bind("getData",function(e,key){ return key + "root"; })
\r
1513 .bind("getData.foo",function(e,key){ return key + "foo"; });
\r
1515 equals( div.data("test"), "testroot", "Check for original data" );
\r
1516 equals( div.data("test.foo"), "testfoo", "Check for namespaced data" );
\r
1517 equals( div.data("test.bar"), "testroot", "Check for unmatched namespace" );
\r
1520 test("jQuery.removeData", function() {
\r
1522 var div = jQuery("#foo")[0];
\r
1523 jQuery.data(div, "test", "testing");
\r
1524 jQuery.removeData(div, "test");
\r
1525 equals( jQuery.data(div, "test"), undefined, "Check removal of data" );
\r
1528 test(".removeData()", function() {
\r
1530 var div = jQuery("#foo");
\r
1531 div.data("test", "testing");
\r
1532 div.removeData("test");
\r
1533 equals( div.data("test"), undefined, "Check removal of data" );
\r
1535 div.data("test", "testing");
\r
1536 div.data("test.foo", "testing2");
\r
1537 div.removeData("test.bar");
\r
1538 equals( div.data("test.foo"), "testing2", "Make sure data is intact" );
\r
1539 equals( div.data("test"), "testing", "Make sure data is intact" );
\r
1541 div.removeData("test");
\r
1542 equals( div.data("test.foo"), "testing2", "Make sure data is intact" );
\r
1543 equals( div.data("test"), undefined, "Make sure data is intact" );
\r
1545 div.removeData("test.foo");
\r
1546 equals( div.data("test.foo"), undefined, "Make sure data is intact" );
\r
1549 test("remove()", function() {
\r
1551 jQuery("#ap").children().remove();
\r
1552 ok( jQuery("#ap").text().length > 10, "Check text is not removed" );
\r
1553 equals( jQuery("#ap").children().length, 0, "Check remove" );
\r
1556 jQuery("#ap").children().remove("a");
\r
1557 ok( jQuery("#ap").text().length > 10, "Check text is not removed" );
\r
1558 equals( jQuery("#ap").children().length, 1, "Check filtered remove" );
\r
1560 // using contents will get comments regular, text, and comment nodes
\r
1561 equals( jQuery("#nonnodes").contents().length, 3, "Check node,textnode,comment remove works" );
\r
1562 jQuery("#nonnodes").contents().remove();
\r
1563 equals( jQuery("#nonnodes").contents().length, 0, "Check node,textnode,comment remove works" );
\r
1566 test("empty()", function() {
\r
1568 equals( jQuery("#ap").children().empty().text().length, 0, "Check text is removed" );
\r
1569 equals( jQuery("#ap").children().length, 4, "Check elements are not removed" );
\r
1571 // using contents will get comments regular, text, and comment nodes
\r
1572 var j = jQuery("#nonnodes").contents();
\r
1574 equals( j.html(), "", "Check node,textnode,comment empty works" );
\r
1577 test("slice()", function() {
\r
1580 var $links = jQuery("#ap a");
\r
1582 isSet( $links.slice(1,2), q("groups"), "slice(1,2)" );
\r
1583 isSet( $links.slice(1), q("groups", "anchor1", "mark"), "slice(1)" );
\r
1584 isSet( $links.slice(0,3), q("google", "groups", "anchor1"), "slice(0,3)" );
\r
1585 isSet( $links.slice(-1), q("mark"), "slice(-1)" );
\r
1587 isSet( $links.eq(1), q("groups"), "eq(1)" );
\r
1589 isSet( $links.eq('2'), q("anchor1"), "eq('2')" );
\r
1592 test("map()", function() {
\r
1593 expect(2);//expect(6);
\r
1596 jQuery("#ap").map(function(){
\r
1597 return jQuery(this).find("a").get();
\r
1599 q("google", "groups", "anchor1", "mark"),
\r
1604 jQuery("#ap > a").map(function(){
\r
1605 return this.parentNode;
\r
1607 q("ap","ap","ap"),
\r
1611 return;//these haven't been accepted yet
\r
1614 var keys = jQuery.map( {a:1,b:2}, function( v, k ){
\r
1618 equals( keys.join(""), "ab", "Map the keys from a hash to an array" );
\r
1620 var values = jQuery.map( {a:1,b:2}, function( v, k ){
\r
1624 equals( values.join(""), "12", "Map the values from a hash to an array" );
\r
1626 var scripts = document.getElementsByTagName("script");
\r
1627 var mapped = jQuery.map( scripts, function( v, k ){
\r
1631 equals( mapped.length, scripts.length, "Map an array(-like) to a hash" );
\r
1633 var flat = jQuery.map( Array(4), function( v, k ){
\r
1634 return k % 2 ? k : [k,k,k];//try mixing array and regular returns
\r
1637 equals( flat.join(""), "00012223", "try the new flatten technique(#2616)" );
\r
1640 test("contents()", function() {
\r
1642 equals( jQuery("#ap").contents().length, 9, "Check element contents" );
\r
1643 ok( jQuery("#iframe").contents()[0], "Check existance of IFrame document" );
\r
1644 var ibody = jQuery("#loadediframe").contents()[0].body;
\r
1645 ok( ibody, "Check existance of IFrame body" );
\r
1647 equals( jQuery("span", ibody).text(), "span text", "Find span in IFrame and check its text" );
\r
1649 jQuery(ibody).append("<div>init text</div>");
\r
1650 equals( jQuery("div", ibody).length, 2, "Check the original div and the new div are in IFrame" );
\r
1652 equals( jQuery("div:last", ibody).text(), "init text", "Add text to div in IFrame" );
\r
1654 jQuery("div:last", ibody).text("div text");
\r
1655 equals( jQuery("div:last", ibody).text(), "div text", "Add text to div in IFrame" );
\r
1657 jQuery("div:last", ibody).remove();
\r
1658 equals( jQuery("div", ibody).length, 1, "Delete the div and check only one div left in IFrame" );
\r
1660 equals( jQuery("div", ibody).text(), "span text", "Make sure the correct div is still left after deletion in IFrame" );
\r
1662 jQuery("<table/>", ibody).append("<tr><td>cell</td></tr>").appendTo(ibody);
\r
1663 jQuery("table", ibody).remove();
\r
1664 equals( jQuery("div", ibody).length, 1, "Check for JS error on add and delete of a table in IFrame" );
\r
1666 // using contents will get comments regular, text, and comment nodes
\r
1667 var c = jQuery("#nonnodes").contents().contents();
\r
1668 equals( c.length, 1, "Check node,textnode,comment contents is just one" );
\r
1669 equals( c[0].nodeValue, "hi", "Check node,textnode,comment contents is just the one from span" );
\r
1672 test("jQuery.makeArray", function(){
\r
1675 equals( jQuery.makeArray(jQuery('html>*'))[0].nodeName, "HEAD", "Pass makeArray a jQuery object" );
\r
1677 equals( jQuery.makeArray(document.getElementsByName("PWD")).slice(0,1)[0].name, "PWD", "Pass makeArray a nodelist" );
\r
1679 equals( (function(){ return jQuery.makeArray(arguments); })(1,2).join(""), "12", "Pass makeArray an arguments array" );
\r
1681 equals( jQuery.makeArray([1,2,3]).join(""), "123", "Pass makeArray a real array" );
\r
1683 equals( jQuery.makeArray().length, 0, "Pass nothing to makeArray and expect an empty array" );
\r
1685 equals( jQuery.makeArray( 0 )[0], 0 , "Pass makeArray a number" );
\r
1687 equals( jQuery.makeArray( "foo" )[0], "foo", "Pass makeArray a string" );
\r
1689 equals( jQuery.makeArray( true )[0].constructor, Boolean, "Pass makeArray a boolean" );
\r
1691 equals( jQuery.makeArray( document.createElement("div") )[0].nodeName, "DIV", "Pass makeArray a single node" );
\r
1693 equals( jQuery.makeArray( {length:2, 0:"a", 1:"b"} ).join(""), "ab", "Pass makeArray an array like map (with length)" );
\r
1695 ok( !!jQuery.makeArray( document.documentElement.childNodes ).slice(0,1)[0].nodeName, "Pass makeArray a childNodes array" );
\r
1697 //function, is tricky as it has length
\r
1698 equals( jQuery.makeArray( function(){ return 1;} )[0](), 1, "Pass makeArray a function" );
\r
1699 //window, also has length
\r
1700 equals( jQuery.makeArray(window)[0], window, "Pass makeArray the window" );
\r
1702 equals( jQuery.makeArray(/a/)[0].constructor, RegExp, "Pass makeArray a regex" );
\r
1704 ok( jQuery.makeArray(document.getElementById('form')).length >= 13, "Pass makeArray a form (treat as elements)" );
\r