Skip to content
This repository
Browse code

Merge branch 'master' of https://github.com/clintecker/zepto into cli…

…ntecker-master
  • Loading branch information...
commit 78480afe5030e73a453cbbc6377a41ed49816580 2 parents 4add077 + 2946e32
Thomas Fuchs authored
5  src/zepto.js
@@ -122,6 +122,11 @@ var Zepto = (function() {
122 122
       return this.each(function(element){
123 123
         element.className = element.className.replace(classRE(name), ' ').trim()
124 124
       });
  125
+    },
  126
+    toggleClass: function(name){
  127
+      return this.each(function(element){
  128
+        $(element).hasClass(name) ? $(element).removeClass(name) : $(element).addClass(name)
  129
+      });
125 130
     }
126 131
   };
127 132
 
23  test/zepto.html
@@ -19,6 +19,8 @@
19 19
     <span class="nay" id="nay">nay</span>
20 20
   </p>
21 21
 
  22
+  <div id="toggle_element"></div>
  23
+
22 24
   <div id="attr_1" data-id="someId1" data-name="someName1"></div>
23 25
   <div id="attr_2" data-id="someId2" data-name="someName2"></div>
24 26
 
@@ -715,6 +717,27 @@
715 717
         t.assert($('#some_element').hasClass('orange'));
716 718
       },
717 719
 
  720
+      testToggleClass: function(t){
  721
+        var el = $('#toggle_element').get(0);
  722
+        $('#toggle_element').toggleClass('green');
  723
+
  724
+        t.assert($('#toggle_element').hasClass('green'));
  725
+        t.assert(!$('#toggle_element').hasClass('orange'));
  726
+
  727
+        $('#toggle_element').toggleClass('orange');
  728
+        t.assert($('#toggle_element').hasClass('green'));
  729
+        t.assert($('#toggle_element').hasClass('orange'));
  730
+
  731
+        $('#toggle_element').toggleClass('green');
  732
+
  733
+        t.assert(!$('#toggle_element').hasClass('green'));
  734
+        t.assert($('#toggle_element').hasClass('orange'));
  735
+
  736
+        $('#toggle_element').toggleClass('orange');
  737
+        t.assert(!$('#toggle_element').hasClass('green'));
  738
+        t.assert(!$('#toggle_element').hasClass('orange'));
  739
+      },
  740
+
718 741
       testIndex: function(t){
719 742
         t.assertEqual($("p > span").index("#nay"), 2);
720 743
         t.assertEqual($("p > span").index(".yay"), 0);

0 notes on commit 78480af

Please sign in to comment.
Something went wrong with that request. Please try again.