From 52695360f9f6a51a808480986e91d74dab09d2e1 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Sun, 24 Oct 2021 18:56:45 +0200 Subject: chore: print the projects list --- htdocs/src/js/app.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'htdocs') diff --git a/htdocs/src/js/app.js b/htdocs/src/js/app.js index 1b7bbc6..959bc56 100644 --- a/htdocs/src/js/app.js +++ b/htdocs/src/js/app.js @@ -1,5 +1,36 @@ +import projects from './config/projects'; import { isStyleJsExists } from './utilities/helpers'; +/** + * Create a list item for a project. + * @param {Integer} id - The project id. + * @param {String} name - The project name. + * @returns {HTMLElement} The list item. + */ +function getProjectsNavItem(id, name) { + const item = document.createElement('li'); + const link = document.createElement('a'); + link.classList.add('nav__link', 'nav__link--app'); + link.href = id; + link.id = id; + link.textContent = name; + item.classList.add('nav__item'); + item.appendChild(link); + return item; +} + +/** + * Print the list of available projects. + */ +function printProjectsNav() { + const ul = document.querySelector('.nav .nav__list'); + + projects.forEach((project) => { + const item = getProjectsNavItem(project.id, project.name); + ul.appendChild(item); + }); +} + /** * Add style.js script for development purposes. */ @@ -17,6 +48,7 @@ function loadWebpackStyles() { */ function init() { loadWebpackStyles(); + printProjectsNav(); } init(); -- cgit v1.2.3