From 435c8032f2ef43ba221b7d417ccdb50c85580e1e Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Wed, 15 Feb 2017 16:01:14 +0100 Subject: [PATCH] allow closing tabs by clicking them again also pass the proper type to attr() - it expects strings! --- js/meta-box.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/js/meta-box.js b/js/meta-box.js index f53e794..432146e 100755 --- a/js/meta-box.js +++ b/js/meta-box.js @@ -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'); }); - - });