dokuwiki-template-sprintdoc.../js/meta-box.js
Andreas Gohr c93c93a805 simplify meta box tab handling RES-799
This simplifies the tab handling by attaching one click handler to
handle the open/close mechanism for all tabs. It should now allow to
dynamically add tabs even after the fact and the handler should still
work.

Support for the actual tab contents has been removed for now. This
should most probably be readded via PHP anyway.
2017-02-15 15:50:11 +01:00

38 lines
989 B
JavaScript
Executable file

jQuery(function () {
const $metaBox = jQuery('#spr__meta-box');
if (!$metaBox.length) return;
/**
* Register the click handler for the tabs
*
* Tabs can be added dynamically later on and this handler will still
* provide the open/close functionality
*/
$metaBox.on('click', '.meta-tabs a', function (e) {
e.preventDefault();
const $tab = jQuery(this);
// disable all existing tabs
$metaBox.find('.meta-tabs li')
.removeClass('active')
.find('a')
.attr('aria-expanded', false);
$metaBox.find('.meta-content .tab-pane')
.removeClass('active')
.attr('aria-hidden', false);
// enable current tab
$tab
.attr('aria-expanded', true)
.closest('li')
.addClass('active');
$metaBox.find($tab.attr('href'))
.addClass('active')
.attr('aria-hidden', false);
});
});