Skip to content

Commit 597492d

Browse files
add specs, add docs and fix to keepOpen option
1 parent 18ce96a commit 597492d

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

Docs/Fx/Fx.Accordion.md

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Fx.Accordion Method: constructor
4242
* alwaysHide - (*boolean*: defaults to false) If set to true, it will be possible to close all displayable elements. Otherwise, one will remain open at all time.
4343
* initialDisplayFx - (*boolean*; defaults to true) If set to false, the initial item displayed will not display with an effect but will just be shown immediately.
4444
* resetHeight - (*boolean*; defaults to true) If set to false, the height of an opened accordion section will be set to an absolute pixel size.
45+
* keepOpen - (*boolean*; defaults to false) If set to true, it will keep multiple elements open (no auto collapsing). To close a element you have to "click" the trigger again.
4546

4647
### Events
4748

Source/Fx/Fx.Accordion.js

+10-6
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,13 @@ Fx.Accordion = new Class({
161161
var obj = {},
162162
elements = this.elements,
163163
options = this.options,
164-
effects = this.effects;
164+
effects = this.effects,
165+
keepOpen = options.keepOpen,
166+
alwaysHide = options.alwaysHide;
165167

166168
if (useFx == null) useFx = true;
167169
if (typeOf(index) == 'element') index = elements.indexOf(index);
168-
if (index == this.current && !options.alwaysHide) return this;
170+
if (index == this.current && !alwaysHide && !keepOpen) return this;
169171

170172
if (options.resetHeight){
171173
var prev = elements[this.current];
@@ -174,19 +176,21 @@ Fx.Accordion = new Class({
174176
}
175177
}
176178

177-
if ((this.timer && options.link == 'chain') || (index === this.current && !options.alwaysHide)) return this;
179+
if (this.timer && options.link == 'chain') return this;
178180

179181
if (this.current != null) this.previous = this.current;
180182
this.current = index;
181183
this.selfHidden = false;
182184

183185
elements.each(function(el, i){
184186
obj[i] = {};
185-
var hide;
186-
if(!options.keepOpen || i == index){
187+
var hide, isOpen;
188+
if(!keepOpen || i == index){
189+
if (i == index) isOpen = (el.offsetHeight > 0 && options.height) || (el.offsetWidth > 0 && options.width);
190+
187191
if (i != index){
188192
hide = true;
189-
} else if (options.alwaysHide && ((el.offsetHeight > 0 && options.height) || el.offsetWidth > 0 && options.width)){
193+
} else if ((alwaysHide || keepOpen) && isOpen){
190194
hide = true;
191195
this.selfHidden = true;
192196
}

Tests/Interactive/Fx/Fx.Accordion.html

+21
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,24 @@
150150
});
151151
</script>
152152

153+
<hr/>
154+
155+
<p>It should keep more than one section open at the time.</p>
156+
157+
<dl id="acc7">
158+
<dl>
159+
<dt class="toggle"><b>first section</b></dt>
160+
<dd class="stretcher">I'm the content for the first section.</dd>
161+
<dt class="toggle"><b>second section</b></dt>
162+
<dd class="stretcher">I'm the content for the second section.</dd>
163+
<dt class="toggle"><b>third section</b></dt>
164+
<dd class="stretcher">I'm the content for the third section.</dd>
165+
</dl>
166+
</dl>
167+
168+
<script>
169+
new Fx.Accordion($$('#acc7 dt'), $$('#acc7 dd'), {
170+
keepOpen: true
171+
});
172+
</script>
173+

0 commit comments

Comments
 (0)