allow closing tabs by clicking them again

also pass the proper type to attr() - it expects strings!
This commit is contained in:
Andreas Gohr 2017-02-15 16:01:14 +01:00
commit 435c8032f2

View file

@ -11,28 +11,29 @@ jQuery(function () {
$metaBox.on('click', '.meta-tabs a', function (e) {
e.preventDefault();
const $tab = jQuery(this);
const isopen = $tab.attr('aria-expanded') === 'true';
// disable all existing tabs
$metaBox.find('.meta-tabs li')
.removeClass('active')
.find('a')
.attr('aria-expanded', false);
.attr('aria-expanded', 'false');
$metaBox.find('.meta-content .tab-pane')
.removeClass('active')
.attr('aria-hidden', false);
.attr('aria-hidden', 'false');
if (isopen) return; // tab was open, we closed it. we're done
// enable current tab
$tab
.attr('aria-expanded', true)
.attr('aria-expanded', 'true')
.closest('li')
.addClass('active');
$metaBox.find($tab.attr('href'))
.addClass('active')
.attr('aria-hidden', false);
.attr('aria-hidden', 'false');
});
});