/** * Sets up the sidebar behaviour * * @author Andreas Gohr * @author Michael Große * @author Jana Deutschlaender */ jQuery(function () { var $nav = jQuery('#dokuwiki__aside'); if (!$nav.length) return; // id of the current sidebar, used to differentiate states var sidebarId = ''; var divId = jQuery('#sidebarId'); if (typeof divId !== 'undefined') { sidebarId = divId.attr('class').split(' ')[0]; } /** * closes sidebar */ var setWideContent = function () { $nav.find('div.nav-panel').hide(); // close all panels jQuery('body').addClass('wide-content'); removeToggleStorage(); window.sessionStorage.setItem('wide-content', true); }, /** * removes information about the toggle-state */ removeToggleStorage = function () { for (var index=0; index <= window.sessionStorage.length; index += 1) { var item = window.sessionStorage.getItem('sidebar-section-' + sidebarId + '-' + index + '-open'); if (!item) { continue; } window.sessionStorage.setItem('sidebar-section-' + sidebarId + '-' + index + '-open', 'false'); } }, /** * opens the sidebar */ setDefaultContent = function () { jQuery('body').removeClass('wide-content'); window.sessionStorage.setItem('wide-content', false); }, /** * Accessibility helper, focuses the first link witih the given element * * @param {jQuery} $elem */ focusFirstSubLink = function ($elem) { $elem.find('a').first().focus(); }, removeOpenStates = function() { $nav.find('.is-open').removeClass('is-open'); }, /** * Toggle a navigation panel * * @param {jQuery} $toggler The a toggler */ toggleNav = function ($toggler) { var $panel = $toggler.parent().next('div.nav-panel'); var isOpen = $panel.is(':visible'); // open sidebar on interaction setDefaultContent(); // toggle the panel, focus first link after opening $panel.dw_toggle(!isOpen, function () { if (!isOpen) { focusFirstSubLink($panel); $toggler.addClass('is-open'); } else { $toggler.removeClass('is-open'); } }); window.sessionStorage.setItem('sidebar-section-' + sidebarId + '-' + $toggler.data('index') + '-open', !isOpen); }, /** * Initialize the content navigation * * It mangles the sidebar content and handles inline Icon configuration */ initContentNav = function () { var $main = $nav.find('nav.nav-main'); if (!$main.length) return; if(jQuery('body').hasClass('wide-content')) { removeToggleStorage(); } var ELEMENT = JSINFO.template.sprintdoc.sidebar_toggle_elements; var $elements = $main.find(ELEMENT); $elements.each(function (index) { var $me = jQuery(this), // prepare text and the optional icon data = $me.text().split('@', 2), text = data[0].trim(); var $icon = jQuery('') .text(text.substr(0, 1).toUpperCase() + text.substr(1, 1).toLowerCase()) .wrapInner(''); if (data[1]) { var src = data[1].trim(); $icon.load(DOKU_BASE + 'lib/tpl/sprintdoc/svg.php?svg=' + src + '&e=1'); // directly embed } // make the new toggler var $toggler = jQuery('') .attr('href', '#') .attr('role', 'heading') .attr('aria-level', '2') .text(text) .wrapInner('') .prepend($icon) .data('index', index) ; $toggler = jQuery('