xref: /template/sprintdoc/js/meta-box.js (revision 81a9f400e799758c364128e4206d06969172defd) !
1
2
3(function($) {
4
5
6    /**
7     * Register the click handler for the tabs
8     *
9     * Tabs can be added dynamically later on and this handler will still
10     * provide the open/close functionality
11     */
12    var registerClickForTabsInMetaBox = function($metaBox) {
13
14        $metaBox.on('click', '.meta-tabs a', function (e) {
15            e.preventDefault();
16            var $tab = $(this),
17                isopen = $tab.attr('aria-expanded') === 'true';
18
19            // disable all existing tabs
20            $metaBox.find('.meta-tabs li')
21                .removeClass('active')
22                .find('a')
23                .attr('aria-expanded', 'false');
24            $metaBox.find('.meta-content .tab-pane')
25                .removeClass('active')
26                .attr('aria-hidden', 'false');
27
28            if (isopen) return; // tab was open, we closed it. we're done
29
30            // enable current tab
31            $tab
32                .attr('aria-expanded', 'true')
33                .closest('li')
34                .addClass('active');
35            $metaBox.find($tab.attr('href'))
36                .addClass('active')
37                .attr('aria-hidden', 'false');
38
39        });
40
41        /**
42         * in admin templates show toc tab, if available
43         */
44        if($('body').hasClass('do-admin')) {
45            var $tocLink = $metaBox.find('a[href="#spr__tab-toc"]');
46            if($tocLink.length === 1) {
47                $tocLink.trigger('click');
48            }
49        }
50    };
51
52
53    $(function(){
54        var $metaBox = $('#spr__meta-box');
55        if (!$metaBox.length) return;
56
57        registerClickForTabsInMetaBox($metaBox);
58    });
59
60
61})(jQuery);
62