Permalink
Browse files

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

…ntecker-master
  • Loading branch information...
2 parents 4add077 + 2946e32 commit 78480afe5030e73a453cbbc6377a41ed49816580 @madrobby committed Dec 17, 2010
Showing with 28 additions and 0 deletions.
  1. +5 −0 src/zepto.js
  2. +23 −0 test/zepto.html
View
5 src/zepto.js
@@ -122,6 +122,11 @@ var Zepto = (function() {
return this.each(function(element){
element.className = element.className.replace(classRE(name), ' ').trim()
});
+ },
+ toggleClass: function(name){
+ return this.each(function(element){
+ $(element).hasClass(name) ? $(element).removeClass(name) : $(element).addClass(name)
+ });
}
};
View
23 test/zepto.html
@@ -19,6 +19,8 @@
<span class="nay" id="nay">nay</span>
</p>
+ <div id="toggle_element"></div>
+
<div id="attr_1" data-id="someId1" data-name="someName1"></div>
<div id="attr_2" data-id="someId2" data-name="someName2"></div>
@@ -715,6 +717,27 @@
t.assert($('#some_element').hasClass('orange'));
},
+ testToggleClass: function(t){
+ var el = $('#toggle_element').get(0);
+ $('#toggle_element').toggleClass('green');
+
+ t.assert($('#toggle_element').hasClass('green'));
+ t.assert(!$('#toggle_element').hasClass('orange'));
+
+ $('#toggle_element').toggleClass('orange');
+ t.assert($('#toggle_element').hasClass('green'));
+ t.assert($('#toggle_element').hasClass('orange'));
+
+ $('#toggle_element').toggleClass('green');
+
+ t.assert(!$('#toggle_element').hasClass('green'));
+ t.assert($('#toggle_element').hasClass('orange'));
+
+ $('#toggle_element').toggleClass('orange');
+ t.assert(!$('#toggle_element').hasClass('green'));
+ t.assert(!$('#toggle_element').hasClass('orange'));
+ },
+
testIndex: function(t){
t.assertEqual($("p > span").index("#nay"), 2);
t.assertEqual($("p > span").index(".yay"), 0);

0 comments on commit 78480af

Please sign in to comment.