fixes + added list open/close indicator
This commit is contained in:
parent
c5b8076e05
commit
7a7e6ab29a
@ -48,7 +48,7 @@ class Docs {
|
|||||||
this.handleLocation(window.location);
|
this.handleLocation(window.location);
|
||||||
} else if (typeof this.defaultViewPath !== 'undefined') {
|
} else if (typeof this.defaultViewPath !== 'undefined') {
|
||||||
// TODO: Do it.
|
// TODO: Do it.
|
||||||
console.log("Missing Feature !\nShould load the default view");
|
console.log('Missing Feature !\nShould load the default view');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,7 +59,7 @@ class Docs {
|
|||||||
const response = await fetch(this.routesPath);
|
const response = await fetch(this.routesPath);
|
||||||
const json = await response.json();
|
const json = await response.json();
|
||||||
|
|
||||||
return json["routes"];
|
return json['routes'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -69,21 +69,21 @@ class Docs {
|
|||||||
generateNav(routesData, target) {
|
generateNav(routesData, target) {
|
||||||
/** @type {Array.<RoutingItem>} */
|
/** @type {Array.<RoutingItem>} */
|
||||||
const routes = [];
|
const routes = [];
|
||||||
const nav = document.createElement("nav");
|
const nav = document.createElement('nav');
|
||||||
|
|
||||||
routesData.forEach(routeData => {
|
routesData.forEach(routeData => {
|
||||||
if ("routes" in routeData) {
|
if ('routes' in routeData) {
|
||||||
routes.push(new RoutingNode(routeData["name"], routeData["hidden"], routeData["routes"]));
|
routes.push(new RoutingNode(routeData['name'], routeData['hidden'], routeData['routes']));
|
||||||
} else {
|
} else {
|
||||||
routes.push(new Route(routeData["name"], routeData["hidden"], routeData["filepath"]));
|
routes.push(new Route(routeData['name'], routeData['hidden'], routeData['filepath']));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
routes.forEach(routingItem => {
|
routes.forEach(routingItem => {
|
||||||
if (routingItem["hidden"] === false || typeof routingItem["hidden"] === "undefined") {
|
if (routingItem['hidden'] === false || typeof routingItem['hidden'] === 'undefined') {
|
||||||
const el = routingItem.buildSelf();
|
const el = routingItem.buildSelf();
|
||||||
|
|
||||||
if (typeof el !== "undefined") {
|
if (typeof el !== 'undefined') {
|
||||||
nav.appendChild(el);
|
nav.appendChild(el);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -106,11 +106,11 @@ class Docs {
|
|||||||
|
|
||||||
console.log(hashes);
|
console.log(hashes);
|
||||||
|
|
||||||
if (typeof this.currentRoute === "undefined" || this.currentRoute.filepath !== hashes[0]) {
|
if (typeof this.currentRoute === 'undefined' || this.currentRoute.filepath !== hashes[0]) {
|
||||||
const route = this.findMatchingRoute(hashes[0], this.routes);
|
const route = this.findMatchingRoute(hashes[0], this.routes);
|
||||||
|
|
||||||
// Scroll back to top.
|
// Scroll back to top.
|
||||||
document.querySelector("#router-outlet").scrollTop = 0;
|
document.querySelector('#router-outlet').scrollTop = 0;
|
||||||
|
|
||||||
this.currentRoute = route;
|
this.currentRoute = route;
|
||||||
this.displayRoute(route);
|
this.displayRoute(route);
|
||||||
@ -144,7 +144,7 @@ class Docs {
|
|||||||
* @returns {Route} The matching route.
|
* @returns {Route} The matching route.
|
||||||
*/
|
*/
|
||||||
findMatchingRoute(filepath, routes) {
|
findMatchingRoute(filepath, routes) {
|
||||||
console.log("filepath:", filepath);
|
console.log('filepath:', filepath);
|
||||||
|
|
||||||
let match = undefined;
|
let match = undefined;
|
||||||
|
|
||||||
@ -203,7 +203,7 @@ class RoutingItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
buildSelf() {
|
buildSelf() {
|
||||||
const element = document.createElement("div");
|
const element = document.createElement('div');
|
||||||
element.innerText = this.name;
|
element.innerText = this.name;
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
@ -227,12 +227,12 @@ class Route extends RoutingItem {
|
|||||||
* @returns {HTMLAnchorElement} The Route as an HTML link.
|
* @returns {HTMLAnchorElement} The Route as an HTML link.
|
||||||
*/
|
*/
|
||||||
buildSelf(force = false) {
|
buildSelf(force = false) {
|
||||||
if (this.hidden === false || typeof this.hidden === "undefined") {
|
if (this.hidden === false || typeof this.hidden === 'undefined') {
|
||||||
force = true
|
force = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if (force) {
|
if (force) {
|
||||||
const element = document.createElement("a");
|
const element = document.createElement('a');
|
||||||
|
|
||||||
element.href = `#${this.filepath}`;
|
element.href = `#${this.filepath}`;
|
||||||
element.innerText = this.name;
|
element.innerText = this.name;
|
||||||
@ -286,10 +286,10 @@ class RoutingNode extends RoutingItem {
|
|||||||
|
|
||||||
onExec() {
|
onExec() {
|
||||||
this.routesData.forEach(routeData => {
|
this.routesData.forEach(routeData => {
|
||||||
if ("routes" in routeData) {
|
if ('routes' in routeData) {
|
||||||
this.routes.push(new RoutingNode(routeData["name"], routeData["hidden"], routeData["routes"]));
|
this.routes.push(new RoutingNode(routeData['name'], routeData['hidden'], routeData['routes']));
|
||||||
} else {
|
} else {
|
||||||
this.routes.push(new Route(routeData["name"], routeData["hidden"], routeData["filepath"]));
|
this.routes.push(new Route(routeData['name'], routeData['hidden'], routeData['filepath']));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -298,31 +298,16 @@ class RoutingNode extends RoutingItem {
|
|||||||
* @returns {HTMLUListElement} The RoutingNode as an HTML unordered list.
|
* @returns {HTMLUListElement} The RoutingNode as an HTML unordered list.
|
||||||
*/
|
*/
|
||||||
buildSelf(force = false) {
|
buildSelf(force = false) {
|
||||||
if (this.hidden === false || typeof this.hidden === "undefined") {
|
if (this.hidden === false || typeof this.hidden === 'undefined') {
|
||||||
force = true
|
force = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if (force) {
|
if (force) {
|
||||||
const element = document.createElement('section');
|
const element = document.createElement('section');
|
||||||
element.classList.add("node", "hide");
|
element.classList.add('node', 'hide');
|
||||||
|
|
||||||
|
const heading = this.buildSelf_Heading(this.name, toggleDisplay);
|
||||||
const heading = document.createElement('div');
|
const list = this.buildSelf_List(this.routes);
|
||||||
heading.innerText = this.name;
|
|
||||||
heading.addEventListener('click', toggleDisplay);
|
|
||||||
|
|
||||||
const list = document.createElement('ul');
|
|
||||||
// list.classList.add("hide");
|
|
||||||
this.routes.forEach(entry => {
|
|
||||||
const childEl = document.createElement('li');
|
|
||||||
const el = entry.buildSelf();
|
|
||||||
|
|
||||||
if (typeof el !== "undefined") {
|
|
||||||
childEl.appendChild(el);
|
|
||||||
}
|
|
||||||
|
|
||||||
list.appendChild(childEl);
|
|
||||||
});
|
|
||||||
|
|
||||||
element.appendChild(heading);
|
element.appendChild(heading);
|
||||||
element.appendChild(list);
|
element.appendChild(list);
|
||||||
@ -332,6 +317,45 @@ class RoutingNode extends RoutingItem {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buildSelf_Heading(text, onClickCallback) {
|
||||||
|
const wrapper = document.createElement('div');
|
||||||
|
const headingText = document.createElement('span');
|
||||||
|
const headingIcon = document.createElement('img');
|
||||||
|
|
||||||
|
headingText.innerText = text;
|
||||||
|
|
||||||
|
headingIcon.src = './assets/img/icons/baseline_expand_more_white_24dp.png';
|
||||||
|
|
||||||
|
wrapper.appendChild(headingText);
|
||||||
|
wrapper.appendChild(headingIcon);
|
||||||
|
|
||||||
|
if (typeof onClickCallback === "function") {
|
||||||
|
wrapper.addEventListener('click', onClickCallback);
|
||||||
|
}
|
||||||
|
|
||||||
|
return wrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Array.<(Route,RoutingNode)>} entries
|
||||||
|
*/
|
||||||
|
buildSelf_List(entries) {
|
||||||
|
const list = document.createElement('ul');
|
||||||
|
|
||||||
|
entries.forEach(entry => {
|
||||||
|
const listItem = document.createElement('li');
|
||||||
|
const itemContent = entry.buildSelf();
|
||||||
|
|
||||||
|
if (typeof itemContent !== 'undefined') {
|
||||||
|
listItem.appendChild(itemContent);
|
||||||
|
|
||||||
|
list.appendChild(listItem);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: find them a new home
|
// TODO: find them a new home
|
||||||
|
Loading…
x
Reference in New Issue
Block a user