Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
TP5 - jQuery
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maxence Billiau
TP5 - jQuery
Commits
87914e88
Commit
87914e88
authored
3 years ago
by
Maxence Billiau
Browse files
Options
Downloads
Patches
Plain Diff
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
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/Router.js
+6
-6
6 additions, 6 deletions
src/Router.js
src/main.js
+5
-4
5 additions, 4 deletions
src/main.js
src/pages/PizzaList.js
+2
-2
2 additions, 2 deletions
src/pages/PizzaList.js
with
13 additions
and
12 deletions
src/Router.js
+
6
−
6
View file @
87914e88
...
...
@@ -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
),
...
...
This diff is collapsed.
Click to expand it.
src/main.js
+
5
−
4
View file @
87914e88
...
...
@@ -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
(
'
/
'
);
});
This diff is collapsed.
Click to expand it.
src/pages/PizzaList.js
+
2
−
2
View file @
87914e88
...
...
@@ -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
'
));
});
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment