diff --git a/package.json b/package.json index c41a110ca19262f50af831518d2d2dc6098b0615..abdfa619e9426f7c982feea585be7add72473e18 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "build": "webpack --mode=production", - "watch": "webpack --mode=development --watch" + "watch": "webpack --mode=development --watch" }, "author": "Thomas Fritsch <thomas.fritsch@univ-lille.fr> (https://gitlab.univ-lille.fr/thomas.fritsch)", "homepage": "https://gitlab.univ-lille.fr/js", diff --git a/src/Router.js b/src/Router.js index 7aef0711884fbc5af076fc2d62abd4dc61ad0d00..b9f4deabf0d6d8e2359edce5a9531513b63ab0a4 100644 --- a/src/Router.js +++ b/src/Router.js @@ -1,7 +1,10 @@ +import { doc } from 'prettier'; + export default class Router { static titleElement; static contentElement; static routes = []; + static #menuElement; static navigate(path) { const route = this.routes.find(route => route.path === path); @@ -10,4 +13,18 @@ export default class Router { this.contentElement.innerHTML = route.page.render(); } } + + static set menuElement(element) { + this.#menuElement = element; + let value = element.querySelectorAll('a'); + value.forEach(elem => { + console.log(elem); + elem.addEventListener('click', event => { + console.log('event'); + }); + }); + // au clic sur n'importe quel lien contenu dans "element" + // déclenchez un appel à Router.navigate(path) + // où "path" est la valeur de l'attribut `href=".."` du lien cliqué + } } diff --git a/src/main.js b/src/main.js index 6148d2ba698b9b4314ca2f4afde288b429439f04..864405f9e77c2049c2d811e5d25bc3148d1c8e78 100644 --- a/src/main.js +++ b/src/main.js @@ -1,13 +1,33 @@ import Router from './Router'; import data from './data'; +import Component from './components/Component.js'; import PizzaList from './pages/PizzaList'; +import { doc } from 'prettier'; Router.titleElement = document.querySelector('.pageTitle'); Router.contentElement = document.querySelector('.pageContent'); -const pizzaList = new PizzaList([]); -Router.routes = [{ path: '/', page: pizzaList, title: 'La carte' }]; +const pizzaList = new PizzaList([]), + aboutPage = new Component('section', null, 'Ce site est génial'), + pizzaForm = new Component( + 'section', + null, + 'Ici vous pourrez ajouter une pizza' + ); +Router.routes = [ + { path: '/', page: pizzaList, title: 'La carte' }, + { path: '/a-propos', page: aboutPage, title: 'À propos' }, + { path: '/ajouter-pizza', page: pizzaForm, title: 'Ajouter une pizza' }, +]; Router.navigate('/'); // affiche une page vide pizzaList.pizzas = data; Router.navigate('/'); // affiche la liste des pizzas + +document.body.children[1].setAttribute('style', ''); +const link = document.querySelector('.newsContainer .closeButton'); +link.addEventListener('click', event => { + document.body.children[1].setAttribute('style', 'display:none'); +}); + +Router.menuElement = document.querySelector('.mainMenu');