Skip to content
This repository was archived by the owner on Aug 5, 2020. It is now read-only.

Commit 9907e45

Browse files
committed
Add toggleAll and openAll
1 parent c856f77 commit 9907e45

File tree

5 files changed

+125
-2
lines changed

5 files changed

+125
-2
lines changed

dist/bellows.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,22 @@
208208
});
209209
},
210210

211+
toggleAll: function() {
212+
var plugin = this;
213+
214+
this.$bellows.find('.' + cssClasses.ITEM).each(function() {
215+
plugin.toggle($(this));
216+
});
217+
},
218+
219+
openAll: function() {
220+
var plugin = this;
221+
222+
this.$bellows.find('.' + cssClasses.ITEM + ':not(.' + cssClasses.OPENED + ')').each(function() {
223+
plugin.open($(this));
224+
});
225+
},
226+
211227
closeAll: function() {
212228
var plugin = this;
213229

dist/bellows.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"type" : "git",
55
"url" : "https://github.com/mobify/bellows.git"
66
},
7-
"version": "5.0.0",
7+
"version": "5.1.0",
88
"description": "A mobile first accordion UI plugin",
99
"devDependencies": {
1010
"grunt": "~0.4.x",

src/js/bellows.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,22 @@
208208
});
209209
},
210210

211+
toggleAll: function() {
212+
var plugin = this;
213+
214+
this.$bellows.find('.' + cssClasses.ITEM).each(function() {
215+
plugin.toggle($(this));
216+
});
217+
},
218+
219+
openAll: function() {
220+
var plugin = this;
221+
222+
this.$bellows.find('.' + cssClasses.ITEM + ':not(.' + cssClasses.OPENED + ')').each(function() {
223+
plugin.open($(this));
224+
});
225+
},
226+
211227
closeAll: function() {
212228
var plugin = this;
213229

tests/unit/plugin.js

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,97 @@ define([
8888
$element.bellows('open', 0);
8989
});
9090

91+
it('opens all bellows items using the openAll method', function(done) {
92+
93+
var openCount = 0;
94+
95+
$element.bellows({
96+
opened: function(e, ui) {
97+
assert.isTrue(ui.item.hasClass('bellows--is-open'));
98+
openCount++;
99+
if (openCount === 2) done();
100+
}
101+
});
102+
103+
$element.bellows('openAll');
104+
});
105+
106+
it('closes all bellows items using the closeAll method', function(done) {
107+
108+
var openCount = 0;
109+
var closeCount = 0;
110+
111+
$element.bellows({
112+
opened: function(e, ui) {
113+
openCount++;
114+
if (openCount === 2) $element.bellows('closeAll');
115+
},
116+
closed: function(e, ui) {
117+
assert.isFalse(ui.item.hasClass('bellows--is-open'));
118+
closeCount++;
119+
if (closeCount === 2) done();
120+
}
121+
});
122+
123+
$element.bellows('openAll');
124+
});
125+
126+
it('opens all bellows items when not all are open', function(done) {
127+
128+
var openedSingle = false;
129+
130+
$element.bellows({
131+
opened: function(e, ui) {
132+
if (!openedSingle) {
133+
openedSingle = true;
134+
$element.bellows('openAll');
135+
return;
136+
}
137+
assert.equal($element.find('.bellows--is-open').length, 2);
138+
done();
139+
}
140+
});
141+
142+
$element.bellows('open', 0);
143+
});
144+
145+
it('closes all bellows items when not all are closed', function(done) {
146+
147+
$element.bellows({
148+
opened: function(e, ui) {
149+
$element.bellows('closeAll');
150+
},
151+
closed: function(e, ui) {
152+
assert.equal($element.find('.bellows__item:not(.bellows--is-open)').length, 2);
153+
done();
154+
}
155+
});
156+
157+
$element.bellows('open', 0);
158+
});
159+
160+
it('toggles all bellows items', function(done) {
161+
162+
var openCount = 0;
163+
var closeCount = 0;
164+
165+
$element.bellows({
166+
opened: function(e, ui) {
167+
openCount++;
168+
if (openCount === 2) $element.bellows('toggleAll');
169+
},
170+
closed: function(e, ui) {
171+
closeCount++;
172+
if (closeCount === 2) {
173+
assert.equal($element.find('.bellows__item:not(.bellows--is-open)').length, 2);
174+
done();
175+
}
176+
}
177+
});
178+
179+
$element.bellows('toggleAll');
180+
});
181+
91182
it('removes aria-hidden attribute when open', function(done) {
92183
$element.bellows({
93184
opened: function(e, ui) {

0 commit comments

Comments
 (0)