jbarnette-johnson 1.0.0.20090326122910 → 1.0.0.20090326154650

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,1571 +0,0 @@
1
- module("core");
2
-
3
- var isLocal = true;
4
-
5
- test("Basic requirements", function() {
6
- expect(7);
7
- ok( Array.prototype.push, "Array.push()" );
8
- ok( Function.prototype.apply, "Function.apply()" );
9
- ok( document.getElementById, "getElementById" );
10
- ok( document.getElementsByTagName, "getElementsByTagName" );
11
- ok( RegExp, "RegExp" );
12
- ok( jQuery, "jQuery" );
13
- ok( $, "$()" );
14
- });
15
-
16
- test("$()", function() {
17
- expect(4);
18
-
19
- var main = $("#main");
20
-
21
- isSet( $("div p", main).get(), q("sndp", "en", "sap"), "Basic selector with jQuery object as context" );
22
-
23
- /*
24
- // disabled since this test was doing nothing. i tried to fix it but i'm not sure
25
- // what the expected behavior should even be. FF returns "\n" for the text node
26
- // make sure this is handled
27
- var crlfContainer = $('<p>\r\n</p>');
28
- var x = crlfContainer.contents().get(0).nodeValue;
29
- equals( x, what???, "Check for \\r and \\n in jQuery()" );
30
- */
31
-
32
- /* // Disabled until we add this functionality in
33
- var pass = true;
34
- try {
35
- $("<div>Testing</div>").appendTo(document.getElementById("iframe").contentDocument.body);
36
- } catch(e){
37
- pass = false;
38
- }
39
- ok( pass, "$('&lt;tag&gt;') needs optional document parameter to ease cross-frame DOM wrangling, see #968" );*/
40
-
41
- var code = $("<code/>");
42
- equals( code.length, 1, "Correct number of elements generated for code" );
43
- var img = $("<img/>");
44
- equals( img.length, 1, "Correct number of elements generated for img" );
45
- var div = $("<div/><hr/><code/><b/>");
46
- equals( div.length, 4, "Correct number of elements generated for div hr code b" );
47
- });
48
-
49
- test("browser", function() {
50
- expect(13);
51
- var browsers = {
52
- //Internet Explorer
53
- "Mozilla/5.0 (Windows; U; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)": "6.0",
54
- "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",
55
- /** Failing #1876
56
- * "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",
57
- */
58
- //Browsers with Gecko engine
59
- //Mozilla
60
- "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.12) Gecko/20050915" : "1.7.12",
61
- //Firefox
62
- "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",
63
- //Netscape
64
- "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20070321 Netscape/8.1.3" : "1.7.5",
65
- //Flock
66
- "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",
67
- //Opera browser
68
- "Opera/9.20 (X11; Linux x86_64; U; en)": "9.20",
69
- "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; en) Opera 9.20" : "9.20",
70
- "Mozilla/5.0 (Windows NT 5.1; U; pl; rv:1.8.0) Gecko/20060728 Firefox/1.5.0 Opera 9.20": "9.20",
71
- //WebKit engine
72
- "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; sv-se) AppleWebKit/418.9 (KHTML, like Gecko) Safari/419.3": "418.9",
73
- "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/418.8 (KHTML, like Gecko) Safari/419.3" : "418.8",
74
- "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; sv-se) AppleWebKit/312.8 (KHTML, like Gecko) Safari/312.5": "312.8",
75
- //Other user agent string
76
- "Other browser's user agent 1.0":null
77
- };
78
- for (var i in browsers) {
79
- var v = i.toLowerCase().match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ); // RegEx from Core jQuery.browser.version check
80
- version = v ? v[1] : null;
81
- equals( version, browsers[i], "Checking UA string" );
82
- }
83
- });
84
-
85
- test("noConflict", function() {
86
- expect(6);
87
-
88
- var old = jQuery;
89
- var newjQuery = jQuery.noConflict();
90
-
91
- ok( newjQuery == old, "noConflict returned the jQuery object" );
92
- ok( jQuery == old, "Make sure jQuery wasn't touched." );
93
- ok( $ == "$", "Make sure $ was reverted." );
94
-
95
- jQuery = $ = old;
96
-
97
- newjQuery = jQuery.noConflict(true);
98
-
99
- ok( newjQuery == old, "noConflict returned the jQuery object" );
100
- ok( jQuery == "jQuery", "Make sure jQuery was reverted." );
101
- ok( $ == "$", "Make sure $ was reverted." );
102
-
103
- jQuery = $ = old;
104
- });
105
-
106
- test("isFunction", function() {
107
- expect(21);
108
-
109
- // Make sure that false values return false
110
- ok( !jQuery.isFunction(), "No Value" );
111
- ok( !jQuery.isFunction( null ), "null Value" );
112
- ok( !jQuery.isFunction( undefined ), "undefined Value" );
113
- ok( !jQuery.isFunction( "" ), "Empty String Value" );
114
- ok( !jQuery.isFunction( 0 ), "0 Value" );
115
-
116
- // Check built-ins
117
- // Safari uses "(Internal Function)"
118
- ok( jQuery.isFunction(String), "String Function" );
119
- ok( jQuery.isFunction(Array), "Array Function" );
120
- ok( jQuery.isFunction(Object), "Object Function" );
121
- ok( jQuery.isFunction(Function), "Function Function" );
122
-
123
- // When stringified, this could be misinterpreted
124
- var mystr = "function";
125
- ok( !jQuery.isFunction(mystr), "Function String" );
126
-
127
- // When stringified, this could be misinterpreted
128
- var myarr = [ "function" ];
129
- ok( !jQuery.isFunction(myarr), "Function Array" );
130
-
131
- // When stringified, this could be misinterpreted
132
- var myfunction = { "function": "test" };
133
- ok( !jQuery.isFunction(myfunction), "Function Object" );
134
-
135
- // Make sure normal functions still work
136
- var fn = function(){};
137
- ok( jQuery.isFunction(fn), "Normal Function" );
138
-
139
- var obj = document.createElement("object");
140
-
141
- // Firefox says this is a function
142
- ok( !jQuery.isFunction(obj), "Object Element" );
143
-
144
- // IE says this is an object
145
- ok( jQuery.isFunction(obj.getAttribute), "getAttribute Function" );
146
-
147
- var nodes = document.body.childNodes;
148
-
149
- // Safari says this is a function
150
- ok( !jQuery.isFunction(nodes), "childNodes Property" );
151
-
152
- var first = document.body.firstChild;
153
-
154
- // Normal elements are reported ok everywhere
155
- ok( !jQuery.isFunction(first), "A normal DOM Element" );
156
-
157
- var input = document.createElement("input");
158
- input.type = "text";
159
- document.body.appendChild( input );
160
-
161
- // IE says this is an object
162
- ok( jQuery.isFunction(input.focus), "A default function property" );
163
-
164
- document.body.removeChild( input );
165
-
166
- var a = document.createElement("a");
167
- a.href = "some-function";
168
- document.body.appendChild( a );
169
-
170
- // This serializes with the word 'function' in it
171
- ok( !jQuery.isFunction(a), "Anchor Element" );
172
-
173
- document.body.removeChild( a );
174
-
175
- // Recursive function calls have lengths and array-like properties
176
- function callme(callback){
177
- function fn(response){
178
- callback(response);
179
- }
180
-
181
- ok( jQuery.isFunction(fn), "Recursive Function Call" );
182
-
183
- fn({ some: "data" });
184
- };
185
-
186
- callme(function(){
187
- callme(function(){});
188
- });
189
- });
190
-
191
- var foo = false;
192
-
193
- test("$('html')", function() {
194
- expect(6);
195
-
196
- reset();
197
- foo = false;
198
- var s = $("<script>var foo='test';</script>")[0];
199
- ok( s, "Creating a script" );
200
- ok( !foo, "Make sure the script wasn't executed prematurely" );
201
- $("body").append(s);
202
- ok( foo, "Executing a scripts contents in the right context" );
203
-
204
- reset();
205
- ok( $("<link rel='stylesheet'/>")[0], "Creating a link" );
206
-
207
- reset();
208
-
209
- var j = $("<span>hi</span> there <!-- mon ami -->");
210
- ok( j.length >= 2, "Check node,textnode,comment creation (some browsers delete comments)" );
211
-
212
- // FIXME I have no idea what is wrong with this
213
- ok( !$("<option>test</option>")[0].selected, "Make sure that options are auto-selected #2050" );
214
- });
215
-
216
- test("$('html', context)", function() {
217
- expect(1);
218
-
219
- var $div = $("<div/>");
220
- var $span = $("<span/>", $div);
221
- equals($span.length, 1, "Verify a span created with a div context works, #1763");
222
- });
223
-
224
- if ( !isLocal ) {
225
- test("$(selector, xml).text(str) - Loaded via XML document", function() {
226
- expect(2);
227
- stop();
228
- $.get('data/dashboard.xml', function(xml) {
229
- // tests for #1419 where IE was a problem
230
- equals( $("tab:first", xml).text(), "blabla", "Verify initial text correct" );
231
- $("tab:first", xml).text("newtext");
232
- equals( $("tab:first", xml).text(), "newtext", "Verify new text correct" );
233
- start();
234
- });
235
- });
236
- }
237
-
238
- test("length", function() {
239
- expect(1);
240
- ok( $("p").length == 6, "Get Number of Elements Found" );
241
- });
242
-
243
- test("size()", function() {
244
- expect(1);
245
- ok( $("p").size() == 6, "Get Number of Elements Found" );
246
- });
247
-
248
- test("get()", function() {
249
- expect(1);
250
- isSet( $("p").get(), q("firstp","ap","sndp","en","sap","first"), "Get All Elements" );
251
- });
252
-
253
- test("get(Number)", function() {
254
- expect(1);
255
- ok( $("p").get(0) == document.getElementById("firstp"), "Get A Single Element" );
256
- });
257
-
258
- test("add(String|Element|Array|undefined)", function() {
259
- expect(8);
260
- isSet( $("#sndp").add("#en").add("#sap").get(), q("sndp", "en", "sap"), "Check elements from document" );
261
- isSet( $("#sndp").add( $("#en")[0] ).add( $("#sap") ).get(), q("sndp", "en", "sap"), "Check elements from document" );
262
-
263
- // FIXME wtf. for some reason, this totally breaks. I have
264
- // no idea why... The problem boils down to this line though:
265
- // $("#form");
266
- ok( $([]).add($("#form")[0].elements).length >= 13, "Check elements from array" );
267
-
268
- // For the time being, we're discontinuing support for $(form.elements) since it's ambiguous in IE
269
- // use $([]).add(form.elements) instead.
270
- //equals( $([]).add($("#form")[0].elements).length, $($("#form")[0].elements).length, "Array in constructor must equals array in add()" );
271
-
272
- var x = $([]).add($("<p id='x1'>xxx</p>")).add($("<p id='x2'>xxx</p>"));
273
- ok( x[0].id == "x1", "Check on-the-fly element1" );
274
- ok( x[1].id == "x2", "Check on-the-fly element2" );
275
-
276
- var x = $([]).add("<p id='x1'>xxx</p>").add("<p id='x2'>xxx</p>");
277
- ok( x[0].id == "x1", "Check on-the-fly element1" );
278
- ok( x[1].id == "x2", "Check on-the-fly element2" );
279
-
280
- var notDefined;
281
- equals( $([]).add(notDefined).length, 0, "Check that undefined adds nothing." );
282
- });
283
-
284
- test("each(Function)", function() {
285
- expect(1);
286
- var div = $("div");
287
- div.each(function(){this.foo = 'zoo';});
288
- var pass = true;
289
- for ( var i = 0; i < div.size(); i++ ) {
290
- if ( div.get(i).foo != "zoo" ) pass = false;
291
- }
292
- ok( pass, "Execute a function, Relative" );
293
- });
294
-
295
- test("index(Object)", function() {
296
- expect(8);
297
- ok( $([window, document]).index(window) == 0, "Check for index of elements" );
298
- ok( $([window, document]).index(document) == 1, "Check for index of elements" );
299
- var inputElements = $('#radio1,#radio2,#check1,#check2');
300
- ok( inputElements.index(document.getElementById('radio1')) == 0, "Check for index of elements" );
301
- ok( inputElements.index(document.getElementById('radio2')) == 1, "Check for index of elements" );
302
- ok( inputElements.index(document.getElementById('check1')) == 2, "Check for index of elements" );
303
- ok( inputElements.index(document.getElementById('check2')) == 3, "Check for index of elements" );
304
- ok( inputElements.index(window) == -1, "Check for not found index" );
305
- ok( inputElements.index(document) == -1, "Check for not found index" );
306
- });
307
-
308
- test("attr(String)", function() {
309
- expect(20);
310
- ok( $('#text1').attr('value') == "Test", 'Check for value attribute' );
311
- ok( $('#text1').attr('value', "Test2").attr('defaultValue') == "Test", 'Check for defaultValue attribute' );
312
- ok( $('#text1').attr('type') == "text", 'Check for type attribute' );
313
- ok( $('#radio1').attr('type') == "radio", 'Check for type attribute' );
314
- ok( $('#check1').attr('type') == "checkbox", 'Check for type attribute' );
315
- ok( $('#simon1').attr('rel') == "bookmark", 'Check for rel attribute' );
316
- ok( $('#google').attr('title') == "Google!", 'Check for title attribute' );
317
- ok( $('#mark').attr('hreflang') == "en", 'Check for hreflang attribute' );
318
- ok( $('#en').attr('lang') == "en", 'Check for lang attribute' );
319
- ok( $('#simon').attr('class') == "blog link", 'Check for class attribute' );
320
- ok( $('#name').attr('name') == "name", 'Check for name attribute' );
321
- ok( $('#text1').attr('name') == "action", 'Check for name attribute' );
322
- ok( $('#form').attr('action').indexOf("formaction") >= 0, 'Check for action attribute' );
323
- ok( $('#text1').attr('maxlength') == '30', 'Check for maxlength attribute' );
324
- ok( $('#text1').attr('maxLength') == '30', 'Check for maxLength attribute' );
325
- ok( $('#area1').attr('maxLength') == '30', 'Check for maxLength attribute' );
326
- ok( $('#select2').attr('selectedIndex') == 3, 'Check for selectedIndex attribute' );
327
- ok( $('#foo').attr('nodeName') == 'DIV', 'Check for nodeName attribute' );
328
- ok( $('#foo').attr('tagName') == 'DIV', 'Check for tagName attribute' );
329
-
330
- $('<a id="tAnchor5"></a>').attr('href', '#5').appendTo('#main'); // using innerHTML in IE causes href attribute to be serialized to the full path
331
- ok( $('#tAnchor5').attr('href') == "#5", 'Check for non-absolute href (an anchor)' );
332
- });
333
-
334
- if ( !isLocal ) {
335
- test("attr(String) in XML Files", function() {
336
- expect(2);
337
- stop();
338
- $.get("data/dashboard.xml", function(xml) {
339
- ok( $("locations", xml).attr("class") == "foo", "Check class attribute in XML document" );
340
- ok( $("location", xml).attr("for") == "bar", "Check for attribute in XML document" );
341
- start();
342
- });
343
- });
344
- }
345
-
346
- test("attr(String, Function)", function() {
347
- expect(2);
348
- ok( $('#text1').attr('value', function() { return this.id })[0].value == "text1", "Set value from id" );
349
- ok( $('#text1').attr('title', function(i) { return i }).attr('title') == "0", "Set value with an index");
350
- });
351
-
352
- test("attr(Hash)", function() {
353
- expect(1);
354
- var pass = true;
355
- $("div").attr({foo: 'baz', zoo: 'ping'}).each(function(){
356
- if ( this.getAttribute('foo') != "baz" && this.getAttribute('zoo') != "ping" ) pass = false;
357
- });
358
- ok( pass, "Set Multiple Attributes" );
359
- });
360
-
361
- test("attr(String, Object)", function() {
362
- expect(17);
363
- var div = $("div");
364
- div.attr("foo", "bar");
365
- var pass = true;
366
- for ( var i = 0; i < div.size(); i++ ) {
367
- if ( div.get(i).getAttribute('foo') != "bar" ) pass = false;
368
- }
369
- ok( pass, "Set Attribute" );
370
-
371
- ok( $("#foo").attr({"width": null}), "Try to set an attribute to nothing" );
372
-
373
- $("#name").attr('name', 'something');
374
- ok( $("#name").attr('name') == 'something', 'Set name attribute' );
375
- $("#check2").attr('checked', true);
376
- ok( document.getElementById('check2').checked == true, 'Set checked attribute' );
377
- $("#check2").attr('checked', false);
378
- ok( document.getElementById('check2').checked == false, 'Set checked attribute' );
379
- $("#text1").attr('readonly', true);
380
- ok( document.getElementById('text1').readOnly == true, 'Set readonly attribute' );
381
- $("#text1").attr('readonly', false);
382
- ok( document.getElementById('text1').readOnly == false, 'Set readonly attribute' );
383
- $("#name").attr('maxlength', '5');
384
- ok( document.getElementById('name').maxLength == '5', 'Set maxlength attribute' );
385
- $("#name").attr('maxLength', '10');
386
- ok( document.getElementById('name').maxLength == '10', 'Set maxlength attribute' );
387
-
388
- // for #1070
389
- $("#name").attr('someAttr', '0');
390
- equals( $("#name").attr('someAttr'), '0', 'Set attribute to a string of "0"' );
391
- $("#name").attr('someAttr', 0);
392
- equals( $("#name").attr('someAttr'), 0, 'Set attribute to the number 0' );
393
- $("#name").attr('someAttr', 1);
394
- equals( $("#name").attr('someAttr'), 1, 'Set attribute to the number 1' );
395
-
396
- // using contents will get comments regular, text, and comment nodes
397
- var j = $("#nonnodes").contents();
398
-
399
- j.attr("name", "attrvalue");
400
- equals( j.attr("name"), "attrvalue", "Check node,textnode,comment for attr" );
401
- j.removeAttr("name")
402
-
403
- reset();
404
-
405
- var type = $("#check2").attr('type');
406
- var thrown = false;
407
- try {
408
- $("#check2").attr('type','hidden');
409
- } catch(e) {
410
- thrown = true;
411
- }
412
- ok( thrown, "Exception thrown when trying to change type property" );
413
- equals( type, $("#check2").attr('type'), "Verify that you can't change the type of an input element" );
414
-
415
- var check = document.createElement("input");
416
- var thrown = true;
417
- try {
418
- $(check).attr('type','checkbox');
419
- } catch(e) {
420
- thrown = false;
421
- }
422
- ok( thrown, "Exception thrown when trying to change type property" );
423
- equals( "checkbox", $(check).attr('type'), "Verify that you can change the type of an input element that isn't in the DOM" );
424
- });
425
-
426
- if ( !isLocal ) {
427
- test("attr(String, Object) - Loaded via XML document", function() {
428
- expect(2);
429
- stop();
430
- $.get('data/dashboard.xml', function(xml) {
431
- var titles = [];
432
- $('tab', xml).each(function() {
433
- titles.push($(this).attr('title'));
434
- });
435
- equals( titles[0], 'Location', 'attr() in XML context: Check first title' );
436
- equals( titles[1], 'Users', 'attr() in XML context: Check second title' );
437
- start();
438
- });
439
- });
440
- }
441
-
442
- test("css(String|Hash)", function() {
443
- expect(19);
444
-
445
- ok( $('#main').css("display") == 'none', 'Check for css property "display"');
446
-
447
- ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
448
- $('#foo').css({display: 'none'});
449
- ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
450
- $('#foo').css({display: 'block'});
451
- ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
452
-
453
- $('#floatTest').css({styleFloat: 'right'});
454
- ok( $('#floatTest').css('styleFloat') == 'right', 'Modified CSS float using "styleFloat": Assert float is right');
455
- $('#floatTest').css({cssFloat: 'left'});
456
- ok( $('#floatTest').css('cssFloat') == 'left', 'Modified CSS float using "cssFloat": Assert float is left');
457
- $('#floatTest').css({'float': 'right'});
458
- ok( $('#floatTest').css('float') == 'right', 'Modified CSS float using "float": Assert float is right');
459
- $('#floatTest').css({'font-size': '30px'});
460
- ok( $('#floatTest').css('font-size') == '30px', 'Modified CSS font-size: Assert font-size is 30px');
461
-
462
- $.each("0,0.25,0.5,0.75,1".split(','), function(i, n) {
463
- $('#foo').css({opacity: n});
464
- ok( $('#foo').css('opacity') == parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" );
465
- $('#foo').css({opacity: parseFloat(n)});
466
- ok( $('#foo').css('opacity') == parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" );
467
- });
468
- $('#foo').css({opacity: ''});
469
- ok( $('#foo').css('opacity') == '1', "Assert opacity is 1 when set to an empty String" );
470
- });
471
-
472
- test("css(String, Object)", function() {
473
- expect(21);
474
- ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
475
- $('#foo').css('display', 'none');
476
- ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
477
- $('#foo').css('display', 'block');
478
- ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
479
-
480
- $('#floatTest').css('styleFloat', 'left');
481
- ok( $('#floatTest').css('styleFloat') == 'left', 'Modified CSS float using "styleFloat": Assert float is left');
482
- $('#floatTest').css('cssFloat', 'right');
483
- ok( $('#floatTest').css('cssFloat') == 'right', 'Modified CSS float using "cssFloat": Assert float is right');
484
- $('#floatTest').css('float', 'left');
485
- ok( $('#floatTest').css('float') == 'left', 'Modified CSS float using "float": Assert float is left');
486
- $('#floatTest').css('font-size', '20px');
487
- ok( $('#floatTest').css('font-size') == '20px', 'Modified CSS font-size: Assert font-size is 20px');
488
-
489
- $.each("0,0.25,0.5,0.75,1".split(','), function(i, n) {
490
- $('#foo').css('opacity', n);
491
- ok( $('#foo').css('opacity') == parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" );
492
- $('#foo').css('opacity', parseFloat(n));
493
- ok( $('#foo').css('opacity') == parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" );
494
- });
495
- $('#foo').css('opacity', '');
496
- ok( $('#foo').css('opacity') == '1', "Assert opacity is 1 when set to an empty String" );
497
- // for #1438, IE throws JS error when filter exists but doesn't have opacity in it
498
- if (jQuery.browser.msie) {
499
- $('#foo').css("filter", "progid:DXImageTransform.Microsoft.Chroma(color='red');");
500
- }
501
- equals( $('#foo').css('opacity'), '1', "Assert opacity is 1 when a different filter is set in IE, #1438" );
502
-
503
- // using contents will get comments regular, text, and comment nodes
504
- var j = $("#nonnodes").contents();
505
- j.css("padding-left", "1px");
506
- equals( j.css("padding-left"), "1px", "Check node,textnode,comment css works" );
507
-
508
- // opera sometimes doesn't update 'display' correctly, see #2037
509
- $("#t2037")[0].innerHTML = $("#t2037")[0].innerHTML
510
- equals( $("#t2037 .hidden").css("display"), "none", "Make sure browser thinks it is hidden" );
511
- });
512
-
513
- test("jQuery.css(elem, 'height') doesn't clear radio buttons (bug #1095)", function () {
514
- expect(4);
515
-
516
- var $checkedtest = $("#checkedtest");
517
- // IE6 was clearing "checked" in jQuery.css(elem, "height");
518
- jQuery.css($checkedtest[0], "height");
519
- ok( !! $(":radio:first", $checkedtest).attr("checked"), "Check first radio still checked." );
520
- ok( ! $(":radio:last", $checkedtest).attr("checked"), "Check last radio still NOT checked." );
521
- ok( !! $(":checkbox:first", $checkedtest).attr("checked"), "Check first checkbox still checked." );
522
- ok( ! $(":checkbox:last", $checkedtest).attr("checked"), "Check last checkbox still NOT checked." );
523
- });
524
-
525
- test("width()", function() {
526
- expect(9);
527
-
528
- var $div = $("#nothiddendiv");
529
- $div.width(30);
530
- equals($div.width(), 30, "Test set to 30 correctly");
531
- $div.width(-1); // handle negative numbers by ignoring #1599
532
- equals($div.width(), 30, "Test negative width ignored");
533
- $div.css("padding", "20px");
534
- equals($div.width(), 30, "Test padding specified with pixels");
535
- $div.css("border", "2px solid #fff");
536
- equals($div.width(), 30, "Test border specified with pixels");
537
- $div.css("padding", "2em");
538
- equals($div.width(), 30, "Test padding specified with ems");
539
- $div.css("border", "1em solid #fff");
540
- equals($div.width(), 30, "Test border specified with ems");
541
- $div.css("padding", "2%");
542
- equals($div.width(), 30, "Test padding specified with percent");
543
- $div.hide();
544
- equals($div.width(), 30, "Test hidden div");
545
-
546
- $div.css({ display: "", border: "", padding: "" });
547
-
548
- $("#nothiddendivchild").css({ padding: "3px", border: "2px solid #fff" });
549
- equals($("#nothiddendivchild").width(), 20, "Test child width with border and padding");
550
- $("#nothiddendiv, #nothiddendivchild").css({ border: "", padding: "", width: "" });
551
- });
552
-
553
- test("height()", function() {
554
- expect(8);
555
-
556
- var $div = $("#nothiddendiv");
557
- $div.height(30);
558
- equals($div.height(), 30, "Test set to 30 correctly");
559
- $div.height(-1); // handle negative numbers by ignoring #1599
560
- equals($div.height(), 30, "Test negative height ignored");
561
- $div.css("padding", "20px");
562
- equals($div.height(), 30, "Test padding specified with pixels");
563
- $div.css("border", "2px solid #fff");
564
- equals($div.height(), 30, "Test border specified with pixels");
565
- $div.css("padding", "2em");
566
- equals($div.height(), 30, "Test padding specified with ems");
567
- $div.css("border", "1em solid #fff");
568
- equals($div.height(), 30, "Test border specified with ems");
569
- $div.css("padding", "2%");
570
- equals($div.height(), 30, "Test padding specified with percent");
571
- $div.hide();
572
- equals($div.height(), 30, "Test hidden div");
573
-
574
- $div.css({ display: "", border: "", padding: "", height: "1px" });
575
- });
576
-
577
- test("text()", function() {
578
- expect(1);
579
- var expected = "This link has class=\"blog\": Simon Willison's Weblog";
580
- ok( $('#sap').text() == expected, 'Check for merged text of more then one element.' );
581
- });
582
-
583
- test("wrap(String|Element)", function() {
584
- expect(8);
585
- var defaultText = 'Try them out:'
586
- var result = $('#first').wrap('<div class="red"><span></span></div>').text();
587
- ok( defaultText == result, 'Check for wrapping of on-the-fly html' );
588
- ok( $('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
589
-
590
- reset();
591
- var defaultText = 'Try them out:'
592
- var result = $('#first').wrap(document.getElementById('empty')).parent();
593
- ok( result.is('ol'), 'Check for element wrapping' );
594
- ok( result.text() == defaultText, 'Check for element wrapping' );
595
-
596
- reset();
597
- $('#check1').click(function() {
598
- var checkbox = this;
599
- ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
600
- $(checkbox).wrap( '<div id="c1" style="display:none;"></div>' );
601
- ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
602
- }).click();
603
-
604
- // using contents will get comments regular, text, and comment nodes
605
- var j = $("#nonnodes").contents();
606
- j.wrap("<i></i>");
607
- equals( $("#nonnodes > i").length, 3, "Check node,textnode,comment wraps ok" );
608
- equals( $("#nonnodes > i").text(), j.text() + j[1].nodeValue, "Check node,textnode,comment wraps doesn't hurt text" );
609
- });
610
-
611
- test("wrapAll(String|Element)", function() {
612
- expect(8);
613
- var prev = $("#first")[0].previousSibling;
614
- var p = $("#first")[0].parentNode;
615
- var result = $('#first,#firstp').wrapAll('<div class="red"><div id="tmp"></div></div>');
616
- equals( result.parent().length, 1, 'Check for wrapping of on-the-fly html' );
617
- ok( $('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
618
- ok( $('#firstp').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
619
- equals( $("#first").parent().parent()[0].previousSibling, prev, "Correct Previous Sibling" );
620
- equals( $("#first").parent().parent()[0].parentNode, p, "Correct Parent" );
621
-
622
- reset();
623
- var prev = $("#first")[0].previousSibling;
624
- var p = $("#first")[0].parentNode;
625
- var result = $('#first,#firstp').wrapAll(document.getElementById('empty'));
626
- equals( $("#first").parent()[0], $("#firstp").parent()[0], "Same Parent" );
627
- equals( $("#first").parent()[0].previousSibling, prev, "Correct Previous Sibling" );
628
- equals( $("#first").parent()[0].parentNode, p, "Correct Parent" );
629
- });
630
-
631
- test("wrapInner(String|Element)", function() {
632
- expect(6);
633
- var num = $("#first").children().length;
634
- var result = $('#first').wrapInner('<div class="red"><div id="tmp"></div></div>');
635
- equals( $("#first").children().length, 1, "Only one child" );
636
- ok( $("#first").children().is(".red"), "Verify Right Element" );
637
- equals( $("#first").children().children().children().length, num, "Verify Elements Intact" );
638
-
639
- reset();
640
- var num = $("#first").children().length;
641
- var result = $('#first').wrapInner(document.getElementById('empty'));
642
- equals( $("#first").children().length, 1, "Only one child" );
643
- ok( $("#first").children().is("#empty"), "Verify Right Element" );
644
- equals( $("#first").children().children().length, num, "Verify Elements Intact" );
645
- });
646
-
647
- test("append(String|Element|Array&lt;Element&gt;|jQuery)", function() {
648
- expect(21);
649
- var defaultText = 'Try them out:'
650
- var result = $('#first').append('<b>buga</b>');
651
- ok( result.text() == defaultText + 'buga', 'Check if text appending works' );
652
- ok( $('#select3').append('<option value="appendTest">Append Test</option>').find('option:last-child').attr('value') == 'appendTest', 'Appending html options to select element');
653
-
654
- reset();
655
- var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
656
- $('#sap').append(document.getElementById('first'));
657
- ok( expected == $('#sap').text(), "Check for appending of element" );
658
-
659
- reset();
660
- expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
661
- $('#sap').append([document.getElementById('first'), document.getElementById('yahoo')]);
662
- ok( expected == $('#sap').text(), "Check for appending of array of elements" );
663
-
664
- reset();
665
- expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
666
- $('#sap').append($("#first, #yahoo"));
667
- ok( expected == $('#sap').text(), "Check for appending of jQuery object" );
668
-
669
- reset();
670
- $("#sap").append( 5 );
671
- ok( $("#sap")[0].innerHTML.match( /5$/ ), "Check for appending a number" );
672
-
673
- reset();
674
- $("#sap").append( " text with spaces " );
675
- ok( $("#sap")[0].innerHTML.match(/ text with spaces $/), "Check for appending text with spaces" );
676
-
677
- reset();
678
- ok( $("#sap").append([]), "Check for appending an empty array." );
679
- ok( $("#sap").append(""), "Check for appending an empty string." );
680
- ok( $("#sap").append(document.getElementsByTagName("foo")), "Check for appending an empty nodelist." );
681
-
682
- reset();
683
- $("#sap").append(document.getElementById('form'));
684
- ok( $("#sap>form").size() == 1, "Check for appending a form" ); // Bug #910
685
-
686
- reset();
687
- var pass = true;
688
- try {
689
- $( $("#iframe")[0].contentWindow.document.body ).append("<div>test</div>");
690
- } catch(e) {
691
- pass = false;
692
- }
693
-
694
- ok( pass, "Test for appending a DOM node to the contents of an IFrame" );
695
-
696
- reset();
697
- $('<fieldset/>').appendTo('#form').append('<legend id="legend">test</legend>');
698
- t( 'Append legend', '#legend', ['legend'] );
699
-
700
- reset();
701
- $('#select1').append('<OPTION>Test</OPTION>');
702
- ok( $('#select1 option:last').text() == "Test", "Appending &lt;OPTION&gt; (all caps)" );
703
-
704
- $('#table').append('<colgroup></colgroup>');
705
- ok( $('#table colgroup').length, "Append colgroup" );
706
-
707
- $('#table colgroup').append('<col/>');
708
- ok( $('#table colgroup col').length, "Append col" );
709
-
710
- reset();
711
- $('#table').append('<caption></caption>');
712
- ok( $('#table caption').length, "Append caption" );
713
-
714
- reset();
715
- $('form:last')
716
- .append('<select id="appendSelect1"></select>')
717
- .append('<select id="appendSelect2"><option>Test</option></select>');
718
-
719
- t( "Append Select", "#appendSelect1, #appendSelect2", ["appendSelect1", "appendSelect2"] );
720
-
721
- // using contents will get comments regular, text, and comment nodes
722
- var j = $("#nonnodes").contents();
723
- var d = $("<div/>").appendTo("#nonnodes").append(j);
724
- equals( $("#nonnodes").length, 1, "Check node,textnode,comment append moved leaving just the div" );
725
- ok( d.contents().length >= 2, "Check node,textnode,comment append works" );
726
- d.contents().appendTo("#nonnodes");
727
- d.remove();
728
- ok( $("#nonnodes").contents().length >= 2, "Check node,textnode,comment append cleanup worked" );
729
- });
730
-
731
- test("appendTo(String|Element|Array&lt;Element&gt;|jQuery)", function() {
732
- expect(6);
733
- var defaultText = 'Try them out:'
734
- $('<b>buga</b>').appendTo('#first');
735
- ok( $("#first").text() == defaultText + 'buga', 'Check if text appending works' );
736
- ok( $('<option value="appendTest">Append Test</option>').appendTo('#select3').parent().find('option:last-child').attr('value') == 'appendTest', 'Appending html options to select element');
737
-
738
- reset();
739
- var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
740
- $(document.getElementById('first')).appendTo('#sap');
741
- ok( expected == $('#sap').text(), "Check for appending of element" );
742
-
743
- reset();
744
- expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
745
- $([document.getElementById('first'), document.getElementById('yahoo')]).appendTo('#sap');
746
- ok( expected == $('#sap').text(), "Check for appending of array of elements" );
747
-
748
- reset();
749
- expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
750
- $("#first, #yahoo").appendTo('#sap');
751
- ok( expected == $('#sap').text(), "Check for appending of jQuery object" );
752
-
753
- reset();
754
- $('#select1').appendTo('#foo');
755
- t( 'Append select', '#foo select', ['select1'] );
756
- });
757
-
758
- test("prepend(String|Element|Array&lt;Element&gt;|jQuery)", function() {
759
- expect(5);
760
- var defaultText = 'Try them out:'
761
- var result = $('#first').prepend('<b>buga</b>');
762
- ok( result.text() == 'buga' + defaultText, 'Check if text prepending works' );
763
- ok( $('#select3').prepend('<option value="prependTest">Prepend Test</option>').find('option:first-child').attr('value') == 'prependTest', 'Prepending html options to select element');
764
-
765
- reset();
766
- var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
767
- $('#sap').prepend(document.getElementById('first'));
768
- ok( expected == $('#sap').text(), "Check for prepending of element" );
769
-
770
- reset();
771
- expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
772
- $('#sap').prepend([document.getElementById('first'), document.getElementById('yahoo')]);
773
- ok( expected == $('#sap').text(), "Check for prepending of array of elements" );
774
-
775
- reset();
776
- expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
777
- $('#sap').prepend($("#first, #yahoo"));
778
- ok( expected == $('#sap').text(), "Check for prepending of jQuery object" );
779
- });
780
-
781
- test("prependTo(String|Element|Array&lt;Element&gt;|jQuery)", function() {
782
- expect(6);
783
- var defaultText = 'Try them out:'
784
- $('<b>buga</b>').prependTo('#first');
785
- ok( $('#first').text() == 'buga' + defaultText, 'Check if text prepending works' );
786
- ok( $('<option value="prependTest">Prepend Test</option>').prependTo('#select3').parent().find('option:first-child').attr('value') == 'prependTest', 'Prepending html options to select element');
787
-
788
- reset();
789
- var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
790
- $(document.getElementById('first')).prependTo('#sap');
791
- ok( expected == $('#sap').text(), "Check for prepending of element" );
792
-
793
- reset();
794
- expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
795
- $([document.getElementById('yahoo'), document.getElementById('first')]).prependTo('#sap');
796
- ok( expected == $('#sap').text(), "Check for prepending of array of elements" );
797
-
798
- reset();
799
- expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
800
- $("#yahoo, #first").prependTo('#sap');
801
- ok( expected == $('#sap').text(), "Check for prepending of jQuery object" );
802
-
803
- reset();
804
- $('<select id="prependSelect1"></select>').prependTo('form:last');
805
- $('<select id="prependSelect2"><option>Test</option></select>').prependTo('form:last');
806
-
807
- t( "Prepend Select", "#prependSelect1, #prependSelect2", ["prependSelect1", "prependSelect2"] );
808
- });
809
-
810
- test("before(String|Element|Array&lt;Element&gt;|jQuery)", function() {
811
- expect(4);
812
- var expected = 'This is a normal link: bugaYahoo';
813
- $('#yahoo').before('<b>buga</b>');
814
- ok( expected == $('#en').text(), 'Insert String before' );
815
-
816
- reset();
817
- expected = "This is a normal link: Try them out:Yahoo";
818
- $('#yahoo').before(document.getElementById('first'));
819
- ok( expected == $('#en').text(), "Insert element before" );
820
-
821
- reset();
822
- expected = "This is a normal link: Try them out:diveintomarkYahoo";
823
- $('#yahoo').before([document.getElementById('first'), document.getElementById('mark')]);
824
- ok( expected == $('#en').text(), "Insert array of elements before" );
825
-
826
- reset();
827
- expected = "This is a normal link: Try them out:diveintomarkYahoo";
828
- $('#yahoo').before($("#first, #mark"));
829
- ok( expected == $('#en').text(), "Insert jQuery before" );
830
- });
831
-
832
- test("insertBefore(String|Element|Array&lt;Element&gt;|jQuery)", function() {
833
- expect(4);
834
- var expected = 'This is a normal link: bugaYahoo';
835
- $('<b>buga</b>').insertBefore('#yahoo');
836
- ok( expected == $('#en').text(), 'Insert String before' );
837
-
838
- reset();
839
- expected = "This is a normal link: Try them out:Yahoo";
840
- $(document.getElementById('first')).insertBefore('#yahoo');
841
- ok( expected == $('#en').text(), "Insert element before" );
842
-
843
- reset();
844
- expected = "This is a normal link: Try them out:diveintomarkYahoo";
845
- $([document.getElementById('first'), document.getElementById('mark')]).insertBefore('#yahoo');
846
- ok( expected == $('#en').text(), "Insert array of elements before" );
847
-
848
- reset();
849
- expected = "This is a normal link: Try them out:diveintomarkYahoo";
850
- $("#first, #mark").insertBefore('#yahoo');
851
- ok( expected == $('#en').text(), "Insert jQuery before" );
852
- });
853
-
854
- test("after(String|Element|Array&lt;Element&gt;|jQuery)", function() {
855
- expect(4);
856
- var expected = 'This is a normal link: Yahoobuga';
857
- $('#yahoo').after('<b>buga</b>');
858
- ok( expected == $('#en').text(), 'Insert String after' );
859
-
860
- reset();
861
- expected = "This is a normal link: YahooTry them out:";
862
- $('#yahoo').after(document.getElementById('first'));
863
- ok( expected == $('#en').text(), "Insert element after" );
864
-
865
- reset();
866
- expected = "This is a normal link: YahooTry them out:diveintomark";
867
- $('#yahoo').after([document.getElementById('first'), document.getElementById('mark')]);
868
- ok( expected == $('#en').text(), "Insert array of elements after" );
869
-
870
- reset();
871
- expected = "This is a normal link: YahooTry them out:diveintomark";
872
- $('#yahoo').after($("#first, #mark"));
873
- ok( expected == $('#en').text(), "Insert jQuery after" );
874
- });
875
-
876
- test("insertAfter(String|Element|Array&lt;Element&gt;|jQuery)", function() {
877
- expect(4);
878
- var expected = 'This is a normal link: Yahoobuga';
879
- $('<b>buga</b>').insertAfter('#yahoo');
880
- ok( expected == $('#en').text(), 'Insert String after' );
881
-
882
- reset();
883
- expected = "This is a normal link: YahooTry them out:";
884
- $(document.getElementById('first')).insertAfter('#yahoo');
885
- ok( expected == $('#en').text(), "Insert element after" );
886
-
887
- reset();
888
- expected = "This is a normal link: YahooTry them out:diveintomark";
889
- $([document.getElementById('mark'), document.getElementById('first')]).insertAfter('#yahoo');
890
- ok( expected == $('#en').text(), "Insert array of elements after" );
891
-
892
- reset();
893
- expected = "This is a normal link: YahooTry them out:diveintomark";
894
- $("#mark, #first").insertAfter('#yahoo');
895
- ok( expected == $('#en').text(), "Insert jQuery after" );
896
- });
897
-
898
- test("replaceWith(String|Element|Array&lt;Element&gt;|jQuery)", function() {
899
- expect(10);
900
- $('#yahoo').replaceWith('<b id="replace">buga</b>');
901
- ok( $("#replace")[0], 'Replace element with string' );
902
- ok( !$("#yahoo")[0], 'Verify that original element is gone, after string' );
903
-
904
- reset();
905
- $('#yahoo').replaceWith(document.getElementById('first'));
906
- ok( $("#first")[0], 'Replace element with element' );
907
- ok( !$("#yahoo")[0], 'Verify that original element is gone, after element' );
908
-
909
- reset();
910
- $('#yahoo').replaceWith([document.getElementById('first'), document.getElementById('mark')]);
911
- ok( $("#first")[0], 'Replace element with array of elements' );
912
- ok( $("#mark")[0], 'Replace element with array of elements' );
913
- ok( !$("#yahoo")[0], 'Verify that original element is gone, after array of elements' );
914
-
915
- reset();
916
- $('#yahoo').replaceWith($("#first, #mark"));
917
- ok( $("#first")[0], 'Replace element with set of elements' );
918
- ok( $("#mark")[0], 'Replace element with set of elements' );
919
- ok( !$("#yahoo")[0], 'Verify that original element is gone, after set of elements' );
920
- });
921
-
922
- test("replaceAll(String|Element|Array&lt;Element&gt;|jQuery)", function() {
923
- expect(10);
924
- $('<b id="replace">buga</b>').replaceAll("#yahoo");
925
- ok( $("#replace")[0], 'Replace element with string' );
926
- ok( !$("#yahoo")[0], 'Verify that original element is gone, after string' );
927
-
928
- reset();
929
- $(document.getElementById('first')).replaceAll("#yahoo");
930
- ok( $("#first")[0], 'Replace element with element' );
931
- ok( !$("#yahoo")[0], 'Verify that original element is gone, after element' );
932
-
933
- reset();
934
- $([document.getElementById('first'), document.getElementById('mark')]).replaceAll("#yahoo");
935
- ok( $("#first")[0], 'Replace element with array of elements' );
936
- ok( $("#mark")[0], 'Replace element with array of elements' );
937
- ok( !$("#yahoo")[0], 'Verify that original element is gone, after array of elements' );
938
-
939
- reset();
940
- $("#first, #mark").replaceAll("#yahoo");
941
- ok( $("#first")[0], 'Replace element with set of elements' );
942
- ok( $("#mark")[0], 'Replace element with set of elements' );
943
- ok( !$("#yahoo")[0], 'Verify that original element is gone, after set of elements' );
944
- });
945
-
946
- test("end()", function() {
947
- expect(3);
948
- ok( 'Yahoo' == $('#yahoo').parent().end().text(), 'Check for end' );
949
- ok( $('#yahoo').end(), 'Check for end with nothing to end' );
950
-
951
- var x = $('#yahoo');
952
- x.parent();
953
- ok( 'Yahoo' == $('#yahoo').text(), 'Check for non-destructive behaviour' );
954
- });
955
-
956
- test("find(String)", function() {
957
- expect(2);
958
- ok( 'Yahoo' == $('#foo').find('.blogTest').text(), 'Check for find' );
959
-
960
- // using contents will get comments regular, text, and comment nodes
961
- var j = $("#nonnodes").contents();
962
- equals( j.find("div").length, 0, "Check node,textnode,comment to find zero divs" );
963
- });
964
-
965
- test("clone()", function() {
966
- expect(20);
967
- ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Assert text for #en' );
968
- var clone = $('#yahoo').clone();
969
- ok( 'Try them out:Yahoo' == $('#first').append(clone).text(), 'Check for clone' );
970
- ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Reassert text for #en' );
971
-
972
- var cloneTags = [
973
- "<table/>", "<tr/>", "<td/>", "<div/>",
974
- "<button/>", "<ul/>", "<ol/>", "<li/>",
975
- "<input type='checkbox' />", "<select/>", "<option/>", "<textarea/>",
976
- "<tbody/>", "<thead/>", "<tfoot/>", "<iframe/>"
977
- ];
978
- for (var i = 0; i < cloneTags.length; i++) {
979
- var j = $(cloneTags[i]);
980
- equals( j[0].tagName, j.clone()[0].tagName, 'Clone a &lt;' + cloneTags[i].substring(1));
981
- }
982
-
983
- // using contents will get comments regular, text, and comment nodes
984
- var cl = $("#nonnodes").contents().clone();
985
- ok( cl.length >= 2, "Check node,textnode,comment clone works (some browsers delete comments on clone)" );
986
- });
987
-
988
- if (!isLocal) {
989
- test("clone() on XML nodes", function() {
990
- expect(2);
991
- stop();
992
- $.get("data/dashboard.xml", function (xml) {
993
- var root = $(xml.documentElement).clone();
994
- $("tab:first", xml).text("origval");
995
- $("tab:first", root).text("cloneval");
996
- equals($("tab:first", xml).text(), "origval", "Check original XML node was correctly set");
997
- equals($("tab:first", root).text(), "cloneval", "Check cloned XML node was correctly set");
998
- start();
999
- });
1000
- });
1001
- }
1002
-
1003
- test("is(String)", function() {
1004
- expect(26);
1005
- ok( $('#form').is('form'), 'Check for element: A form must be a form' );
1006
- ok( !$('#form').is('div'), 'Check for element: A form is not a div' );
1007
- ok( $('#mark').is('.blog'), 'Check for class: Expected class "blog"' );
1008
- ok( !$('#mark').is('.link'), 'Check for class: Did not expect class "link"' );
1009
- ok( $('#simon').is('.blog.link'), 'Check for multiple classes: Expected classes "blog" and "link"' );
1010
- ok( !$('#simon').is('.blogTest'), 'Check for multiple classes: Expected classes "blog" and "link", but not "blogTest"' );
1011
- ok( $('#en').is('[lang="en"]'), 'Check for attribute: Expected attribute lang to be "en"' );
1012
- ok( !$('#en').is('[lang="de"]'), 'Check for attribute: Expected attribute lang to be "en", not "de"' );
1013
- ok( $('#text1').is('[type="text"]'), 'Check for attribute: Expected attribute type to be "text"' );
1014
- ok( !$('#text1').is('[type="radio"]'), 'Check for attribute: Expected attribute type to be "text", not "radio"' );
1015
- ok( $('#text2').is(':disabled'), 'Check for pseudoclass: Expected to be disabled' );
1016
- ok( !$('#text1').is(':disabled'), 'Check for pseudoclass: Expected not disabled' );
1017
- ok( $('#radio2').is(':checked'), 'Check for pseudoclass: Expected to be checked' );
1018
- ok( !$('#radio1').is(':checked'), 'Check for pseudoclass: Expected not checked' );
1019
- ok( $('#foo').is(':has(p)'), 'Check for child: Expected a child "p" element' );
1020
- ok( !$('#foo').is(':has(ul)'), 'Check for child: Did not expect "ul" element' );
1021
- ok( $('#foo').is(':has(p):has(a):has(code)'), 'Check for childs: Expected "p", "a" and "code" child elements' );
1022
- ok( !$('#foo').is(':has(p):has(a):has(code):has(ol)'), 'Check for childs: Expected "p", "a" and "code" child elements, but no "ol"' );
1023
- ok( !$('#foo').is(0), 'Expected false for an invalid expression - 0' );
1024
- ok( !$('#foo').is(null), 'Expected false for an invalid expression - null' );
1025
- ok( !$('#foo').is(''), 'Expected false for an invalid expression - ""' );
1026
- ok( !$('#foo').is(undefined), 'Expected false for an invalid expression - undefined' );
1027
-
1028
- // test is() with comma-seperated expressions
1029
- ok( $('#en').is('[lang="en"],[lang="de"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
1030
- ok( $('#en').is('[lang="de"],[lang="en"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
1031
- ok( $('#en').is('[lang="en"] , [lang="de"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
1032
- ok( $('#en').is('[lang="de"] , [lang="en"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
1033
- });
1034
-
1035
- test("$.extend(Object, Object)", function() {
1036
- expect(17);
1037
-
1038
- var settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
1039
- options = { xnumber2: 1, xstring2: "x", xxx: "newstring" },
1040
- optionsCopy = { xnumber2: 1, xstring2: "x", xxx: "newstring" },
1041
- merged = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "x", xxx: "newstring" },
1042
- deep1 = { foo: { bar: true } },
1043
- deep1copy = { foo: { bar: true } },
1044
- deep2 = { foo: { baz: true }, foo2: document },
1045
- deep2copy = { foo: { baz: true }, foo2: document },
1046
- deepmerged = { foo: { bar: true, baz: true }, foo2: document };
1047
-
1048
- jQuery.extend(settings, options);
1049
- isObj( settings, merged, "Check if extended: settings must be extended" );
1050
- isObj( options, optionsCopy, "Check if not modified: options must not be modified" );
1051
-
1052
- jQuery.extend(settings, null, options);
1053
- isObj( settings, merged, "Check if extended: settings must be extended" );
1054
- isObj( options, optionsCopy, "Check if not modified: options must not be modified" );
1055
-
1056
- jQuery.extend(true, deep1, deep2);
1057
- isObj( deep1.foo, deepmerged.foo, "Check if foo: settings must be extended" );
1058
- isObj( deep2.foo, deep2copy.foo, "Check if not deep2: options must not be modified" );
1059
- equals( deep1.foo2, document, "Make sure that a deep clone was not attempted on the document" );
1060
-
1061
- var target = {};
1062
- var recursive = { foo:target, bar:5 };
1063
- jQuery.extend(true, target, recursive);
1064
- isObj( target, { bar:5 }, "Check to make sure a recursive obj doesn't go never-ending loop by not copying it over" );
1065
-
1066
- var ret = jQuery.extend(true, { foo: [] }, { foo: [0] } ); // 1907
1067
- ok( ret.foo.length == 1, "Check to make sure a value with coersion 'false' copies over when necessary to fix #1907" );
1068
-
1069
- var ret = jQuery.extend(true, { foo: "1,2,3" }, { foo: [1, 2, 3] } );
1070
- ok( typeof ret.foo != "string", "Check to make sure values equal with coersion (but not actually equal) overwrite correctly" );
1071
-
1072
- var ret = jQuery.extend(true, { foo:"bar" }, { foo:null } );
1073
- ok( typeof ret.foo !== 'undefined', "Make sure a null value doesn't crash with deep extend, for #1908" );
1074
-
1075
- var obj = { foo:null };
1076
- jQuery.extend(true, obj, { foo:"notnull" } );
1077
- equals( obj.foo, "notnull", "Make sure a null value can be overwritten" );
1078
-
1079
- function func() {}
1080
- jQuery.extend(func, { key: "value" } );
1081
- equals( func.key, "value", "Verify a function can be extended" );
1082
-
1083
- var defaults = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
1084
- defaultsCopy = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
1085
- options1 = { xnumber2: 1, xstring2: "x" },
1086
- options1Copy = { xnumber2: 1, xstring2: "x" },
1087
- options2 = { xstring2: "xx", xxx: "newstringx" },
1088
- options2Copy = { xstring2: "xx", xxx: "newstringx" },
1089
- merged2 = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "xx", xxx: "newstringx" };
1090
-
1091
- var settings = jQuery.extend({}, defaults, options1, options2);
1092
- isObj( settings, merged2, "Check if extended: settings must be extended" );
1093
- isObj( defaults, defaultsCopy, "Check if not modified: options1 must not be modified" );
1094
- isObj( options1, options1Copy, "Check if not modified: options1 must not be modified" );
1095
- isObj( options2, options2Copy, "Check if not modified: options2 must not be modified" );
1096
- });
1097
-
1098
- test("val()", function() {
1099
- expect(4);
1100
- ok( $("#text1").val() == "Test", "Check for value of input element" );
1101
- ok( !$("#text1").val() == "", "Check for value of input element" );
1102
- // ticket #1714 this caused a JS error in IE
1103
- ok( $("#first").val() == "", "Check a paragraph element to see if it has a value" );
1104
- ok( $([]).val() === undefined, "Check an empty jQuery object will return undefined from val" );
1105
- });
1106
-
1107
- // test("val(String)", function() {
1108
- // expect(4);
1109
- // document.getElementById('text1').value = "bla";
1110
- // ok( $("#text1").val() == "bla", "Check for modified value of input element" );
1111
- // $("#text1").val('test');
1112
- // ok ( document.getElementById('text1').value == "test", "Check for modified (via val(String)) value of input element" );
1113
- //
1114
- // $("#select1").val("3");
1115
- // ok( $("#select1").val() == "3", "Check for modified (via val(String)) value of select element" );
1116
- //
1117
- // // using contents will get comments regular, text, and comment nodes
1118
- // var j = $("#nonnodes").contents();
1119
- // j.val("asdf");
1120
- // equals( j.val(), "asdf", "Check node,textnode,comment with val()" );
1121
- // j.removeAttr("value");
1122
- // });
1123
-
1124
- var scriptorder = 0;
1125
-
1126
- test("html(String)", function() {
1127
- expect(11);
1128
- var div = $("#main > div");
1129
- div.html("<b>test</b>");
1130
- var pass = true;
1131
- for ( var i = 0; i < div.size(); i++ ) {
1132
- if ( div.get(i).childNodes.length != 1 ) pass = false;
1133
- }
1134
- ok( pass, "Set HTML" );
1135
-
1136
- reset();
1137
- // using contents will get comments regular, text, and comment nodes
1138
- var j = $("#nonnodes").contents();
1139
- j.html("<b>bold</b>");
1140
- equals( j.html().toLowerCase(), "<b>bold</b>", "Check node,textnode,comment with html()" );
1141
-
1142
- $("#main").html("<select/>");
1143
- $("#main select").html("<option>O1</option><option selected='selected'>O2</option><option>O3</option>");
1144
- equals( $("#main select").val(), "O2", "Selected option correct" );
1145
-
1146
- stop();
1147
-
1148
- $("#main").html('<script type="text/javascript">ok( true, "$().html().evalScripts() Evals Scripts Twice in Firefox, see #975" );</script>');
1149
-
1150
- $("#main").html('foo <form><script type="text/javascript">ok( true, "$().html().evalScripts() Evals Scripts Twice in Firefox, see #975" );</script></form>');
1151
-
1152
- // 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
1153
- $("#main").html("<script>ok(scriptorder++ == 0, 'Script is executed in order');ok($('#scriptorder').length == 1,'Execute after html (even though appears before)')<\/script><span id='scriptorder'><script>ok(scriptorder++ == 1, 'Script (nested) is executed in order');ok($('#scriptorder').length == 1,'Execute after html')<\/script></span><script>ok(scriptorder++ == 2, 'Script (unnested) is executed in order');ok($('#scriptorder').length == 1,'Execute after html')<\/script>");
1154
-
1155
- setTimeout( start, 100 );
1156
- });
1157
-
1158
- test("filter()", function() {
1159
- expect(6);
1160
- isSet( $("#form input").filter(":checked").get(), q("radio2", "check1"), "filter(String)" );
1161
- isSet( $("p").filter("#ap, #sndp").get(), q("ap", "sndp"), "filter('String, String')" );
1162
- isSet( $("p").filter("#ap,#sndp").get(), q("ap", "sndp"), "filter('String,String')" );
1163
- isSet( $("p").filter(function() { return !$("a", this).length }).get(), q("sndp", "first"), "filter(Function)" );
1164
-
1165
- // using contents will get comments regular, text, and comment nodes
1166
- var j = $("#nonnodes").contents();
1167
- equals( j.filter("span").length, 1, "Check node,textnode,comment to filter the one span" );
1168
- equals( j.filter("[name]").length, 0, "Check node,textnode,comment to filter the one span" );
1169
- });
1170
-
1171
- test("not()", function() {
1172
- expect(8);
1173
- ok( $("#main > p#ap > a").not("#google").length == 2, "not('selector')" );
1174
- ok( $("#main > p#ap > a").not(document.getElementById("google")).length == 2, "not(DOMElement)" );
1175
- isSet( $("p").not(".result").get(), q("firstp", "ap", "sndp", "en", "sap", "first"), "not('.class')" );
1176
- isSet( $("p").not("#ap, #sndp, .result").get(), q("firstp", "en", "sap", "first"), "not('selector, selector')" );
1177
- isSet( $("p").not($("#ap, #sndp, .result")).get(), q("firstp", "en", "sap", "first"), "not(jQuery)" );
1178
- ok( $("p").not(document.getElementsByTagName("p")).length == 0, "not(Array-like DOM collection)" );
1179
- isSet( $("#form option").not("option.emptyopt:contains('Nothing'),[selected],[value='1']").get(), q("option1c", "option1d", "option2c", "option3d" ), "not('complex selector')");
1180
-
1181
- var selects = $("#form select");
1182
- isSet( selects.not( selects[1] ), q("select1", "select3"), "filter out DOM element");
1183
- });
1184
-
1185
- test("andSelf()", function() {
1186
- expect(4);
1187
- isSet( $("#en").siblings().andSelf().get(), q("sndp", "sap","en"), "Check for siblings and self" );
1188
- isSet( $("#foo").children().andSelf().get(), q("sndp", "en", "sap", "foo"), "Check for children and self" );
1189
- isSet( $("#en, #sndp").parent().andSelf().get(), q("foo","en","sndp"), "Check for parent and self" );
1190
- isSet( $("#groups").parents("p, div").andSelf().get(), q("ap", "main", "groups"), "Check for parents and self" );
1191
- });
1192
-
1193
- test("siblings([String])", function() {
1194
- expect(5);
1195
- isSet( $("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" );
1196
- isSet( $("#sndp").siblings(":has(code)").get(), q("sap"), "Check for filtered siblings (has code child element)" );
1197
- isSet( $("#sndp").siblings(":has(a)").get(), q("en", "sap"), "Check for filtered siblings (has anchor child element)" );
1198
- isSet( $("#foo").siblings("form, b").get(), q("form", "lengthtest", "testForm", "floatTest"), "Check for multiple filters" );
1199
- isSet( $("#en, #sndp").siblings().get(), q("sndp", "sap", "en"), "Check for unique results from siblings" );
1200
- });
1201
-
1202
- test("children([String])", function() {
1203
- expect(3);
1204
- isSet( $("#foo").children().get(), q("sndp", "en", "sap"), "Check for children" );
1205
- isSet( $("#foo").children(":has(code)").get(), q("sndp", "sap"), "Check for filtered children" );
1206
- isSet( $("#foo").children("#en, #sap").get(), q("en", "sap"), "Check for multiple filters" );
1207
- });
1208
-
1209
- test("parent([String])", function() {
1210
- expect(5);
1211
- ok( $("#groups").parent()[0].id == "ap", "Simple parent check" );
1212
- ok( $("#groups").parent("p")[0].id == "ap", "Filtered parent check" );
1213
- ok( $("#groups").parent("div").length == 0, "Filtered parent check, no match" );
1214
- ok( $("#groups").parent("div, p")[0].id == "ap", "Check for multiple filters" );
1215
- isSet( $("#en, #sndp").parent().get(), q("foo"), "Check for unique results from parent" );
1216
- });
1217
-
1218
- test("parents([String])", function() {
1219
- expect(5);
1220
- ok( $("#groups").parents()[0].id == "ap", "Simple parents check" );
1221
- ok( $("#groups").parents("p")[0].id == "ap", "Filtered parents check" );
1222
- ok( $("#groups").parents("div")[0].id == "main", "Filtered parents check2" );
1223
- isSet( $("#groups").parents("p, div").get(), q("ap", "main"), "Check for multiple filters" );
1224
- isSet( $("#en, #sndp").parents().get(), q("foo", "main", "dl", "body", "html"), "Check for unique results from parents" );
1225
- });
1226
-
1227
- test("next([String])", function() {
1228
- expect(4);
1229
- ok( $("#ap").next()[0].id == "foo", "Simple next check" );
1230
- ok( $("#ap").next("div")[0].id == "foo", "Filtered next check" );
1231
- ok( $("#ap").next("p").length == 0, "Filtered next check, no match" );
1232
- ok( $("#ap").next("div, p")[0].id == "foo", "Multiple filters" );
1233
- });
1234
-
1235
- test("prev([String])", function() {
1236
- expect(4);
1237
- ok( $("#foo").prev()[0].id == "ap", "Simple prev check" );
1238
- ok( $("#foo").prev("p")[0].id == "ap", "Filtered prev check" );
1239
- ok( $("#foo").prev("div").length == 0, "Filtered prev check, no match" );
1240
- ok( $("#foo").prev("p, div")[0].id == "ap", "Multiple filters" );
1241
- });
1242
-
1243
- test("show()", function() {
1244
- expect(15);
1245
- var pass = true, div = $("div");
1246
- div.show().each(function(){
1247
- if ( this.style.display == "none" ) pass = false;
1248
- });
1249
- ok( pass, "Show" );
1250
-
1251
- $("#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>');
1252
- var test = {
1253
- "div" : "block",
1254
- "p" : "block",
1255
- "a" : "inline",
1256
- "code" : "inline",
1257
- "pre" : "block",
1258
- "span" : "inline",
1259
- "table" : $.browser.msie ? "block" : "table",
1260
- "thead" : $.browser.msie ? "block" : "table-header-group",
1261
- "tbody" : $.browser.msie ? "block" : "table-row-group",
1262
- "tr" : $.browser.msie ? "block" : "table-row",
1263
- "th" : $.browser.msie ? "block" : "table-cell",
1264
- "td" : $.browser.msie ? "block" : "table-cell",
1265
- "ul" : "block",
1266
- "li" : $.browser.msie ? "block" : "list-item"
1267
- };
1268
-
1269
- $.each(test, function(selector, expected) {
1270
- var elem = $(selector, "#show-tests").show();
1271
- equals( elem.css("display"), expected, "Show using correct display type for " + selector );
1272
- });
1273
- });
1274
-
1275
- test("addClass(String)", function() {
1276
- expect(2);
1277
- var div = $("div");
1278
- div.addClass("test");
1279
- var pass = true;
1280
- for ( var i = 0; i < div.size(); i++ ) {
1281
- if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
1282
- }
1283
- ok( pass, "Add Class" );
1284
-
1285
- // using contents will get regular, text, and comment nodes
1286
- var j = $("#nonnodes").contents();
1287
- j.addClass("asdf");
1288
- ok( j.hasClass("asdf"), "Check node,textnode,comment for addClass" );
1289
- });
1290
-
1291
- test("removeClass(String) - simple", function() {
1292
- expect(4);
1293
- var div = $("div").addClass("test").removeClass("test"),
1294
- pass = true;
1295
- for ( var i = 0; i < div.size(); i++ ) {
1296
- if ( div.get(i).className.indexOf("test") != -1 ) pass = false;
1297
- }
1298
- ok( pass, "Remove Class" );
1299
-
1300
- reset();
1301
- var div = $("div").addClass("test").addClass("foo").addClass("bar");
1302
- div.removeClass("test").removeClass("bar").removeClass("foo");
1303
- var pass = true;
1304
- for ( var i = 0; i < div.size(); i++ ) {
1305
- if ( div.get(i).className.match(/test|bar|foo/) ) pass = false;
1306
- }
1307
- ok( pass, "Remove multiple classes" );
1308
-
1309
- reset();
1310
- var div = $("div:eq(0)").addClass("test").removeClass("");
1311
- ok( div.is('.test'), "Empty string passed to removeClass" );
1312
-
1313
- // using contents will get regular, text, and comment nodes
1314
- var j = $("#nonnodes").contents();
1315
- j.removeClass("asdf");
1316
- ok( !j.hasClass("asdf"), "Check node,textnode,comment for removeClass" );
1317
- });
1318
-
1319
- test("toggleClass(String)", function() {
1320
- expect(3);
1321
- var e = $("#firstp");
1322
- ok( !e.is(".test"), "Assert class not present" );
1323
- e.toggleClass("test");
1324
- ok( e.is(".test"), "Assert class present" );
1325
- e.toggleClass("test");
1326
- ok( !e.is(".test"), "Assert class not present" );
1327
- });
1328
-
1329
- test("removeAttr(String", function() {
1330
- expect(1);
1331
- ok( $('#mark').removeAttr("class")[0].className == "", "remove class" );
1332
- });
1333
-
1334
- test("text(String)", function() {
1335
- expect(4);
1336
- ok( $("#foo").text("<div><b>Hello</b> cruel world!</div>")[0].innerHTML == "&lt;div&gt;&lt;b&gt;Hello&lt;/b&gt; cruel world!&lt;/div&gt;", "Check escaped text" );
1337
-
1338
- // using contents will get comments regular, text, and comment nodes
1339
- var j = $("#nonnodes").contents();
1340
- j.text("hi!");
1341
- equals( $(j[0]).text(), "hi!", "Check node,textnode,comment with text()" );
1342
- equals( j[1].nodeValue, " there ", "Check node,textnode,comment with text()" );
1343
- equals( j[2].nodeType, 8, "Check node,textnode,comment with text()" );
1344
- });
1345
-
1346
- test("$.each(Object,Function)", function() {
1347
- expect(12);
1348
- $.each( [0,1,2], function(i, n){
1349
- ok( i == n, "Check array iteration" );
1350
- });
1351
-
1352
- $.each( [5,6,7], function(i, n){
1353
- ok( i == n - 5, "Check array iteration" );
1354
- });
1355
-
1356
- $.each( { name: "name", lang: "lang" }, function(i, n){
1357
- ok( i == n, "Check object iteration" );
1358
- });
1359
-
1360
- var total = 0;
1361
- jQuery.each([1,2,3], function(i,v){ total += v; });
1362
- ok( total == 6, "Looping over an array" );
1363
- total = 0;
1364
- jQuery.each([1,2,3], function(i,v){ total += v; if ( i == 1 ) return false; });
1365
- ok( total == 3, "Looping over an array, with break" );
1366
- total = 0;
1367
- jQuery.each({"a":1,"b":2,"c":3}, function(i,v){ total += v; });
1368
- ok( total == 6, "Looping over an object" );
1369
- total = 0;
1370
- jQuery.each({"a":3,"b":3,"c":3}, function(i,v){ total += v; return false; });
1371
- ok( total == 3, "Looping over an object, with break" );
1372
- });
1373
-
1374
- test("$.prop", function() {
1375
- expect(2);
1376
- var handle = function() { return this.id };
1377
- ok( $.prop($("#ap")[0], handle) == "ap", "Check with Function argument" );
1378
- ok( $.prop($("#ap")[0], "value") == "value", "Check with value argument" );
1379
- });
1380
-
1381
- test("$.className", function() {
1382
- expect(6);
1383
- var x = $("<p>Hi</p>")[0];
1384
- var c = $.className;
1385
- c.add(x, "hi");
1386
- ok( x.className == "hi", "Check single added class" );
1387
- c.add(x, "foo bar");
1388
- ok( x.className == "hi foo bar", "Check more added classes" );
1389
- c.remove(x);
1390
- ok( x.className == "", "Remove all classes" );
1391
- c.add(x, "hi foo bar");
1392
- c.remove(x, "foo");
1393
- ok( x.className == "hi bar", "Check removal of one class" );
1394
- ok( c.has(x, "hi"), "Check has1" );
1395
- ok( c.has(x, "bar"), "Check has2" );
1396
- });
1397
-
1398
- test("$.data", function() {
1399
- expect(3);
1400
- var div = $("#foo")[0];
1401
- ok( jQuery.data(div, "test") == undefined, "Check for no data exists" );
1402
- jQuery.data(div, "test", "success");
1403
- ok( jQuery.data(div, "test") == "success", "Check for added data" );
1404
- jQuery.data(div, "test", "overwritten");
1405
- ok( jQuery.data(div, "test") == "overwritten", "Check for overwritten data" );
1406
- });
1407
-
1408
- test(".data()", function() {
1409
- expect(16);
1410
- var div = $("#foo");
1411
- ok( div.data("test") == undefined, "Check for no data exists" );
1412
- div.data("test", "success");
1413
- ok( div.data("test") == "success", "Check for added data" );
1414
- div.data("test", "overwritten");
1415
- ok( div.data("test") == "overwritten", "Check for overwritten data" );
1416
-
1417
- var hits = {test:0}, gets = {test:0};
1418
-
1419
- div
1420
- .bind("setData",function(e,key,value){ hits[key] += value; })
1421
- .bind("setData.foo",function(e,key,value){ hits[key] += value; })
1422
- .bind("getData",function(e,key){ gets[key] += 1; })
1423
- .bind("getData.foo",function(e,key){ gets[key] += 3; });
1424
-
1425
- div.data("test.foo", 2);
1426
- ok( div.data("test") == "overwritten", "Check for original data" );
1427
- ok( div.data("test.foo") == 2, "Check for namespaced data" );
1428
- ok( div.data("test.bar") == "overwritten", "Check for unmatched namespace" );
1429
- equals( hits.test, 2, "Check triggered setter functions" );
1430
- equals( gets.test, 5, "Check triggered getter functions" );
1431
-
1432
- hits.test = 0;
1433
- gets.test = 0;
1434
-
1435
- div.data("test", 1);
1436
- ok( div.data("test") == 1, "Check for original data" );
1437
- ok( div.data("test.foo") == 2, "Check for namespaced data" );
1438
- ok( div.data("test.bar") == 1, "Check for unmatched namespace" );
1439
- equals( hits.test, 1, "Check triggered setter functions" );
1440
- equals( gets.test, 5, "Check triggered getter functions" );
1441
-
1442
- hits.test = 0;
1443
- gets.test = 0;
1444
-
1445
- div
1446
- .bind("getData",function(e,key){ return key + "root"; })
1447
- .bind("getData.foo",function(e,key){ return key + "foo"; });
1448
-
1449
- ok( div.data("test") == "testroot", "Check for original data" );
1450
- ok( div.data("test.foo") == "testfoo", "Check for namespaced data" );
1451
- ok( div.data("test.bar") == "testroot", "Check for unmatched namespace" );
1452
- });
1453
-
1454
- test("$.removeData", function() {
1455
- expect(1);
1456
- var div = $("#foo")[0];
1457
- jQuery.data(div, "test", "testing");
1458
- jQuery.removeData(div, "test");
1459
- ok( jQuery.data(div, "test") == undefined, "Check removal of data" );
1460
- });
1461
-
1462
- test(".removeData()", function() {
1463
- expect(6);
1464
- var div = $("#foo");
1465
- div.data("test", "testing");
1466
- div.removeData("test");
1467
- ok( div.data("test") == undefined, "Check removal of data" );
1468
-
1469
- div.data("test", "testing");
1470
- div.data("test.foo", "testing2");
1471
- div.removeData("test.bar");
1472
- ok( div.data("test.foo") == "testing2", "Make sure data is intact" );
1473
- ok( div.data("test") == "testing", "Make sure data is intact" );
1474
-
1475
- div.removeData("test");
1476
- ok( div.data("test.foo") == "testing2", "Make sure data is intact" );
1477
- ok( div.data("test") == undefined, "Make sure data is intact" );
1478
-
1479
- div.removeData("test.foo");
1480
- ok( div.data("test.foo") == undefined, "Make sure data is intact" );
1481
- });
1482
-
1483
- test("remove()", function() {
1484
- expect(6);
1485
- $("#ap").children().remove();
1486
- ok( $("#ap").text().length > 10, "Check text is not removed" );
1487
- ok( $("#ap").children().length == 0, "Check remove" );
1488
-
1489
- reset();
1490
- $("#ap").children().remove("a");
1491
- ok( $("#ap").text().length > 10, "Check text is not removed" );
1492
- ok( $("#ap").children().length == 1, "Check filtered remove" );
1493
-
1494
- // using contents will get comments regular, text, and comment nodes
1495
- equals( $("#nonnodes").contents().length, 3, "Check node,textnode,comment remove works" );
1496
- $("#nonnodes").contents().remove();
1497
- equals( $("#nonnodes").contents().length, 0, "Check node,textnode,comment remove works" );
1498
- });
1499
-
1500
- test("empty()", function() {
1501
- expect(3);
1502
- ok( $("#ap").children().empty().text().length == 0, "Check text is removed" );
1503
- ok( $("#ap").children().length == 4, "Check elements are not removed" );
1504
-
1505
- // using contents will get comments regular, text, and comment nodes
1506
- var j = $("#nonnodes").contents();
1507
- j.empty();
1508
- equals( j.html(), "", "Check node,textnode,comment empty works" );
1509
- });
1510
-
1511
- test("slice()", function() {
1512
- expect(5);
1513
- isSet( $("#ap a").slice(1,2), q("groups"), "slice(1,2)" );
1514
- isSet( $("#ap a").slice(1), q("groups", "anchor1", "mark"), "slice(1)" );
1515
- isSet( $("#ap a").slice(0,3), q("google", "groups", "anchor1"), "slice(0,3)" );
1516
- isSet( $("#ap a").slice(-1), q("mark"), "slice(-1)" );
1517
-
1518
- isSet( $("#ap a").eq(1), q("groups"), "eq(1)" );
1519
- });
1520
-
1521
- test("map()", function() {
1522
- expect(2);
1523
-
1524
- isSet(
1525
- $("#ap").map(function(){
1526
- return $(this).find("a").get();
1527
- }),
1528
- q("google", "groups", "anchor1", "mark"),
1529
- "Array Map"
1530
- );
1531
-
1532
- isSet(
1533
- $("#ap > a").map(function(){
1534
- return this.parentNode;
1535
- }),
1536
- q("ap","ap","ap"),
1537
- "Single Map"
1538
- );
1539
- });
1540
-
1541
- test("contents()", function() {
1542
- expect(12);
1543
- equals( $("#ap").contents().length, 9, "Check element contents" );
1544
- ok( $("#iframe").contents()[0], "Check existance of IFrame document" );
1545
- var ibody = $("#loadediframe").contents()[0].body;
1546
- ok( ibody, "Check existance of IFrame body" );
1547
-
1548
- equals( $("span", ibody).text(), "span text", "Find span in IFrame and check its text" );
1549
-
1550
- $(ibody).append("<div>init text</div>");
1551
- equals( $("div", ibody).length, 2, "Check the original div and the new div are in IFrame" );
1552
-
1553
- equals( $("div:last", ibody).text(), "init text", "Add text to div in IFrame" );
1554
-
1555
- $("div:last", ibody).text("div text");
1556
- equals( $("div:last", ibody).text(), "div text", "Add text to div in IFrame" );
1557
-
1558
- $("div:last", ibody).remove();
1559
- equals( $("div", ibody).length, 1, "Delete the div and check only one div left in IFrame" );
1560
-
1561
- equals( $("div", ibody).text(), "span text", "Make sure the correct div is still left after deletion in IFrame" );
1562
-
1563
- $("<table/>", ibody).append("<tr><td>cell</td></tr>").appendTo(ibody);
1564
- $("table", ibody).remove();
1565
- equals( $("div", ibody).length, 1, "Check for JS error on add and delete of a table in IFrame" );
1566
-
1567
- // using contents will get comments regular, text, and comment nodes
1568
- var c = $("#nonnodes").contents().contents();
1569
- equals( c.length, 1, "Check node,textnode,comment contents is just one" );
1570
- equals( c[0].nodeValue, "hi", "Check node,textnode,comment contents is just the one from span" );
1571
- });