github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

jquery / jquery

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 1,579
    • 150
  • Source
  • Commits
  • Network (150)
  • Graphs
  • Tree: d6d5ed4

click here to add a description

click here to add a homepage

  • Branches (3)
    • master
    • mobile
    • omgrequire
  • Tags (40)
    • 1.4rc1
    • 1.4a2
    • 1.4a1
    • 1.4.1
    • 1.4
    • 1.3rc1
    • 1.3b2
    • 1.3b1
    • 1.3.2
    • 1.3.1rc1
    • 1.3.1
    • 1.3
    • 1.2.6
    • 1.2.5
    • 1.2.4b
    • 1.2.4a
    • 1.2.4
    • 1.2.3b
    • 1.2.3a
    • 1.2.3
    • 1.2.2b2
    • 1.2.2b
    • 1.2.2
    • 1.2.1
    • 1.2
    • 1.1b
    • 1.1a
    • 1.1.4
    • 1.1.3a
    • 1.1.3.1
    • 1.1.3
    • 1.1.2
    • 1.1.1
    • 1.1
    • 1.0a
    • 1.0.4
    • 1.0.3
    • 1.0.2
    • 1.0.1
    • 1.0
  • Comments
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

jQuery JavaScript Library — Read more

  cancel

http://jquery.com/

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

Merge branch 'setterargs'
jeresig (author)
Thu Jan 07 11:26:06 -0800 2010
commit  d6d5ed4c683ceee4d3c64ce75e7349dde8205d50
tree    e377719ab472a02cd24a6db629e83fbd25744ad9
parent  a9665bbe9bb50b060b3f8f2f5facf2e1d1115f37 parent  0e5370b89c0dfe56bf2f02fdd34fd820ecd48254
M src/attributes.js 127 ••••
M src/core.js 2 ••
M src/manipulation.js 26 ••••
M src/offset.js 25 •••••
M test/unit/attributes.js 236 ••••
M test/unit/css.js 146 ••••
M test/unit/manipulation.js 315 ••••
M test/unit/offset.js 39 ••••
0
src/attributes.js
...
12
13
14
 
 
 
 
 
 
 
 
 
15
16
17
18
 
 
 
19
20
21
...
46
47
48
49
50
 
 
 
51
52
53
...
75
76
77
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
79
80
...
142
143
144
145
146
147
148
 
149
150
 
 
151
152
153
154
 
 
 
155
156
157
158
159
160
 
 
161
162
163
164
 
 
 
 
165
166
167
168
 
169
170
171
...
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
...
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 
 
26
27
28
29
30
31
...
56
57
58
 
 
59
60
61
62
63
64
...
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
...
188
189
190
 
 
 
 
191
192
 
193
194
195
 
 
 
196
197
198
199
 
 
 
 
 
200
201
202
203
 
 
204
205
206
207
208
209
210
 
