Skip to content

Commit ad17ac4

Browse files
Merge pull request #1333 from SergioCrisostomo/pr1187
new option "keepOpen" to Fx.Accordion
2 parents c6a90c3 + 597492d commit ad17ac4

File tree

3 files changed

+42
-13
lines changed

3 files changed

+42
-13
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

+20-13
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ Fx.Accordion = new Class({
3838
alwaysHide: false,
3939
trigger: 'click',
4040
initialDisplayFx: true,
41-
resetHeight: true
41+
resetHeight: true,
42+
keepOpen: false
4243
},
4344

4445
initialize: function(){
@@ -160,11 +161,13 @@ Fx.Accordion = new Class({
160161
var obj = {},
161162
elements = this.elements,
162163
options = this.options,
163-
effects = this.effects;
164+
effects = this.effects,
165+
keepOpen = options.keepOpen,
166+
alwaysHide = options.alwaysHide;
164167

165168
if (useFx == null) useFx = true;
166169
if (typeOf(index) == 'element') index = elements.indexOf(index);
167-
if (index == this.current && !options.alwaysHide) return this;
170+
if (index == this.current && !alwaysHide && !keepOpen) return this;
168171

169172
if (options.resetHeight){
170173
var prev = elements[this.current];
@@ -173,24 +176,28 @@ Fx.Accordion = new Class({
173176
}
174177
}
175178

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

178181
if (this.current != null) this.previous = this.current;
179182
this.current = index;
180183
this.selfHidden = false;
181184

182185
elements.each(function(el, i){
183186
obj[i] = {};
184-
var hide;
185-
if (i != index){
186-
hide = true;
187-
} else if (options.alwaysHide && ((el.offsetHeight > 0 && options.height) || el.offsetWidth > 0 && options.width)){
188-
hide = true;
189-
this.selfHidden = true;
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+
191+
if (i != index){
192+
hide = true;
193+
} else if ((alwaysHide || keepOpen) && isOpen){
194+
hide = true;
195+
this.selfHidden = true;
196+
}
197+
this.fireEvent(hide ? 'background' : 'active', [this.togglers[i], el]);
198+
for (var fx in effects) obj[i][fx] = hide ? 0 : el[effects[fx]];
199+
if (!useFx && !hide && options.resetHeight) obj[i].height = 'auto';
190200
}
191-
this.fireEvent(hide ? 'background' : 'active', [this.togglers[i], el]);
192-
for (var fx in effects) obj[i][fx] = hide ? 0 : el[effects[fx]];
193-
if (!useFx && !hide && options.resetHeight) obj[i].height = 'auto';
194201
}, this);
195202

196203
this.internalChain.clearChain();

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)