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
Maxime Magnier
TP3 - API DOM
Commits
34fa2735
Commit
34fa2735
authored
4 years ago
by
Maxime Magnier
Browse files
Options
Downloads
Patches
Plain Diff
blbl
parent
0d843c27
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Router.js
+15
-7
15 additions, 7 deletions
src/Router.js
src/main.js
+14
-7
14 additions, 7 deletions
src/main.js
with
29 additions
and
14 deletions
src/Router.js
+
15
−
7
View file @
34fa2735
...
@@ -2,19 +2,27 @@ export default class Router {
...
@@ -2,19 +2,27 @@ export default class Router {
static
titleElement
;
static
titleElement
;
static
contentElement
;
static
contentElement
;
static
routes
;
static
routes
;
static
#menuElement
;
static
set
menuElement
(
element
)
{
this
.
#menuElement
=
element
;
// 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é
}
#menuElement
;
static
navigate
(
path
)
{
static
navigate
(
path
)
{
const
route
=
this
.
routes
.
find
(
route
=>
route
.
path
===
path
);
const
route
=
this
.
routes
.
find
(
route
=>
route
.
path
===
path
);
if
(
route
)
{
if
(
route
)
{
this
.
titleElement
.
innerHTML
=
`<h1>
${
route
.
title
}
</h1>`
;
this
.
titleElement
.
innerHTML
=
`<h1>
${
route
.
title
}
</h1>`
;
this
.
contentElement
.
innerHTML
=
route
.
page
.
render
();
this
.
contentElement
.
innerHTML
=
route
.
page
.
render
();
route
.
page
.
mount
?.(
this
.
contentElement
);
}
}
}
static
set
menuElement
(
element
)
{
this
.
#menuElement
=
element
;
let
value
=
element
.
querySelectorAll
(
'
a
'
);
console
.
log
(
value
);
value
.
forEach
(
winnie
=>
{
winnie
.
addEventListener
(
'
click
'
,
event
=>
{
event
.
preventDefault
();
this
.
navigate
(
winnie
.
getAttribute
(
'
href
'
));
});
});
}
}
}
}
This diff is collapsed.
Click to expand it.
src/main.js
+
14
−
7
View file @
34fa2735
...
@@ -5,6 +5,8 @@ import Component from './components/Component.js';
...
@@ -5,6 +5,8 @@ import Component from './components/Component.js';
Router
.
titleElement
=
document
.
querySelector
(
'
.pageTitle
'
);
Router
.
titleElement
=
document
.
querySelector
(
'
.pageTitle
'
);
Router
.
contentElement
=
document
.
querySelector
(
'
.pageContent
'
);
Router
.
contentElement
=
document
.
querySelector
(
'
.pageContent
'
);
Router
.
menuElement
=
document
.
querySelector
(
'
.mainMenu
'
);
const
pizzaList
=
new
PizzaList
([]),
const
pizzaList
=
new
PizzaList
([]),
aboutPage
=
new
Component
(
'
section
'
,
null
,
'
Ce site est génial
'
),
aboutPage
=
new
Component
(
'
section
'
,
null
,
'
Ce site est génial
'
),
pizzaForm
=
new
Component
(
pizzaForm
=
new
Component
(
...
@@ -13,15 +15,20 @@ const pizzaList = new PizzaList([]),
...
@@ -13,15 +15,20 @@ const pizzaList = new PizzaList([]),
'
Ici vous pourrez ajouter une pizza
'
'
Ici vous pourrez ajouter une pizza
'
);
);
Router
.
routes
=
[{
path
:
'
/
'
,
page
:
pizzaList
,
title
:
'
La carte
'
}];
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
Router
.
navigate
(
'
/
'
);
// affiche une page vide
pizzaList
.
pizzas
=
data
;
pizzaList
.
pizzas
=
data
;
Router
.
navigate
(
'
/
'
);
// affiche la liste des pizzas
Router
.
navigate
(
'
/
'
);
// affiche la liste des pizzas
document
.
querySelector
(
'
.newsContainer
'
).
style
.
display
=
''
;
document
.
querySelector
(
'
.closeButton
'
).
addEventListener
(
'
click
'
,
event
=>
{
event
.
preventDefault
();
document
.
querySelector
(
'
.newsContainer
'
).
style
.
display
=
'
none
'
;
});
Router
.
menuElement
=
document
.
querySelector
(
'
.mainMenu
'
);
document
.
body
.
querySelector
(
'
.newsContainer
'
).
setAttribute
(
'
style
'
,
''
);
const
close
=
document
.
body
.
querySelector
(
'
.newsContainer .closeButton
'
);
close
.
addEventListener
(
'
click
'
,
event
=>
{
document
.
body
.
querySelector
(
'
.newsContainer
'
)
.
setAttribute
(
'
style
'
,
'
display:none
'
);
});
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