211
212
213
214
...
228
229
230
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
231
232
233
0
@@ -12,10 +12,20 @@ jQuery.fn.extend({
0
     return access( this, name, value, true, jQuery.attr );
0
   },
0
 
0
+  removeAttr: function( name, fn ) {
0
+    return this.each(function(){
0
+      jQuery.attr( this, name, "" );
0
+      if ( this.nodeType === 1 ) {
0
+        this.removeAttribute( name );
0
+      }
0
+    });
0
+  },
0
+
0
   addClass: function( value ) {
0
     if ( jQuery.isFunction(value) ) {
0
-      return this.each(function() {
0
-        jQuery(this).addClass( value.call(this) );
0
+      return this.each(function(i) {
0
+        var self = jQuery(this);
0
+        self.addClass( value.call(this, i, self.attr("class")) );
0
       });
0
     }
0
 
0
@@ -46,8 +56,9 @@ jQuery.fn.extend({
0
 
0
   removeClass: function( value ) {
0
     if ( jQuery.isFunction(value) ) {
0
-      return this.each(function() {
0
-        jQuery(this).removeClass( value.call(this) );
0
+      return this.each(function(i) {
0
+        var self = jQuery(this);
0
+        self.removeClass( value.call(this, i, self.attr("class")) );
0
       });
0
     }
0
 
0
@@ -75,6 +86,41 @@ jQuery.fn.extend({
0
     return this;
0
   },
0
 
0
+  toggleClass: function( value, stateVal ) {
0
+    var type = typeof value, isBool = typeof stateVal === "boolean";
0
+
0
+    if ( jQuery.isFunction( value ) ) {
0
+      return this.each(function(i) {
0
+        var self = jQuery(this);
0
+        self.toggleClass( value.call(this, i, self.attr("class"), stateVal), stateVal );
0
+      });
0
+    }
0
+
0
+    return this.each(function() {
0
+      if ( type === "string" ) {
0
+        // toggle individual class names
0
+        var className, i = 0, self = jQuery(this),
0
+          state = stateVal,
0
+          classNames = value.split( rspace );
0
+
0
+        while ( (className = classNames[ i++ ]) ) {
0
+          // check each className given, space seperated list
0
+          state = isBool ? state : !self.hasClass( className );
0
+          self[ state ? "addClass" : "removeClass" ]( className );
0
+        }
0
+
0
+      } else if ( type === "undefined" || type === "boolean" ) {
0
+        if ( this.className ) {
0
+          // store className if set
0
+          jQuery.data( this, "__className__", this.className );
0
+        }
0
+
0
+        // toggle whole className
0
+        this.className = this.className || value === false ? "" : jQuery.data( this, "__className__" ) || "";
0
+      }
0
+    });
0
+  },
0
+
0
   hasClass: function( selector ) {
0
     var className = " " + selector + " ";
0
     for ( var i = 0, l = this.length; i < l; i++ ) {
0
@@ -142,30 +188,27 @@ jQuery.fn.extend({
0
       return undefined;
0
     }
0
 
0
-    // Typecast once if the value is a number
0
-    if ( typeof value === "number" ) {
0
-      value += "";
0
-    }
0
+    var isFunction = jQuery.isFunction(value);
0
 
0
-    var val = value;
0
+    return this.each(function(i) {
0
+      var self = jQuery(this), val = value;
0
 
0
-    return this.each(function() {
0
-      if ( jQuery.isFunction(value) ) {
0
-        val = value.call(this);
0
+      if ( this.nodeType !== 1 ) {
0
+        return;
0
+      }
0
 
0
-        // Typecast each time if the value is a Function and the appended
0
-        // value is therefore different each time.
0
-        if ( typeof val === "number" ) {
0
-          val += "";
0
-        }
0
+      if ( isFunction ) {
0
+        val = value.call(this, i, self.val());
0
       }
0
 
0
-      if ( this.nodeType !== 1 ) {
0
-        return;
0
+      // Typecast each time if the value is a Function and the appended
0
+      // value is therefore different each time.
0
+      if ( typeof val === "number" ) {
0
+        val += "";
0
       }
0
 
0
       if ( jQuery.isArray(val) && rradiocheck.test( this.type ) ) {
0
-        this.checked = jQuery.inArray( jQuery(this).val(), val ) >= 0;
0
+        this.checked = jQuery.inArray( self.val(), val ) >= 0;
0
 
0
       } else if ( jQuery.nodeName( this, "select" ) ) {
0
         var values = jQuery.makeArray(val);
0
@@ -185,50 +228,6 @@ jQuery.fn.extend({
0
   }
0
 });
0
 
0
-jQuery.each({
0
-  removeAttr: function( name ) {
0
-    jQuery.attr( this, name, "" );
0
-    if ( this.nodeType === 1 ) {
0
-      this.removeAttribute( name );
0
-    }
0
-  },
0
-
0
-  toggleClass: function( classNames, state ) {
0
-    var type = typeof classNames;
0
-
0
-    if ( type === "string" ) {
0
-      // toggle individual class names
0
-      var isBool = typeof state === "boolean", className, i = 0,
0
-        classNames = classNames.split( rspace );
0
-
0
-      while ( (className = classNames[ i++ ]) ) {
0
-        // check each className given, space seperated list
0
-        state = isBool ? state : !jQuery(this).hasClass( className );
0
-        jQuery(this)[ state ? "addClass" : "removeClass" ]( className );
0
-      }
0
-
0
-    } else if ( type === "undefined" || type === "boolean" ) {
0
-      if ( this.className ) {
0
-        // store className if set
0
-        jQuery.data( this, "__className__", this.className );
0
-      }
0
-
0
-      // toggle whole className
0
-      this.className = this.className || classNames === false ? "" : jQuery.data( this, "__className__" ) || "";
0
-    }
0
-  }
0
-}, function( name, fn ) {
0
-  jQuery.fn[ name ] = function( val, state ) {
0
-    if ( jQuery.isFunction( val ) ) {
0
-      return this.each(function() {
0
-        jQuery(this)[ name ]( val.call(this), state );
0
-      });
0
-    }
0
-
0
-    return this.each( fn, arguments );
0
-  };
0
-});
0
-
0
 jQuery.extend({
0
   attrFn: {
0
     val: true,
0
src/core.js
...
775
776
777
778
 
779
780
781
...
775
776
777
 
778
779
780
781
0
@@ -775,7 +775,7 @@ function access( elems, key, value, exec, fn, pass ) {
0
     exec = exec && jQuery.isFunction(value);
0
     
0
     for ( var i = 0; i < length; i++ ) {
0
-      fn( elems[i], key, exec ? value.call( elems[i], i ) : value, pass );
0
+      fn( elems[i], key, exec ? value.call( elems[i], i, fn( elems[i], key ) ) : value, pass );
0
     }
0
     
0
     return elems;
0
src/manipulation.js
...
33
34
35
36
37
 
 
 
38
39
40
...
47
48
49
50
51
 
 
52
53
54
...
172
173
174
175
 
176
177
178
...
195
196
197
 
 
 
 
 
 
 
 
198
199
200
...
228
229
230
231
232
233
 
 
 
 
234
235
236
...
33
34
35
 
 
36
37
38
39
40
41
...
48
49
50
 
 
51
52
53
54
55
...
173
174
175
 
176
177
178
179
...
196
197
198
199
200
201
202
203
204
205
206
207
208
209
...
237
238
239
 
 
 
240
241
242
243
244
245
246
0
@@ -33,8 +33,9 @@ if ( !jQuery.support.htmlSerialize ) {
0
 jQuery.fn.extend({
0
   text: function( text ) {
0
     if ( jQuery.isFunction(text) ) {
0
-      return this.each(function() {
0
-        return jQuery(this).text( text.call(this) );
0
+      return this.each(function(i) {
0
+        var self = jQuery(this);
0
+        return self.text( text.call(this, i, self.text()) );
0
       });
0
     }
0
 
0
@@ -47,8 +48,8 @@ jQuery.fn.extend({
0
 
0
   wrapAll: function( html ) {
0
     if ( jQuery.isFunction( html ) ) {
0
-      return this.each(function() {
0
-        jQuery(this).wrapAll( html.apply(this, arguments) );
0
+      return this.each(function(i) {
0
+        jQuery(this).wrapAll( html.call(this, i) );
0
       });
0
     }
0
 
0
@@ -172,7 +173,7 @@ jQuery.fn.extend({
0
 
0
   html: function( value ) {
0
     if ( value === undefined ) {
0
-      return this[0] ?
0
+      return this[0] && this[0].nodeType === 1 ?
0
         this[0].innerHTML.replace(rinlinejQuery, "") :
0
         null;
0
 
0
@@ -195,6 +196,14 @@ jQuery.fn.extend({
0
         this.empty().append( value );
0
       }
0
 
0
+    } else if ( jQuery.isFunction( value ) ) {
0
+      this.each(function(i){
0
+        var self = jQuery(this), old = self.html();
0
+        self.empty().append(function(){
0
+          return value.call( this, i, old );
0
+        });
0
+      });
0
+
0
     } else {
0
       this.empty().append( value );
0
     }
0
@@ -228,9 +237,10 @@ jQuery.fn.extend({
0
     var results, first, value = args[0], scripts = [];
0
 
0
     if ( jQuery.isFunction(value) ) {
0
-      return this.each(function() {
0
-        args[0] = value.call(this);
0
-        return jQuery(this).domManip( args, table, callback );
0
+      return this.each(function(i) {
0
+        var self = jQuery(this);
0
+        args[0] = value.call(this, i, table ? self.html() : undefined);
0
+        return self.domManip( args, table, callback );
0
       });
0
     }
0
 
0
src/offset.js
...
7
8
9
10
11
 
 
12
13
14
...
33
34
35
36
37
 
 
38
39
40
...
137
138
139
140
 
141
142
143
...
145
146
147
148
149
150
151
152
 
 
 
 
 
 
 
 
 
 
153
154
155
...
7
8
9
 
 
10
11
12
13
14
...
33
34
35
 
 
36
37
38
39
40
...
137
138
139
 
140
141
142
143
...
145
146
147
 
 
 
 
 
148
149
150
151
152
153
154
155
156
157
158
159
160
0
@@ -7,8 +7,8 @@ if ( "getBoundingClientRect" in document.documentElement ) {
0
     }
0
 
0
     if ( options ) { 
0
-      return this.each(function() {
0
-        jQuery.offset.setOffset( this, options );
0
+      return this.each(function( i ) {
0
+        jQuery.offset.setOffset( this, options, i );
0
       });
0
     }
0
 
0
@@ -33,8 +33,8 @@ if ( "getBoundingClientRect" in document.documentElement ) {
0
     }
0
 
0
     if ( options ) { 
0
-      return this.each(function() {
0
-        jQuery.offset.setOffset( this, options );
0
+      return this.each(function( i ) {
0
+        jQuery.offset.setOffset( this, options, i );
0
       });
0
     }
0
 
0
@@ -137,7 +137,7 @@ jQuery.offset = {
0
     return { top: top, left: left };
0
   },
0
   
0
-  setOffset: function( elem, options ) {
0
+  setOffset: function( elem, options, i ) {
0
     // set position first, in-case top/left are set even on static elem
0
     if ( /static/.test( jQuery.curCSS( elem, "position" ) ) ) {
0
       elem.style.position = "relative";
0
@@ -145,11 +145,16 @@ jQuery.offset = {
0
     var curElem   = jQuery( elem ),
0
       curOffset = curElem.offset(),
0
       curTop    = parseInt( jQuery.curCSS( elem, "top",  true ), 10 ) || 0,
0
-      curLeft   = parseInt( jQuery.curCSS( elem, "left", true ), 10)  || 0,
0
-      props     = {
0
-        top:  (options.top  - curOffset.top)  + curTop,
0
-        left: (options.left - curOffset.left) + curLeft
0
-      };
0
+      curLeft   = parseInt( jQuery.curCSS( elem, "left", true ), 10 ) || 0;
0
+
0
+    if ( jQuery.isFunction( options ) ) {
0
+      options = options.call( elem, i, curOffset );
0
+    }
0
+
0
+    var props = {
0
+      top:  (options.top  - curOffset.top)  + curTop,
0
+      left: (options.left - curOffset.left) + curLeft
0
+    };
0
     
0
     if ( "using" in options ) {
0
       options.using.call( elem, props );
0
test/unit/attributes.js
...
292
293
294
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
295
296
297
...
316
317
318
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
319
320
321
...
357
358
359
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
360
361
362
...
417
418
419
420
421
422
423
 
 
424
425
426
427
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
428
429
430
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
431
432
433
...
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
...
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
...
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
...
595
596
597
 
 
 
 
598
599
600
 
 
 
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
 
 
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
0
@@ -292,6 +292,148 @@ test("attr('tabindex', value)", function() {
0
   equals(element.attr('tabindex'), -1, 'set negative tabindex');
0
 });
0
 
0
+test("removeAttr(String)", function() {
0
+  expect(1);
0
+  equals( jQuery('#mark').removeAttr( "class" )[0].className, "", "remove class" );
0
+});
0
+
0
+test("val()", function() {
0
+  expect(17);
0
+
0
+  document.getElementById('text1').value = "bla";
0
+  equals( jQuery("#text1").val(), "bla", "Check for modified value of input element" );
0
+
0
+  reset();
0
+
0
+  equals( jQuery("#text1").val(), "Test", "Check for value of input element" );
0
+  // ticket #1714 this caused a JS error in IE
0
+  equals( jQuery("#first").val(), "", "Check a paragraph element to see if it has a value" );
0
+  ok( jQuery([]).val() === undefined, "Check an empty jQuery object will return undefined from val" );
0
+
0
+  equals( jQuery('#select2').val(), '3', 'Call val() on a single="single" select' );
0
+
0
+  same( jQuery('#select3').val(), ['1', '2'], 'Call val() on a multiple="multiple" select' );
0
+
0
+  equals( jQuery('#option3c').val(), '2', 'Call val() on a option element with value' );
0
+
0
+  equals( jQuery('#option3a').val(), '', 'Call val() on a option element with empty value' );
0
+
0
+  equals( jQuery('#option3e').val(), 'no value', 'Call val() on a option element with no value attribute' );
0
+
0
+  equals( jQuery('#option3a').val(), '', 'Call val() on a option element with no value attribute' );
0
+
0
+  jQuery('#select3').val("");
0
+  same( jQuery('#select3').val(), [''], 'Call val() on a multiple="multiple" select' );
0
+
0
+  var checks = jQuery("<input type='checkbox' name='test' value='1'/>").appendTo("#form")
0
+    .add( jQuery("<input type='checkbox' name='test' value='2'/>").appendTo("#form") )
0
+    .add( jQuery("<input type='checkbox' name='test' value=''/>").appendTo("#form") )
0
+    .add( jQuery("<input type='checkbox' name='test'/>").appendTo("#form") );
0
+
0
+  same( checks.serialize(), "", "Get unchecked values." );
0
+
0
+  equals( checks.eq(3).val(), "on", "Make sure a value of 'on' is provided if none is specified." );
0
+
0
+  checks.val([ "2" ]);
0
+  same( checks.serialize(), "test=2", "Get a single checked value." );
0
+
0
+  checks.val([ "1", "" ]);
0
+  same( checks.serialize(), "test=1&test=", "Get multiple checked values." );
0
+
0
+  checks.val([ "", "2" ]);
0
+  same( checks.serialize(), "test=2&test=", "Get multiple checked values." );
0
+
0
+  checks.val([ "1", "on" ]);
0
+  same( checks.serialize(), "test=1&test=on", "Get multiple checked values." );
0
+
0
+  checks.remove();
0
+});
0
+
0
+var testVal = function(valueObj) {
0
+  expect(6);
0
+
0
+  jQuery("#text1").val(valueObj( 'test' ));
0
+  equals( document.getElementById('text1').value, "test", "Check for modified (via val(String)) value of input element" );
0
+
0
+  jQuery("#text1").val(valueObj( 67 ));
0
+  equals( document.getElementById('text1').value, "67", "Check for modified (via val(Number)) value of input element" );
0
+
0
+  jQuery("#select1").val(valueObj( "3" ));
0
+  equals( jQuery("#select1").val(), "3", "Check for modified (via val(String)) value of select element" );
0
+
0
+  jQuery("#select1").val(valueObj( 2 ));
0
+  equals( jQuery("#select1").val(), "2", "Check for modified (via val(Number)) value of select element" );
0
+
0
+  jQuery("#select1").append("<option value='4'>four</option>");
0
+  jQuery("#select1").val(valueObj( 4 ));
0
+  equals( jQuery("#select1").val(), "4", "Should be possible to set the val() to a newly created option" );
0
+
0
+  // using contents will get comments regular, text, and comment nodes
0
+  var j = jQuery("#nonnodes").contents();
0
+  j.val(valueObj( "asdf" ));
0
+  equals( j.val(), "asdf", "Check node,textnode,comment with val()" );
0
+  j.removeAttr("value");
0
+}
0
+
0
+test("val(String/Number)", function() {
0
+  testVal(bareObj);
0
+});
0
+
0
+test("val(Function)", function() {
0
+  testVal(functionReturningObj);
0
+})
0
+
0
+test("val(Function) with incoming value", function() {
0
+  expect(10);
0
+
0
+  var oldVal = jQuery("#text1").val();
0
+
0
+  jQuery("#text1").val(function(i, val) {
0
+    equals( val, oldVal, "Make sure the incoming value is correct." );
0
+    return "test";
0
+  });
0
+
0
+  equals( document.getElementById('text1').value, "test", "Check for modified (via val(String)) value of input element" );
0
+
0
+  oldVal = jQuery("#text1").val();
0
+
0
+  jQuery("#text1").val(function(i, val) {
0
+    equals( val, oldVal, "Make sure the incoming value is correct." );
0
+    return 67;
0
+  });
0
+
0
+  equals( document.getElementById('text1').value, "67", "Check for modified (via val(Number)) value of input element" );
0
+
0
+  oldVal = jQuery("#select1").val();
0
+
0
+  jQuery("#select1").val(function(i, val) {
0
+    equals( val, oldVal, "Make sure the incoming value is correct." );
0
+    return "3";
0
+  });
0
+
0
+  equals( jQuery("#select1").val(), "3", "Check for modified (via val(String)) value of select element" );
0
+
0
+  oldVal = jQuery("#select1").val();
0
+
0
+  jQuery("#select1").val(function(i, val) {
0
+    equals( val, oldVal, "Make sure the incoming value is correct." );
0
+    return 2;
0
+  });
0
+
0
+  equals( jQuery("#select1").val(), "2", "Check for modified (via val(Number)) value of select element" );
0
+
0
+  jQuery("#select1").append("<option value='4'>four</option>");
0
+
0
+  oldVal = jQuery("#select1").val();
0
+
0
+  jQuery("#select1").val(function(i, val) {
0
+    equals( val, oldVal, "Make sure the incoming value is correct." );
0
+    return 4;
0
+  });
0
+
0
+  equals( jQuery("#select1").val(), "4", "Should be possible to set the val() to a newly created option" );
0
+});
0
+
0
 var testAddClass = function(valueObj) {
0
   expect(2);
0
   var div = jQuery("div");
0
@@ -316,6 +458,25 @@ test("addClass(Function)", function() {
0
   testAddClass(functionReturningObj);
0
 });
0
 
0
+test("addClass(Function) with incoming value", function() {
0
+  expect(39);
0
+
0
+  var div = jQuery("div"), old = div.map(function(){
0
+    return jQuery(this).attr("class");
0
+  });
0
+
0
+  div.addClass(function(i, val) {
0
+    equals( val, old[i], "Make sure the incoming value is correct." );
0
+    return "test";
0
+  });
0
+
0
+  var pass = true;
0
+  for ( var i = 0; i < div.size(); i++ ) {
0
+   if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
0
+  }
0
+  ok( pass, "Add Class" );
0
+});
0
+
0
 var testRemoveClass = function(valueObj) {
0
   expect(5);
0
 
0
@@ -357,6 +518,23 @@ test("removeClass(Function) - simple", function() {
0
   testRemoveClass(functionReturningObj);
0
 });
0
 
0
+test("removeClass(Function) with incoming value", function() {
0
+  expect(39);
0
+
0
+  var $divs = jQuery('div').addClass("test"), old = $divs.map(function(){
0
+    return jQuery(this).attr("class");
0
+  });
0
+
0
+  $divs.removeClass(function(i, val) {
0
+    equals( val, old[i], "Make sure the incoming value is correct." );
0
+    return "test";
0
+  });
0
+
0
+  ok( !$divs.is('.test'), "Remove Class" );
0
+
0
+  reset();  
0
+});
0
+
0
 var testToggleClass = function(valueObj) {
0
   expect(17);
0
 
0
@@ -417,17 +595,57 @@ test("toggleClass(Function[, boolean])", function() {
0
   testToggleClass(functionReturningObj);
0
 });
0
 
0
-var testRemoveAttr = function(valueObj) {
0
-  expect(1);
0
-  equals( jQuery('#mark').removeAttr( valueObj("class") )[0].className, "", "remove class" );
0
-};
0
+test("toggleClass(Fucntion[, boolean]) with incoming value", function() {
0
+  expect(14);
0
 
0
-test("removeAttr(String)", function() {
0
-  testRemoveAttr(bareObj);
0
-});
0
+  var e = jQuery("#firstp"), old = e.attr("class");
0
+  ok( !e.is(".test"), "Assert class not present" );
0
+  
0
+  e.toggleClass(function(i, val) {
0
+    equals( val, old, "Make sure the incoming value is correct." );
0
+    return "test";
0
+  });
0
+  ok( e.is(".test"), "Assert class present" );
0
+  
0
+  old = e.attr("class");
0
+  
0
+  e.toggleClass(function(i, val) {
0
+    equals( val, old, "Make sure the incoming value is correct." );
0
+    return "test";
0
+  });
0
+  ok( !e.is(".test"), "Assert class not present" );
0
+  
0
+  old = e.attr("class");
0
 
0
-test("removeAttr(Function)", function() {
0
-  testRemoveAttr(functionReturningObj);
0
+  // class name with a boolean
0
+  e.toggleClass(function(i, val, state) {
0
+    equals( val, old, "Make sure the incoming value is correct." );
0
+    equals( state, false, "Make sure that the state is passed in." );
0
+    return "test";
0
+  }, false );
0
+  ok( !e.is(".test"), "Assert class not present" );
0
+  
0
+  old = e.attr("class");
0
+  
0
+  e.toggleClass(function(i, val, state) {
0
+    equals( val, old, "Make sure the incoming value is correct." );
0
+    equals( state, true, "Make sure that the state is passed in." );
0
+    return "test";
0
+  }, true );
0
+  ok( e.is(".test"), "Assert class present" );
0
+  
0
+  old = e.attr("class");
0
+  
0
+  e.toggleClass(function(i, val, state) {
0
+    equals( val, old, "Make sure the incoming value is correct." );
0
+    equals( state, false, "Make sure that the state is passed in." );
0
+    return "test";
0
+  }, false );
0
+  ok( !e.is(".test"), "Assert class not present" );
0
+
0
+  // Cleanup
0
+  e.removeClass("test");
0
+  e.removeData('__className__');
0
 });
0
 
0
 test("addClass, removeClass, hasClass", function() {
0
test/unit/css.js
...
120
121
122
123
124
 
125
126
 
127
128
129
130
131
 
 
 
 
132
133
 
134
135
136
137
138
139
 
 
 
 
 
140
141
 
 
 
 
 
 
 
 
 
 
 
 
 
 
142
143
144
145
146
147
148
 
 
 
 
 
 
 
 
 
 
 
 
 
 
149
150
151
152
 
 
 
 
 
 
 
 
 
 
153
154
155
156
157
 
158
159
 
 
 
 
 
 
 
 
160
161
162
163
164
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
165
166
 
 
 
 
 
 
167
168
169
170
171
172
 
 
 
 
 
173
174
 
175
176
177
178
179
180
181
 
 
 
 
 
 
182
183
184
185
 
186
187
188
...
120
121
122
 
 
123
124
 
125
126
 
 
 
 
127
128
129
130
131
 
132
133
 
 
 
 
 
134
135
136
137
138
139
 
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
 
 
 
 
 
 
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
 
 
 
170
171
172
173
174
175
176
177
178
179
180
181
182
 
 
183
184
 
185
186
187
188
189
190
191
192
193
 
 
 
 
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
 
217
218
219
220
221
222
223
 
 
 
 
 
224
225
226
227
228
229
 
230
231
 
 
 
 
 
 
232
233
234
235
236
237
238
 
 
 
239
240
241
242
0
@@ -120,69 +120,123 @@ if(jQuery.browser.msie) {
0
 }
0
 
0
 test("css(String, Function)", function() {
0
-  try { 
0
-    expect(3);
0
+  expect(3);
0
     
0
-    var sizes = ["10px", "20px", "30px"];
0
+  var sizes = ["10px", "20px", "30px"];
0
   
0
-    jQuery("<div id='cssFunctionTest'><div class='cssFunction'></div>" + 
0
-           "<div class='cssFunction'></div>" + 
0
-           "<div class='cssFunction'></div></div>")
0
-      .appendTo("body");
0
+  jQuery("<div id='cssFunctionTest'><div class='cssFunction'></div>" + 
0
+         "<div class='cssFunction'></div>" + 
0
+         "<div class='cssFunction'></div></div>")
0
+    .appendTo("body");
0
   
0
-    var index = 0;
0
+  var index = 0;
0
   
0
-    jQuery("#cssFunctionTest div").css("font-size", function() {
0
-      var size = sizes[index];
0
-      index++;
0
-      return size;
0
-    });
0
+  jQuery("#cssFunctionTest div").css("font-size", function() {
0
+    var size = sizes[index];
0
+    index++;
0
+    return size;
0
+  });
0
     
0
-    index = 0;
0
+  index = 0;
0
+  
0
+  jQuery("#cssFunctionTest div").each(function() {
0
+    var computedSize = jQuery(this).css("font-size")
0
+    var expectedSize = sizes[index]
0
+    equals( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize );
0
+    index++;
0
+  });
0
+
0
+  jQuery("#cssFunctionTest").remove();
0
+});
0
+
0
+test("css(String, Function) with incoming value", function() {
0
+  expect(3);
0
     
0
-    jQuery("#cssFunctionTest div").each(function() {
0
-      var computedSize = jQuery(this).css("font-size")
0
-      var expectedSize = sizes[index]
0
-      equals( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize );
0
-      index++;
0
-    });
0
+  var sizes = ["10px", "20px", "30px"];
0
+  
0
+  jQuery("<div id='cssFunctionTest'><div class='cssFunction'></div>" + 
0
+         "<div class='cssFunction'></div>" + 
0
+         "<div class='cssFunction'></div></div>")
0
+    .appendTo("body");
0
+  
0
+  var index = 0;
0
+  
0
+  jQuery("#cssFunctionTest div").css("font-size", function() {
0
+    var size = sizes[index];
0
+    index++;
0
+    return size;
0
+  });
0
     
0
-  } finally {
0
-    jQuery("#cssFunctionTest").remove();
0
-  }
0
+  index = 0;
0
+  
0
+  jQuery("#cssFunctionTest div").css("font-size", function(i, computedSize) {
0
+    var expectedSize = sizes[index]
0
+    equals( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize );
0
+    index++;
0
+    return computedSize;
0
+  });
0
+
0
+  jQuery("#cssFunctionTest").remove();
0
 });
0
 
0
 test("css(Object) where values are Functions", function() {
0
-  try { 
0
-    expect(3);
0
+  expect(3);
0
     
0
-    var sizes = ["10px", "20px", "30px"];
0
+  var sizes = ["10px", "20px", "30px"];
0
+  
0
+  jQuery("<div id='cssFunctionTest'><div class='cssFunction'></div>" + 
0
+         "<div class='cssFunction'></div>" + 
0
+         "<div class='cssFunction'></div></div>")
0
+    .appendTo("body");
0
+
0
+  var index = 0;
0
   
0
-    jQuery("<div id='cssFunctionTest'><div class='cssFunction'></div>" + 
0
-           "<div class='cssFunction'></div>" + 
0
-           "<div class='cssFunction'></div></div>")
0
-      .appendTo("body");
0
+  jQuery("#cssFunctionTest div").css({fontSize: function() {
0
+    var size = sizes[index];
0
+    index++;
0
+    return size;
0
+  }});
0
+    
0
+  index = 0;
0
+    
0
+  jQuery("#cssFunctionTest div").each(function() {
0
+    var computedSize = jQuery(this).css("font-size")
0
+    var expectedSize = sizes[index]
0
+    equals( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize );
0
+    index++;
0
+  });
0
+    
0
+  jQuery("#cssFunctionTest").remove();
0
+});
0
+
0
+test("css(Object) where values are Functions with incoming values", function() {
0
+  expect(3);
0
+    
0
+  var sizes = ["10px", "20px", "30px"];
0
   
0
-    var index = 0;
0
+  jQuery("<div id='cssFunctionTest'><div class='cssFunction'></div>" + 
0
+         "<div class='cssFunction'></div>" + 
0
+         "<div class='cssFunction'></div></div>")
0
+    .appendTo("body");
0
+
0
+  var index = 0;
0
   
0
-    jQuery("#cssFunctionTest div").css({fontSize: function() {
0
-      var size = sizes[index];
0
-      index++;
0
-      return size;
0
-    }});
0
+  jQuery("#cssFunctionTest div").css({fontSize: function() {
0
+    var size = sizes[index];
0
+    index++;
0
+    return size;
0
+  }});
0
     
0
-    index = 0;
0
+  index = 0;
0
     
0
-    jQuery("#cssFunctionTest div").each(function() {
0
-      var computedSize = jQuery(this).css("font-size")
0
-      var expectedSize = sizes[index]
0
-      equals( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize );
0
-      index++;
0
-    });
0
+  jQuery("#cssFunctionTest div").css({"font-size": function(i, computedSize) {
0
+    var expectedSize = sizes[index]
0
+    equals( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize );
0
+    index++;
0
+    return computedSize;
0
+  }});
0
     
0
-  } finally {
0
-    jQuery("#cssFunctionTest").remove();
0
-  }
0
+  jQuery("#cssFunctionTest").remove();
0
 });
0
 
0
 test("jQuery.css(elem, 'height') doesn't clear radio buttons (bug #1095)", function () {
0
test/unit/manipulation.js
...
12
13
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
16
17
...
133
134
135
136
 
137
138
139
...
158
159
160
161
162
163
164
165
166
167
...
256
257
258
259
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
260
261
262
...
330
331
332
333
 
334
335
336
...
338
339
340
341
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
342
343
344
...
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
...
768
769
770
771
772
773
774
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
775
 
776
777
778
779
780
781
782
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
783
784
785
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
786
787
788
789
790
791
792
793
794
...
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
...
169
170
171
 
172
173
174
175
...
194
195
196
 
 
 
 
197
198
199
...
288
289
290
 
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
...
423
424
425
 
426
427
428
429
...
431
432
433
 
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
...
762
763
764
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
765
766
767
...
826
827
828
 
 
 
 
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
 
 
 
 
 
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
 
 
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
 
 
 
 
889
890
891
0
@@ -12,6 +12,42 @@ test("text()", function() {
0
   equals( jQuery(document.createTextNode("foo")).text(), "foo", "Text node was retreived from .text()." );
0
 });
0
 
0
+var testText = function(valueObj) {
0
+  expect(4);
0
+  var val = valueObj("<div><b>Hello</b> cruel world!</div>");
0
+  equals( jQuery("#foo").text(val)[0].innerHTML.replace(/>/g, "&gt;"), "&lt;div&gt;&lt;b&gt;Hello&lt;/b&gt; cruel world!&lt;/div&gt;", "Check escaped text" );
0
+
0
+  // using contents will get comments regular, text, and comment nodes
0
+  var j = jQuery("#nonnodes").contents();
0
+  j.text(valueObj("hi!"));
0
+  equals( jQuery(j[0]).text(), "hi!", "Check node,textnode,comment with text()" );
0
+  equals( j[1].nodeValue, " there ", "Check node,textnode,comment with text()" );
0
+  equals( j[2].nodeType, 8, "Check node,textnode,comment with text()" );
0
+}
0
+
0
+test("text(String)", function() {
0
+  testText(bareObj)
0
+});
0
+
0
+test("text(Function)", function() {
0
+  testText(functionReturningObj);
0
+});
0
+
0
+test("text(Function) with incoming value", function() {
0
+  expect(2);
0
+  
0
+  var old = "This link has class=\"blog\": Simon Willison's Weblog";
0
+  
0
+  jQuery('#sap').text(function(i, val) {
0
+    equals( val, old, "Make sure the incoming value is correct." );
0
+    return "foobar";
0
+  });
0
+  
0
+  equals( jQuery("#sap").text(), "foobar", 'Check for merged text of more then one element.' );
0
+  
0
+  reset();
0
+});
0
+
0
 var testWrap = function(val) {
0
   expect(18);
0
   var defaultText = 'Try them out:'
0
@@ -133,7 +169,7 @@ test("wrapInner(String|Element)", function() {
0
 //  testWrapInner(functionReturningObj)
0
 // })
0
 
0
-var testUnwrap = function() {
0
+test("unwrap()", function() {
0
   expect(9);
0
 
0
   jQuery("body").append('  <div id="unwrap" style="display: none;"> <div id="unwrap1"> <span class="unwrap">a</span> <span class="unwrap">b</span> </div> <div id="unwrap2"> <span class="unwrap">c</span> <span class="unwrap">d</span> </div> <div id="unwrap3"> <b><span class="unwrap unwrap3">e</span></b> <b><span class="unwrap unwrap3">f</span></b> </div> </div>');
0
@@ -158,10 +194,6 @@ var testUnwrap = function() {
0
   same( jQuery('body > span.unwrap').get(), abcdef, 'body contains 6 .unwrap child spans' );
0
 
0
   jQuery('body > span.unwrap').remove();
0
-}
0
-
0
-test("unwrap()", function() {
0
-  testUnwrap();
0
 });
0
 
0
 var testAppend = function(valueObj) {
0
@@ -256,7 +288,68 @@ test("append(String|Element|Array&lt;Element&gt;|jQuery)", function() {
0
 
0
 test("append(Function)", function() {
0
   testAppend(functionReturningObj);
0
-})
0
+});
0
+
0
+test("append(Function) with incoming value", function() {
0
+  expect(12);
0
+  
0
+  var defaultText = 'Try them out:', old = jQuery("#first").html();
0
+  
0
+  var result = jQuery('#first').append(function(i, val){
0
+    equals( val, old, "Make sure the incoming value is correct." );
0
+    return '<b>buga</b>';
0
+  });
0
+  equals( result.text(), defaultText + 'buga', 'Check if text appending works' );
0
+  
0
+  var select = jQuery('#select3');
0
+  old = select.html();
0
+  
0
+  equals( select.append(function(i, val){
0
+    equals( val, old, "Make sure the incoming value is correct." );
0
+    return '<option value="appendTest">Append Test</option>';
0
+  }).find('option:last-child').attr('value'), 'appendTest', 'Appending html options to select element');
0
+
0
+  reset();
0
+  var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
0
+  old = jQuery("#sap").html();
0
+  
0
+  jQuery('#sap').append(function(i, val){
0
+    equals( val, old, "Make sure the incoming value is correct." );
0
+    return document.getElementById('first');
0
+  });
0
+  equals( expected, jQuery('#sap').text(), "Check for appending of element" );
0
+
0
+  reset();
0
+  expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
0
+  old = jQuery("#sap").html();
0
+  
0
+  jQuery('#sap').append(function(i, val){
0
+    equals( val, old, "Make sure the incoming value is correct." );
0
+    return [document.getElementById('first'), document.getElementById('yahoo')];
0
+  });
0
+  equals( expected, jQuery('#sap').text(), "Check for appending of array of elements" );
0
+
0
+  reset();
0
+  expected = "This link has class=\"blog\": Simon Willison's WeblogYahooTry them out:";
0
+  old = jQuery("#sap").html();
0
+  
0
+  jQuery('#sap').append(function(i, val){
0
+    equals( val, old, "Make sure the incoming value is correct." );
0
+    return jQuery("#first, #yahoo");
0
+  });
0
+  equals( expected, jQuery('#sap').text(), "Check for appending of jQuery object" );
0
+
0
+  reset();
0
+  old = jQuery("#sap").html();
0
+  
0
+  jQuery("#sap").append(function(i, val){
0
+    equals( val, old, "Make sure the incoming value is correct." );
0
+    return 5;
0
+  });
0
+  ok( jQuery("#sap")[0].innerHTML.match( /5$/ ), "Check for appending a number" );  
0
+  
0
+  reset();
0
+});
0
 
0
 test("appendTo(String|Element|Array&lt;Element&gt;|jQuery)", function() {
0
   expect(12);
0
@@ -330,7 +423,7 @@ var testPrepend = function(val) {
0
   expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog";
0
   jQuery('#sap').prepend(val( jQuery("#first, #yahoo") ));
0
   equals( expected, jQuery('#sap').text(), "Check for prepending of jQuery object" );
0
-}
0
+};
0
 
0
 test("prepend(String|Element|Array&lt;Element&gt;|jQuery)", function() {
0
   testPrepend(bareObj);
0
@@ -338,7 +431,58 @@ test("prepend(String|Element|Array&lt;Element&gt;|jQuery)", function() {
0
 
0
 test("prepend(Function)", function() {
0
   testPrepend(functionReturningObj);
0
-})
0
+});
0
+
0
+test("prepend(Function) with incoming value", function() {
0
+  expect(10);
0
+  
0
+  var defaultText = 'Try them out:', old = jQuery('#first').html();
0
+  var result = jQuery('#first').prepend(function(i, val) {
0
+    equals( val, old, "Make sure the incoming value is correct." );
0
+    return '<b>buga</b>';
0
+  });
0
+  equals( result.text(), 'buga' + defaultText, 'Check if text prepending works' );
0
+  
0
+  old = jQuery("#select3").html();
0
+  
0
+  equals( jQuery('#select3').prepend(function(i, val) {
0
+    equals( val, old, "Make sure the incoming value is correct." );
0
+    return '<option value="prependTest">Prepend Test</option>';
0
+  }).find('option:first-child').attr('value'), 'prependTest', 'Prepending html options to select element');
0
+
0
+  reset();
0
+  var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
0
+  old = jQuery('#sap').html();
0
+  
0
+  jQuery('#sap').prepend(function(i, val) {
0
+    equals( val, old, "Make sure the incoming value is correct." );
0
+    return document.getElementById('first');
0
+  });
0
+  
0
+  equals( expected, jQuery('#sap').text(), "Check for prepending of element" );
0
+
0
+  reset();
0
+  expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
0
+  old = jQuery('#sap').html();
0
+  
0
+  jQuery('#sap').prepend(function(i, val) {
0
+    equals( val, old, "Make sure the incoming value is correct." );
0
+    return [document.getElementById('first'), document.getElementById('yahoo')];
0
+  });
0
+  
0
+  equals( expected, jQuery('#sap').text(), "Check for prepending of array of elements" );
0
+
0
+  reset();
0
+  expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog";
0
+  old = jQuery('#sap').html();
0
+  
0
+  jQuery('#sap').prepend(function(i, val) {
0
+    equals( val, old, "Make sure the incoming value is correct." );
0
+    return jQuery("#first, #yahoo");
0
+  });
0
+  
0
+  equals( expected, jQuery('#sap').text(), "Check for prepending of jQuery object" );  
0
+});
0
 
0
 test("prependTo(String|Element|Array&lt;Element&gt;|jQuery)", function() {
0
   expect(6);
0
@@ -618,92 +762,6 @@ test("clone() on XML nodes", function() {
0
 });
0
 }
0
 
0
-test("val()", function() {
0
-  expect(17);
0
-
0
-  document.getElementById('text1').value = "bla";
0
-  equals( jQuery("#text1").val(), "bla", "Check for modified value of input element" );
0
-
0
-  reset();
0
-
0
-  equals( jQuery("#text1").val(), "Test", "Check for value of input element" );
0
-  // ticket #1714 this caused a JS error in IE
0
-  equals( jQuery("#first").val(), "", "Check a paragraph element to see if it has a value" );
0
-  ok( jQuery([]).val() === undefined, "Check an empty jQuery object will return undefined from val" );
0
-
0
-  equals( jQuery('#select2').val(), '3', 'Call val() on a single="single" select' );
0
-
0
-  same( jQuery('#select3').val(), ['1', '2'], 'Call val() on a multiple="multiple" select' );
0
-
0
-  equals( jQuery('#option3c').val(), '2', 'Call val() on a option element with value' );
0
-
0
-  equals( jQuery('#option3a').val(), '', 'Call val() on a option element with empty value' );
0
-
0
-  equals( jQuery('#option3e').val(), 'no value', 'Call val() on a option element with no value attribute' );
0
-
0
-  equals( jQuery('#option3a').val(), '', 'Call val() on a option element with no value attribute' );
0
-
0
-  jQuery('#select3').val("");
0
-  same( jQuery('#select3').val(), [''], 'Call val() on a multiple="multiple" select' );
0
-
0
-  var checks = jQuery("<input type='checkbox' name='test' value='1'/>").appendTo("#form")
0
-    .add( jQuery("<input type='checkbox' name='test' value='2'/>").appendTo("#form") )
0
-    .add( jQuery("<input type='checkbox' name='test' value=''/>").appendTo("#form") )
0
-    .add( jQuery("<input type='checkbox' name='test'/>").appendTo("#form") );
0
-
0
-  same( checks.serialize(), "", "Get unchecked values." );
0
-
0
-  equals( checks.eq(3).val(), "on", "Make sure a value of 'on' is provided if none is specified." );
0
-
0
-  checks.val([ "2" ]);
0
-  same( checks.serialize(), "test=2", "Get a single checked value." );
0
-
0
-  checks.val([ "1", "" ]);
0
-  same( checks.serialize(), "test=1&test=", "Get multiple checked values." );
0
-
0
-  checks.val([ "", "2" ]);
0
-  same( checks.serialize(), "test=2&test=", "Get multiple checked values." );
0
-
0
-  checks.val([ "1", "on" ]);
0
-  same( checks.serialize(), "test=1&test=on", "Get multiple checked values." );
0
-
0
-  checks.remove();
0
-});
0
-
0
-var testVal = function(valueObj) {
0
-  expect(6);
0
-
0
-  jQuery("#text1").val(valueObj( 'test' ));
0
-  equals( document.getElementById('text1').value, "test", "Check for modified (via val(String)) value of input element" );
0
-
0
-  jQuery("#text1").val(valueObj( 67 ));
0
-  equals( document.getElementById('text1').value, "67", "Check for modified (via val(Number)) value of input element" );
0
-
0
-  jQuery("#select1").val(valueObj( "3" ));
0
-  equals( jQuery("#select1").val(), "3", "Check for modified (via val(String)) value of select element" );
0
-
0
-  jQuery("#select1").val(valueObj( 2 ));
0
-  equals( jQuery("#select1").val(), "2", "Check for modified (via val(Number)) value of select element" );
0
-
0
-  jQuery("#select1").append("<option value='4'>four</option>");
0
-  jQuery("#select1").val(valueObj( 4 ));
0
-  equals( jQuery("#select1").val(), "4", "Should be possible to set the val() to a newly created option" );
0
-
0
-  // using contents will get comments regular, text, and comment nodes
0
-  var j = jQuery("#nonnodes").contents();
0
-  j.val(valueObj( "asdf" ));
0
-  equals( j.val(), "asdf", "Check node,textnode,comment with val()" );
0
-  j.removeAttr("value");
0
-}
0
-
0
-test("val(String/Number)", function() {
0
-  testVal(bareObj);
0
-});
0
-
0
-test("val(Function)", function() {
0
-  testVal(functionReturningObj);
0
-})
0
-
0
 var testHtml = function(valueObj) {
0
   expect(22);
0
 
0
@@ -768,27 +826,66 @@ test("html(Function)", function() {
0
   testHtml(functionReturningObj);
0
 });
0
 
0
-var testText = function(valueObj) {
0
-  expect(4);
0
-  var val = valueObj("<div><b>Hello</b> cruel world!</div>");
0
-  equals( jQuery("#foo").text(val)[0].innerHTML.replace(/>/g, "&gt;"), "&lt;div&gt;&lt;b&gt;Hello&lt;/b&gt; cruel world!&lt;/div&gt;", "Check escaped text" );
0
+test("html(Function) with incoming value", function() {
0
+  expect(20);
0
+  
0
+  var div = jQuery("#main > div"), old = div.map(function(){ return jQuery(this).html() });
0
+  
0
+  div.html(function(i, val) {
0
+    equals( val, old[i], "Make sure the incoming value is correct." );
0
+    return "<b>test</b>";
0
+  });
0
+  
0
+  var pass = true;
0
+  div.each(function(){
0
+    if ( this.childNodes.length !== 1 ) {
0
+      pass = false;
0
+    }
0
+  })
0
+  ok( pass, "Set HTML" );
0
 
0
+  reset();
0
   // using contents will get comments regular, text, and comment nodes
0
   var j = jQuery("#nonnodes").contents();
0
-  j.text(valueObj("hi!"));
0
-  equals( jQuery(j[0]).text(), "hi!", "Check node,textnode,comment with text()" );
0
-  equals( j[1].nodeValue, " there ", "Check node,textnode,comment with text()" );
0
-  equals( j[2].nodeType, 8, "Check node,textnode,comment with text()" );
0
-}
0
+  old = j.map(function(){ return jQuery(this).html(); });
0
+  
0
+  j.html(function(i, val) {
0
+    equals( val, old[i], "Make sure the incoming value is correct." );
0
+    return "<b>bold</b>";
0
+  });
0
+  
0
+  j.find('b').removeData();
0
+  equals( j.html().replace(/ xmlns="[^"]+"/g, "").toLowerCase(), "<b>bold</b>", "Check node,textnode,comment with html()" );
0
+  
0
+  var $div = jQuery('<div />');
0
+  
0
+  equals( $div.html(function(i, val) {
0
+    equals( val, "", "Make sure the incoming value is correct." );
0
+    return 5;
0
+  }).html(), '5', 'Setting a number as html' );
0
+  
0
+  equals( $div.html(function(i, val) {
0
+    equals( val, "5", "Make sure the incoming value is correct." );
0
+    return 0;
0
+  }).html(), '0', 'Setting a zero as html' );
0
 
0
-test("text(String)", function() {
0
-  testText(bareObj)
0
+  var $div2 = jQuery('<div/>'), insert = "&lt;div&gt;hello1&lt;/div&gt;";
0
+  equals( $div2.html(function(i, val) {
0
+    equals( val, "", "Make sure the incoming value is correct." );
0
+    return insert;
0
+  }).html(), insert, "Verify escaped insertion." );
0
+  
0
+  equals( $div2.html(function(i, val) {
0
+    equals( val, insert, "Make sure the incoming value is correct." );
0
+    return "x" + insert;
0
+  }).html(), "x" + insert, "Verify escaped insertion." );
0
+  
0
+  equals( $div2.html(function(i, val) {
0
+    equals( val, "x" + insert, "Make sure the incoming value is correct." );
0
+    return " " + insert;
0
+  }).html(), " " + insert, "Verify escaped insertion." );  
0
 });
0
 
0
-test("text(Function)", function() {
0
-  testText(functionReturningObj);
0
-})
0
-
0
 var testRemove = function(method) {
0
   expect(9);
0
 
0
test/unit/offset.js
...
1
2
3
 
 
4
5
6
...
51
52
53
 
 
 
 
 
 
 
 
 
 
54
55
56
...
63
64
65
 
 
66
67
68
...
122
123
124
 
 
125
126
127
...
187
188
189
 
 
190
191
192
...
238
239
240
241
 
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
 
 
266
267
268
...
294
295
296
 
 
297
298
299
...
1
2
3
4
5
6
7
8
...
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
...
75
76
77
78
79
80
81
82
...
136
137
138
139
140
141
142
143
...
203
204
205
206
207
208
209
210
...
256
257
258
 
259
260
261
262
263
264
265
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
266
267
268
269
270
271
272
273
...
299
300
301
302
303
304
305
306
0
@@ -1,6 +1,8 @@
0
 module("offset");
0
 
0
 testoffset("absolute", function( jQuery ) {
0
+  expect(144);
0
+  
0
   // get offset tests
0
   var tests = [
0
     { id: '#absolute-1',     top:  1, left:  1 }, 
0
@@ -51,6 +53,16 @@ testoffset("absolute", function( jQuery ) {
0
     equals( jQuery( this.id ).offset().top,  this.top,  "jQuery('" + this.id + "').offset({ top: "  + this.top  + " })" );
0
     equals( jQuery( this.id ).offset().left, this.left, "jQuery('" + this.id + "').offset({ left: " + this.left + " })" );
0
     
0
+    var top = this.top, left = this.left;
0
+    
0
+    jQuery( this.id ).offset(function(i, val){
0
+      equals( val.top, top, "Verify incoming top position." );
0
+      equals( val.left, left, "Verify incoming top position." );
0
+      return { top: top + 1, left: left + 1 };
0
+    });
0
+    equals( jQuery( this.id ).offset().top,  this.top + 1,  "jQuery('" + this.id + "').offset({ top: "  + this.top  + " })" );
0
+    equals( jQuery( this.id ).offset().left, this.left + 1, "jQuery('" + this.id + "').offset({ left: " + this.left + " })" );
0
+    
0
     jQuery( this.id ).offset({ top: this.top, left: this.left, using: function( props ) {
0
       jQuery( this ).css({
0
         top:  props.top  + 1,
0
@@ -63,6 +75,8 @@ testoffset("absolute", function( jQuery ) {
0
 });
0
 
0
 testoffset("relative", function( jQuery ) {
0
+  expect(60);
0
+  
0
   // IE is collapsing the top margin of 1px
0
   var ie = jQuery.browser.msie && parseInt( jQuery.browser.version ) < 8;
0
   
0
@@ -122,6 +136,8 @@ testoffset("relative", function( jQuery ) {
0
 });
0
 
0
 testoffset("static", function( jQuery ) {
0
+  expect(80);
0
+  
0
   // IE is collapsing the top margin of 1px
0
   var ie = jQuery.browser.msie && parseInt( jQuery.browser.version ) < 8;
0
   
0
@@ -187,6 +203,8 @@ testoffset("static", function( jQuery ) {
0
 });
0
 
0
 testoffset("fixed", function( jQuery ) {
0
+  expect(28);
0
+  
0
   jQuery.offset.initialize();
0
   
0
   var tests = [
0
@@ -238,31 +256,18 @@ testoffset("fixed", function( jQuery ) {
0
 });
0
 
0
 testoffset("table", function( jQuery ) {
0
-  var ie = jQuery.browser.msie;
0
+  expect(4);
0
   
0
   equals( jQuery('#table-1').offset().top, 6, "jQuery('#table-1').offset().top" );
0
   equals( jQuery('#table-1').offset().left, 6, "jQuery('#table-1').offset().left" );
0
   
0
   equals( jQuery('#th-1').offset().top, 10, "jQuery('#th-1').offset().top" );
0
   equals( jQuery('#th-1').offset().left, 10, "jQuery('#th-1').offset().left" );
0
-  
0
-  // equals( jQuery('#th-2').offset().top, 10, "jQuery('#th-2').offset().top" );
0
-  // equals( jQuery('#th-2').offset().left, 116, "jQuery('#th-2').offset().left" );
0
-  // 
0
-  // equals( jQuery('#th-3').offset().top, 10, "jQuery('#th-3').offset().top" );
0
-  // equals( jQuery('#th-3').offset().left, 222, "jQuery('#th-3').offset().left" );
0
-  
0
-  // equals( jQuery('#td-1').offset().top, ie ? 116 : 112, "jQuery('#td-1').offset().top" );
0
-  // equals( jQuery('#td-1').offset().left, 10, "jQuery('#td-1').offset().left" );
0
-  // 
0
-  // equals( jQuery('#td-2').offset().top, ie ? 116 : 112, "jQuery('#td-2').offset().top" );
0
-  // equals( jQuery('#td-2').offset().left, 116, "jQuery('#td-2').offset().left" );
0
-  // 
0
-  // equals( jQuery('#td-3').offset().top, ie ? 116 : 112, "jQuery('#td-3').offset().top" );
0
-  // equals( jQuery('#td-3').offset().left, 222, "jQuery('#td-3').offset().left" );
0
 });
0
 
0
 testoffset("scroll", function( jQuery, win ) {
0
+  expect(12);
0
+  
0
   var ie = jQuery.browser.msie && parseInt( jQuery.browser.version ) < 8;
0
   
0
   // IE is collapsing the top margin of 1px
0
@@ -294,6 +299,8 @@ testoffset("scroll", function( jQuery, win ) {
0
 });
0
 
0
 testoffset("body", function( jQuery ) {
0
+  expect(2);
0
+  
0
   equals( jQuery('body').offset().top, 1, "jQuery('#body').offset().top" );
0
   equals( jQuery('body').offset().left, 1, "jQuery('#body').offset().left" );
0
 });

Comments

Please log in to comment.
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server