From fa52d908f7668e06851a2f31d3a0f5c5dd2aaaba Mon Sep 17 00:00:00 2001
From: unknown <mohamed.bourdim.etu@univ-lille.fr>
Date: Tue, 9 Feb 2021 11:10:31 +0100
Subject: [PATCH] fin C

---
 package.json  |  2 +-
 src/Router.js | 15 ++++++++++++++-
 src/main.js   | 22 +++++++++++++++++++---
 3 files changed, 34 insertions(+), 5 deletions(-)

diff --git a/package.json b/package.json
index c41a110..abdfa61 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 7aef071..0d49216 100644
--- a/src/Router.js
+++ b/src/Router.js
@@ -2,7 +2,20 @@ export default class Router {
 	static titleElement;
 	static contentElement;
 	static routes = [];
-
+	
+	static #menuElement;
+	static set menuElement(element) {
+        this.#menuElement = element;
+        const link = document.querySelectorAll('header a');
+        for (let i = 0; i < link.length; i++) {
+            link[i].addEventListener('click', e => {
+                e.preventDefault();
+                console.log(link[i].getAttribute('href'));
+                Router.navigate(link[i].getAttribute('href'));
+            });
+        }
+    }
+	
 	static navigate(path) {
 		const route = this.routes.find(route => route.path === path);
 		if (route) {
diff --git a/src/main.js b/src/main.js
index 6148d2b..8a70fee 100644
--- a/src/main.js
+++ b/src/main.js
@@ -1,13 +1,29 @@
 import Router from './Router';
 import data from './data';
 import PizzaList from './pages/PizzaList';
-
+import Component from './components/Component';
 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' },
+];
 
+const link = document.querySelector('button'); // sélectionne le premier lien de la page
+
+link.addEventListener('click', event => {
+    event.preventDefault();
+    document.querySelector('section').setAttribute('style', 'display:none');
+    console.log(event);
+}); 
 Router.navigate('/'); // affiche une page vide
 pizzaList.pizzas = data;
 Router.navigate('/'); // affiche la liste des pizzas
+document.querySelector('section').setAttribute('style','');
+Router.menuElement = document.querySelector('.mainMenu');
+
-- 
GitLab