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: b3cee01

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 'master' of git@github.com:jquery/jquery
jeresig (author)
Wed Dec 09 20:59:12 -0800 2009
commit  b3cee01820adde707428d68fcf02b0fdf53fe527
tree    d7ca36700d6dee5792d5fd5e8aa432b4c9d5a2dc
parent  cf72fba64fd164507752376a578dee7919cec911 parent  da51cd0e43d6d61e0d3d6c197cef1e658bad29bc
M src/attributes.js 33 ••••
M src/manipulation.js 8 ••••
M test/unit/attributes.js 73 ••••
M test/unit/manipulation.js 7 ••••
0
src/attributes.js
...
4
5
6
 
 
 
 
 
 
7
8
9
...
29
30
31
 
 
 
 
 
 
32
33
34
...
113
114
115
116
 
117
118
119
...
122
123
124
125
 
126
127
128
 
129
130
131
...
158
159
160
 
 
 
 
 
 
 
161
162
163
...
178
179
180
181
 
 
 
 
 
182
183
184
...
192
193
194
195
 
196
197
198
...
4
5
6
7
8
9
10
11
12
13
14
15
...
35
36
37
38
39
40
41
42
43
44
45
46
...
125
126
127
 
128
129
130
131
...
134
135
136
 
137
138
139
 
140
141
142
143
...
170
171
172
173
174
175
176
177
178
179
180
181
182
...
197
198
199
 
200
201
202
203
204
205
206
207
...
215
216
217
 
