diff --git a/src/gui/quicklinks.js b/src/gui/quicklinks.js index 46d74e9359af1894d657e369481ad2b9f7f4016c..bc929d197958763de14da316af91c59ad7cfae25 100644 --- a/src/gui/quicklinks.js +++ b/src/gui/quicklinks.js @@ -273,6 +273,9 @@ App.UI.quickMenu = (function() { goBack(); }); + /** + * Goes back in history if possible. + */ function goBack() { if (history.length > 0 && jumpFrom.includes(State.passage)) { historyNavigation = true; @@ -281,6 +284,7 @@ App.UI.quickMenu = (function() { } /** + * Add a "Return" link at second position if there is a history. * @param {HTMLDivElement} container */ function addBackLink(container) { @@ -296,6 +300,10 @@ App.UI.quickMenu = (function() { } } + /** + * Generate a quick menu + * @returns {string|HTMLDivElement} + */ function generateMenu() { if (!jumpFrom.includes(State.passage)) { hotkeysEnabled = false; @@ -333,7 +341,14 @@ App.UI.quickMenu = (function() { return div; } + /** + * Create a list of links and/or categories based on the given category + * + * @param {object} category + * @returns {Array<HTMLElement>} + */ function generateLinkList(category) { + /** @type {Array<HTMLElement>} */ const links = []; for (const passage in category) { if (category[passage] === true) { @@ -345,6 +360,13 @@ App.UI.quickMenu = (function() { return links; } + /** + * Add a category to a link list + * + * @param {Array<HTMLElement>} outerLinkList + * @param {string} name + * @param {object} category + */ function addCategory(outerLinkList, name, category) { const innerLinkList = generateLinkList(category); if (innerLinkList.length === 0) { @@ -368,6 +390,12 @@ App.UI.quickMenu = (function() { outerLinkList.push(wrapper); } + /** + * Create a link to the given passage and add it to the link list if link is accessible. + * + * @param {Array<HTMLElement>} linkList + * @param {string} passage + */ function addMenuLink(linkList, passage) { // passage is hidden if (hiddenPassages.hasOwnProperty(passage) && hiddenPassages[passage]()) { @@ -409,6 +437,12 @@ App.UI.quickMenu = (function() { } } + /** + * Gives back the proper name for the passage or the passage title itself if there is none + * + * @param {string} passage + * @returns {string} + */ function uiName(passage) { if (uiNames[passage]) { if (typeof uiNames[passage] === "function") { @@ -419,6 +453,13 @@ App.UI.quickMenu = (function() { return passage; } + /** + * Adds an "Other" category to a given layout consisting of passages that can be jumped to not sorted into the + * existing layout. + * + * @param {object} layout + * @returns {object} + */ function addOtherCategory(layout) { const passages = jumpTo.slice(); filterPassages(passages, layout); @@ -433,6 +474,12 @@ App.UI.quickMenu = (function() { return layout; } + /** + * Remove all entries from a given list that exist as keys in a given layout. + * + * @param {Array<string>} passages + * @param {object} layout + */ function filterPassages(passages, layout) { for (const category in layout) { const index = passages.indexOf(category);