diff --git a/static/js/cours.js b/static/js/cours.js index 721b23f..5f539a9 100644 --- a/static/js/cours.js +++ b/static/js/cours.js @@ -1,3 +1,10 @@ +/** + * Clean URLs from anchors + * @param {string} url Link URL + * @returns Link URL cleaned + */ +const cleanURL = (url) => url.split("#")[0]; + /** * Build the filetree * @param {HTMLElement} parent Root element of the filetree @@ -30,7 +37,7 @@ const buildFileTree = (parent, data, location) => { ); } else { // File - const url = window.location.href.split("?")[0]; + const url = cleanURL(window.location.href).split("?")[0]; const a = document.createElement("a"); a.text = item.name; a.href = `${url}?q=${location}${item.name}`; @@ -66,7 +73,7 @@ const uncollapse = (element) => { * Find the deepest opened directory * @param {string[]} path Current path we are looking at, init with fullpath * @param {NodeListOf} options Options we have, init with list root - * @returns + * @returns The deepest node */ const deepestNodeOpened = (path, options) => { if (path[0] === "") { @@ -91,6 +98,12 @@ const deepestNodeOpened = (path, options) => { } }; +/** + * Search in the filetree, when nothing is aske, returns to initial state + * @param {string} query Query + * @param {HTMLElement} parent Filetree + * @param {HTMLLIElement} currentFile Current file opened + */ const searchFiles = (query, parent, currentFile) => { // Prevent blocking the main thread requestAnimationFrame(() => { @@ -136,7 +149,7 @@ window.addEventListener("load", () => { dataElement.remove(); // Open nested openeded directories - const infoURL = window.location.href.split("?"); + const infoURL = cleanURL(window.location.href).split("?"); const fullpath = infoURL.length > 1 ? infoURL[1].substring(2) : "index.md"; const path = fullpath.substring(0, fullpath.lastIndexOf("/"));