218
219
220
221
0
@@ -4,6 +4,12 @@ jQuery.fn.extend({
0
   },
0
 
0
   addClass: function( value ) {
0
+    if(jQuery.isFunction(value)) {
0
+      return this.each(function() {
0
+        jQuery(this).addClass( value.call(this) );
0
+      });
0
+    }
0
+
0
     if ( value && typeof value === "string" ) {
0
       var classNames = (value || "").split(/\s+/);
0
 
0
@@ -29,6 +35,12 @@ jQuery.fn.extend({
0
   },
0
 
0
   removeClass: function( value ) {
0
+    if(jQuery.isFunction(value)) {
0
+      return this.each(function() {
0
+        jQuery(this).removeClass( value.call(this) );
0
+      });
0
+    }
0
+
0
     if ( (value && typeof value === "string") || value === undefined ) {
0
       var classNames = (value || "").split(/\s+/);
0
 
0
@@ -113,7 +125,7 @@ jQuery.fn.extend({
0
     // Typecast once if the value is a number
0
     if ( typeof value === "number" ) {
0
       value += '';
0
-    }  
0
+    }
0
     var val = value;
0
 
0
     return this.each(function(){
0
@@ -122,10 +134,10 @@ jQuery.fn.extend({
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
+          val += '';
0
         }
0
       }
0
-      
0
+
0
       if ( this.nodeType != 1 ) {
0
         return;
0
       }
0
@@ -158,6 +170,13 @@ jQuery.each({
0
   },
0
 
0
   toggleClass: function( classNames, state ) {
0
+    if( jQuery.isFunction(classNames) ) {
0
+      return this.each(function() {
0
+        console.log(this);
0
+        jQuery(this).toggleClass( classNames.call(this), state );
0
+      });
0
+    }
0
+
0
     var type = typeof classNames;
0
     if ( type === "string" ) {
0
       // toggle individual class names
0
@@ -178,7 +197,11 @@ jQuery.each({
0
     }
0
   }
0
 }, function(name, fn){
0
-  jQuery.fn[ name ] = function(){
0
+  jQuery.fn[ name ] = function(val, state){
0
+    if( jQuery.isFunction( val ) ) {
0
+      return this.each(function() { jQuery(this)[ name ]( val.call(this), state ); });
0
+    }
0
+
0
     return this.each( fn, arguments );
0
   };
0
 });
0
@@ -192,7 +215,7 @@ jQuery.extend({
0
     if ( name in jQuery.fn && name !== "attr" ) {
0
       return jQuery(elem)[name](value);
0
     }
0
-    
0
+
0
     var notxml = elem.nodeType !== 1 || !jQuery.isXMLDoc( elem ),
0
       // Whether we are setting (or getting)
0
       set = value !== undefined;
0
src/manipulation.js
...
32
33
34
 
 
 
 
 
 
35
36
37
...
87
88
89
90
 
91
92
93
...
32
33
34
35
36
37
38
39
40
41
42
43
...
93
94
95
 
96
97
98
99
0
@@ -32,6 +32,12 @@ if ( !jQuery.support.htmlSerialize ) {
0
 
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
+      });
0
+    }
0
+
0
     if ( typeof text !== "object" && text !== undefined ) {
0
       return this.empty().append( (this[0] && this[0].ownerDocument || document).createTextNode( text ) );
0
     }
0
@@ -87,7 +93,7 @@ jQuery.fn.extend({
0
       }
0
     }).end();
0
   },
0
-  
0
+
0
   append: function() {
0
     return this.domManip(arguments, true, function(elem){
0
       if ( this.nodeType === 1 ) {
0
test/unit/attributes.js
...
1
2
 
 
 
3
4
5
...
294
295
296
297
 
298
299
300
 
301
302
303
...
306
307
308
309
 
310
 
 
 
 
311
312
313
 
 
 
 
 
314
315
316
317
318
 
319
320
321
...
323
324
325
326
 
327
328
329
...
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
...
393
394
395
 
 
 
 
396
397
398
 
 
 
 
 
399
400
 
 
 
 
 
 
 
 
 
401
402
403
...
1
2
3
4
5
6
7
8
...
297
298
299
 
300
301
302
 
303
304
305
306
...
309
310
311
 
312
313
314
315
316
317
318
319
 
320
321
322
323
324
325
326
327
328
 
329
330
331
332
...
334
335
336
 
337
338
339
340
...
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
...
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
0
@@ -1,5 +1,8 @@
0
 module("attributes");
0
 
0
+var bareObj = function(value) { return value; };
0
+var functionReturningObj = function(value) { return (function() { return value; }); };
0
+
0
 test("attr(String)", function() {
0
   expect(28);
0
   
0
@@ -294,10 +297,10 @@ test("attr('tabindex', value)", function() {
0
   equals(element.attr('tabindex'), -1, 'set negative tabindex');
0
 });
0
 
0
-test("addClass(String)", function() {
0
+var testAddClass = function(valueObj) {
0
   expect(2);
0
   var div = jQuery("div");
0
-  div.addClass("test");
0
+  div.addClass( valueObj("test") );
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
@@ -306,16 +309,24 @@ test("addClass(String)", function() {
0
 
0
   // using contents will get regular, text, and comment nodes
0
   var j = jQuery("#nonnodes").contents();
0
-  j.addClass("asdf");
0
+  j.addClass( valueObj("asdf") );
0
   ok( j.hasClass("asdf"), "Check node,textnode,comment for addClass" );
0
+}
0
+
0
+test("addClass(String)", function() {
0
+  testAddClass(bareObj);
0
 });
0
 
0
-test("removeClass(String) - simple", function() {
0
+test("addClass(Function)", function() {
0
+  testAddClass(functionReturningObj);
0
+});
0
+
0
+var testRemoveClass = function(valueObj) {
0
   expect(5);
0
 
0
   var $divs = jQuery('div');
0
 
0
-  $divs.addClass("test").removeClass("test");
0
+  $divs.addClass("test").removeClass( valueObj("test") );
0
 
0
   ok( !$divs.is('.test'), "Remove Class" );
0
 
0
@@ -323,7 +334,7 @@ test("removeClass(String) - simple", function() {
0
   $divs = jQuery('div');
0
 
0
   $divs.addClass("test").addClass("foo").addClass("bar");
0
-  $divs.removeClass("test").removeClass("bar").removeClass("foo");
0
+  $divs.removeClass( valueObj("test") ).removeClass( valueObj("bar") ).removeClass( valueObj("foo") );
0
 
0
   ok( !$divs.is('.test,.bar,.foo'), "Remove multiple classes" );
0
 
0
@@ -331,42 +342,50 @@ test("removeClass(String) - simple", function() {
0
   $divs = jQuery('div');
0
 
0
   // Make sure that a null value doesn't cause problems
0
-  $divs.eq(0).addClass("test").removeClass(null);
0
+  $divs.eq(0).addClass("test").removeClass( valueObj(null) );
0
   ok( $divs.eq(0).is('.test'), "Null value passed to removeClass" );
0
 
0
-  $divs.eq(0).addClass("test").removeClass("");
0
+  $divs.eq(0).addClass("test").removeClass( valueObj("") );
0
   ok( $divs.eq(0).is('.test'), "Empty string passed to removeClass" );
0
 
0
   // using contents will get regular, text, and comment nodes
0
   var j = jQuery("#nonnodes").contents();
0
-  j.removeClass("asdf");
0
+  j.removeClass( valueObj("asdf") );
0
   ok( !j.hasClass("asdf"), "Check node,textnode,comment for removeClass" );
0
+};
0
+
0
+test("removeClass(String) - simple", function() {
0
+  testRemoveClass(bareObj);
0
 });
0
 
0
-test("toggleClass(String|boolean|undefined[, boolean])", function() {
0
+test("removeClass(Function) - simple", function() {
0
+  testRemoveClass(functionReturningObj);
0
+});
0
+
0
+var testToggleClass = function(valueObj) {
0
   expect(17);
0
 
0
   var e = jQuery("#firstp");
0
   ok( !e.is(".test"), "Assert class not present" );
0
-  e.toggleClass("test");
0
+  e.toggleClass( valueObj("test") );
0
   ok( e.is(".test"), "Assert class present" );
0
-  e.toggleClass("test");
0
+  e.toggleClass( valueObj("test") );
0
   ok( !e.is(".test"), "Assert class not present" );
0
 
0
   // class name with a boolean
0
-  e.toggleClass("test", false);
0
+  e.toggleClass( valueObj("test"), false );
0
   ok( !e.is(".test"), "Assert class not present" );
0
-  e.toggleClass("test", true);
0
+  e.toggleClass( valueObj("test"), true );
0
   ok( e.is(".test"), "Assert class present" );
0
-  e.toggleClass("test", false);
0
+  e.toggleClass( valueObj("test"), false );
0
   ok( !e.is(".test"), "Assert class not present" );
0
 
0
   // multiple class names
0
   e.addClass("testA testB");
0
   ok( (e.is(".testA.testB")), "Assert 2 different classes present" );
0
-  e.toggleClass("testB testC");
0
+  e.toggleClass( valueObj("testB testC") );
0
   ok( (e.is(".testA.testC") && !e.is(".testB")), "Assert 1 class added, 1 class removed, and 1 class kept" );
0
-  e.toggleClass("testA testC");
0
+  e.toggleClass( valueObj("testA testC") );
0
   ok( (!e.is(".testA") && !e.is(".testB") && !e.is(".testC")), "Assert no class present" );
0
 
0
   // toggleClass storage
0
@@ -393,11 +412,27 @@ test("toggleClass(String|boolean|undefined[, boolean])", function() {
0
   // Cleanup
0
   e.removeClass("testD");
0
   e.removeData('__className__');
0
+};
0
+
0
+test("toggleClass(String|boolean|undefined[, boolean])", function() {
0
+  testToggleClass(bareObj);
0
 });
0
 
0
-test("removeAttr(String", function() {
0
+test("toggleClass(Function[, boolean])", function() {
0
+  testToggleClass(functionReturningObj);
0
+});
0
+
0
+var testRemoveAttr = function(valueObj) {
0
   expect(1);
0
-  equals( jQuery('#mark').removeAttr("class")[0].className, "", "remove class" );
0
+  equals( jQuery('#mark').removeAttr( valueObj("class") )[0].className, "", "remove class" );
0
+};
0
+
0
+test("removeAttr(String)", function() {
0
+  testRemoveAttr(bareObj);
0
+});
0
+
0
+test("removeAttr(Function)", function() {
0
+  testRemoveAttr(functionReturningObj);
0
 });
0
 
0
 test("addClass, removeClass, hasClass", function() {
0
test/unit/manipulation.js
...
739
740
741
742
 
743
744
745
746
 
 
747
748
749
750
 
751
752
753
...
739
740
741
 
742
743
744
745
 
746
747
748
749
750
 
751
752
753
754
0
@@ -739,15 +739,16 @@ test("html(String)", function() {
0
 
0
 test("html(Function)", function() {
0
   testHtml(functionReturningObj);
0
-})
0
+});
0
 
0
 var testText = function(valueObj) {
0
   expect(4);
0
-  equals( jQuery("#foo").text("<div><b>Hello</b> cruel world!</div>")[0].innerHTML.replace(/>/g, "&gt;"), "&lt;div&gt;&lt;b&gt;Hello&lt;/b&gt; cruel world!&lt;/div&gt;", "Check escaped text" );
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("hi!");
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()" );

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