Skip to content
Snippets Groups Projects
Commit 87914e88 authored by Maxence Billiau's avatar Maxence Billiau :speech_balloon:
Browse files

Update 1st on click / On clic for pizza picture fix / add $ for JQuery variable

parent 57b3d64d
No related branches found
No related tags found
No related merge requests found
......@@ -2,8 +2,8 @@ import { lineBreak } from 'acorn';
import $ from 'jquery';
export default class Router {
static titleElement;
static contentElement;
static $titleElement;
static $contentElement;
/**
* Tableau des routes/pages de l'application.
* @example `Router.routes = [{ path: '/', page: pizzaList, title: 'La carte' }]`
......@@ -17,7 +17,7 @@ export default class Router {
* Écoute le clic sur chaque lien et déclenche la méthode navigate.
* @param element Élément HTML qui contient le menu principal
*/
static set menuElement(element) {
static set $menuElement(element) {
this.#menuElement = element;
const $links = $('a', this.#menuElement);
$links.on('click', event => {
......@@ -35,11 +35,11 @@ export default class Router {
const route = this.routes.find(route => route.path === path);
if (route) {
// rendu du titre
$(this.titleElement).html(`<h1>${route.title}</h1>`);
$(this.$titleElement).html(`<h1>${route.title}</h1>`);
// rendu de la page
$(this.contentElement).html(route.page.render());
$(this.$contentElement).html(route.page.render());
// initialisation de la page
route.page.mount?.(this.contentElement);
route.page.mount?.(this.$contentElement);
// Activation/désactivation des liens du menu
const $previousMenuLink = $('.active', this.#menuElement),
......
......@@ -15,9 +15,9 @@ Router.routes = [
{ path: '/a-propos', page: aboutPage, title: 'À propos' },
{ path: '/ajouter-pizza', page: pizzaForm, title: 'Ajouter une pizza' },
];
Router.titleElement = $('.pageTitle');
Router.contentElement = $('.pageContent');
Router.menuElement = $('.mainMenu');
Router.$titleElement = $('.pageTitle');
Router.$contentElement = $('.pageContent');
Router.$menuElement = $('.mainMenu');
// History API (gestion des boutons précédent/suivant du navigateur)
window.onpopstate = () => {
......@@ -48,6 +48,7 @@ fetch('./news.html')
//console.log($('.logo span'));
//$('.logo span').html('UwU<em>forever</em>');
//console.log($('.logo span').html());
$('.logo').on('click', function () {
$('.logo').on('click', event => {
event.preventDefault();
Router.navigate('/');
});
......@@ -23,9 +23,9 @@ export default class PizzaList extends Page {
}
addListeners(element) {
$('.pizzaList a', element).on('click', event => {
$('.pizzaList img', this.element).on('click', event => {
event.preventDefault();
console.log($(event.currentTarget).attr('href'));
console.log($(event.currentTarget).attr('src'));
});
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment