Permalink
Browse files

modify .removeClass() to accept functions as argument

  • Loading branch information...
1 parent 50ee09a commit 677054c0b5b2df1934be3d805fbbf2dcc3271de6 @ekhaled ekhaled committed May 3, 2011
Showing with 12 additions and 2 deletions.
  1. +2 −2 src/zepto.js
  2. +10 −0 test/zepto.html
View
4 src/zepto.js
@@ -252,9 +252,9 @@ var Zepto = (function() {
})
},
removeClass: function(name){
- return this.each(function() {
+ return this.each(function(idx) {
classList = this.className;
- name.split(/\s+/g).forEach(function(klass) {
+ funcArg(this,name,idx,classList).split(/\s+/g).forEach(function(klass) {
classList = classList.replace(classRE(klass), " ")
});
this.className = classList.trim()
View
10 test/zepto.html
@@ -1067,6 +1067,16 @@
return "green";
});
t.assertEqual('red blue green', el.className);
+
+ //removeClass with function argument
+ $('#some_element').removeClass(function(idx,classes){
+ //test the value of "this"
+ t.assertEqualCollection($('#some_element'), $(this));
+ //test original classes are being passed
+ t.assertEqual('red blue green', this.className);
+ return "blue";
+ });
+ t.assertEqual('red green', el.className);
},
testHasClass: function(t){

0 comments on commit 677054c

Please sign in to comment.