Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
TP3 - API DOM
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
Mohamed Bourdim
TP3 - API DOM
Commits
fa52d908
Commit
fa52d908
authored
4 years ago
by
Mohamed Bourdim
Browse files
Options
Downloads
Patches
Plain Diff
fin C
parent
f98a536c
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
package.json
+1
-1
1 addition, 1 deletion
package.json
src/Router.js
+14
-1
14 additions, 1 deletion
src/Router.js
src/main.js
+19
-3
19 additions, 3 deletions
src/main.js
with
34 additions
and
5 deletions
package.json
+
1
−
1
View file @
fa52d908
This diff is collapsed.
Click to expand it.
src/Router.js
+
14
−
1
View file @
fa52d908
...
...
@@ -3,6 +3,19 @@ export default class Router {
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
)
{
...
...
This diff is collapsed.
Click to expand it.
src/main.js
+
19
−
3
View file @
fa52d908
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
'
);
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