Permalink
Browse files

support for multiple class names in toggleClass()

  • Loading branch information...
1 parent 47b119c commit 441dd66f8ce7678cb6570d87c2bd280f0cec04fd Viktor Kelemen committed with mislav Nov 30, 2012
Showing with 15 additions and 3 deletions.
  1. +5 −3 src/zepto.js
  2. +10 −0 test/zepto.html
View
@@ -626,9 +626,11 @@ var Zepto = (function() {
},
toggleClass: function(name, when){
return this.each(function(idx){
- var newName = funcArg(this, name, idx, className(this))
- ;(when === undefined ? !$(this).hasClass(newName) : when) ?
- $(this).addClass(newName) : $(this).removeClass(newName)
+ var newName = funcArg(this, name, idx, className(this));
+ newName.split(/\s+/g).forEach(function(klass){
+ (when === undefined ? !$(this).hasClass(klass) : when) ?
+ $(this).addClass(klass) : $(this).removeClass(klass)
+ }, this)
})
},
scrollTop: function(){
View
@@ -2040,6 +2040,16 @@
t.assert(!$('#toggle_element').hasClass('green'))
t.assert(!$('#toggle_element').hasClass('orange'))
+ el.className = ''
+ $(el).toggleClass('orange green')
+ t.assert($(el).hasClass('orange'))
+ t.assert($(el).hasClass('green'))
+ $(el).toggleClass('orange green blue')
+ t.assert(!$(el).hasClass('orange'))
+ t.assert(!$(el).hasClass('green'))
+ t.assert($(el).hasClass('blue'))
+ el.className = ''
+
$('#toggle_element').toggleClass('orange', false)
t.assert(!$('#toggle_element').hasClass('orange'))

0 comments on commit 441dd66

Please sign in to comment.