define(["options", "jquery", "nav"], function (options, $, navConfig) { /** * The path of the output directory, relative to the current HTML file. * @type {String} */ var path2root = null; $(document).ready ( function() { // Register the click handler for the TOC var topicRefExpandBtn = $(".wh_publication_toc .wh-expand-btn"); topicRefExpandBtn.click(toggleTocExpand); /* Toggle expand/collapse on enter and space */ topicRefExpandBtn.keypress(handleKeyEvent); }); /** * Retrieves the path of the output directory, relative to the current HTML file. * * @returns {*} the path of the output directory, relative to the current HTML file. */ function getPathToRoot() { if (path2root == null) { path2root = $('meta[name="wh-path2root"]').attr("content"); if (path2root == null || path2root == undefined) { path2root = ""; } } return path2root; }; /* * Toggles expand/collapse on enter and space */ function handleKeyEvent(event) { // Enter & Spacebar events if ( event.which === 13 || event.which === 32) { event.preventDefault(); toggleTocExpand.call(this); } } function toggleTocExpand() { var topicRef = $(this).closest(".topicref"); var state = topicRef.attr(navConfig.attrs.state); var parentLi = $(this).closest('li'); var titleLink = $(this).siblings(".title").children("a"); var titleLinkID = titleLink.attr("id"); if (state == null) { // Do nothing } else if (state == navConfig.states.pending) { // Do nothing } else if (state == navConfig.states.notReady) { topicRef.attr(navConfig.attrs.state, navConfig.states.pending); parentLi.attr('aria-expanded', 'true'); $(this).attr("aria-labelledby", navConfig.btnIds.pending + " " + titleLinkID); retrieveChildNodes(topicRef); } else if (state == navConfig.states.expanded) { topicRef.attr(navConfig.attrs.state, navConfig.states.collapsed); $(this).attr("aria-labelledby", navConfig.btnIds.expand + " " + titleLinkID); parentLi.attr('aria-expanded', 'false'); } else if (state == navConfig.states.collapsed) { topicRef.attr(navConfig.attrs.state, navConfig.states.expanded); $(this).attr("aria-labelledby", navConfig.btnIds.collapse + " " + titleLinkID); parentLi.attr('aria-expanded', 'true'); } }; /** * Loads the JS file containing the list of child nodes for the current topic node. * Builds the list of child topics element nodes based on the retrieved data. * * @param topicRefSpan The topicref 'span' element of the current node from TOC / Menu. */ function retrieveChildNodes(topicRefSpan) { var tocId = $(topicRefSpan).attr(navConfig.attrs.tocID); if (tocId != null) { var jsonHref = navConfig.jsonBaseDir + "/" + tocId; require( [jsonHref], function(data) { if (data != null) { var topics = data.topics; var topicLi = topicRefSpan.closest('li'); var topicsUl = createTopicsList(topics); var topicsUlParent = $('