vendor/assets/js/foundation.accordion.js.es6 in foundation-rails-6.2.3.0 vs vendor/assets/js/foundation.accordion.js.es6 in foundation-rails-6.2.4.0
- old
+ new
@@ -74,20 +74,12 @@
var $elem = $(this);
var $tabContent = $elem.children('[data-tab-content]');
if ($tabContent.length) {
$elem.children('a').off('click.zf.accordion keydown.zf.accordion')
.on('click.zf.accordion', function(e) {
- // $(this).children('a').on('click.zf.accordion', function(e) {
e.preventDefault();
- if ($elem.hasClass('is-active')) {
- if(_this.options.allowAllClosed || $elem.siblings().hasClass('is-active')){
- _this.up($tabContent);
- }
- }
- else {
- _this.down($tabContent);
- }
+ _this.toggle($tabContent);
}).on('keydown.zf.accordion', function(e){
Foundation.Keyboard.handleKey(e, 'Accordion', {
toggle: function() {
_this.toggle($tabContent);
},
@@ -113,44 +105,42 @@
});
}
/**
* Toggles the selected content pane's open/close state.
- * @param {jQuery} $target - jQuery object of the pane to toggle.
+ * @param {jQuery} $target - jQuery object of the pane to toggle (`.accordion-content`).
* @function
*/
toggle($target) {
if($target.parent().hasClass('is-active')) {
- if(this.options.allowAllClosed || $target.parent().siblings().hasClass('is-active')){
- this.up($target);
- } else { return; }
+ this.up($target);
} else {
this.down($target);
}
}
/**
* Opens the accordion tab defined by `$target`.
- * @param {jQuery} $target - Accordion pane to open.
+ * @param {jQuery} $target - Accordion pane to open (`.accordion-content`).
* @param {Boolean} firstTime - flag to determine if reflow should happen.
* @fires Accordion#down
* @function
*/
down($target, firstTime) {
- if (!this.options.multiExpand && !firstTime) {
- var $currentActive = this.$element.children('.is-active').children('[data-tab-content]');
- if($currentActive.length){
- this.up($currentActive);
- }
- }
-
$target
.attr('aria-hidden', false)
.parent('[data-tab-content]')
.addBack()
.parent().addClass('is-active');
+ if (!this.options.multiExpand && !firstTime) {
+ var $currentActive = this.$element.children('.is-active').children('[data-tab-content]');
+ if ($currentActive.length) {
+ this.up($currentActive.not($target));
+ }
+ }
+
$target.slideDown(this.options.slideSpeed, () => {
/**
* Fires when the tab is done opening.
* @event Accordion#down
*/
@@ -163,19 +153,18 @@
});
}
/**
* Closes the tab defined by `$target`.
- * @param {jQuery} $target - Accordion tab to close.
+ * @param {jQuery} $target - Accordion tab to close (`.accordion-content`).
* @fires Accordion#up
* @function
*/
up($target) {
var $aunts = $target.parent().siblings(),
_this = this;
- var canClose = this.options.multiExpand ? $aunts.hasClass('is-active') : $target.parent().hasClass('is-active');
- if(!this.options.allowAllClosed && !canClose) {
+ if((!this.options.allowAllClosed && !$aunts.hasClass('is-active')) || !$target.parent().hasClass('is-active')) {
return;
}
// Foundation.Move(this.options.slideSpeed, $target, function(){
$target.slideUp(_this.options.slideSpeed, function () {