mirror of
https://git.leinelab.org/Mal/mr-crocs-adventures.git
synced 2025-09-11 02:57:36 +02:00
Main menu and save function to json file implemented.
This commit is contained in:
27
tilorswift/js/menu/MainMenu.js
Normal file
27
tilorswift/js/menu/MainMenu.js
Normal file
@@ -0,0 +1,27 @@
|
||||
export default class MainMenu
|
||||
{
|
||||
constructor(id)
|
||||
{
|
||||
this.id = id;
|
||||
this.menuGroups = [];
|
||||
}
|
||||
|
||||
addMenuGroup(group)
|
||||
{
|
||||
this.menuGroups.push(group);
|
||||
}
|
||||
|
||||
getElement()
|
||||
{
|
||||
let htmlElement = document.createElement('div');
|
||||
htmlElement.id = this.id;
|
||||
|
||||
this.menuGroups.forEach(
|
||||
(group) =>{
|
||||
htmlElement.appendChild(group.getElement());
|
||||
}
|
||||
);
|
||||
|
||||
return htmlElement;
|
||||
}
|
||||
}
|
||||
22
tilorswift/js/menu/MainMenuEntry.js
Normal file
22
tilorswift/js/menu/MainMenuEntry.js
Normal file
@@ -0,0 +1,22 @@
|
||||
export default class MainMenuEntry
|
||||
{
|
||||
constructor(title, event)
|
||||
{
|
||||
this.title = title;
|
||||
this.event = event;
|
||||
}
|
||||
|
||||
getElement()
|
||||
{
|
||||
let htmlElement = document.createElement('li');
|
||||
htmlElement.innerText = this.title;
|
||||
htmlElement.addEventListener(
|
||||
'click',
|
||||
() => {
|
||||
window.dispatchEvent(new this.event());
|
||||
}
|
||||
);
|
||||
|
||||
return htmlElement;
|
||||
}
|
||||
}
|
||||
34
tilorswift/js/menu/MenuGroup.js
Normal file
34
tilorswift/js/menu/MenuGroup.js
Normal file
@@ -0,0 +1,34 @@
|
||||
export default class MenuGroup
|
||||
{
|
||||
className = 'menu-group';
|
||||
|
||||
constructor(title)
|
||||
{
|
||||
this.title = title;
|
||||
this.menuEntries = [];
|
||||
}
|
||||
|
||||
addMenuEntry(entry)
|
||||
{
|
||||
this.menuEntries.push(entry);
|
||||
}
|
||||
|
||||
getElement()
|
||||
{
|
||||
let htmlElement = document.createElement('div');
|
||||
htmlElement.classList.add(this.className);
|
||||
htmlElement.innerText = this.title;
|
||||
|
||||
let dropdown = document.createElement('ul');
|
||||
dropdown.classList.add('menu-dropdown');
|
||||
htmlElement.appendChild(dropdown);
|
||||
|
||||
this.menuEntries.forEach(
|
||||
(entry) => {
|
||||
dropdown.appendChild(entry.getElement());
|
||||
}
|
||||
);
|
||||
|
||||
return htmlElement;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user