-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dynamische menu in plaats van hard-coded in index.html
- Loading branch information
Showing
8 changed files
with
153 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
var CONF_builddate="20241116-202831" | ||
var CONF_builddate="20241117-113301" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
interface MenuItem { | ||
name: string; | ||
callback: () => void; | ||
} | ||
|
||
class TopMenu { | ||
private ulElement: HTMLUListElement; | ||
private liClassName: string; | ||
private menuItems: MenuItem[]; | ||
|
||
constructor(ulId: string, liClassName: string, menuItems: MenuItem[]) { | ||
this.ulElement = document.getElementById(ulId) as HTMLUListElement; | ||
this.liClassName = liClassName; | ||
this.menuItems = menuItems; | ||
|
||
this.renderMenu(); | ||
this.resetToFirstItem(); // Ensure the first item is selected initially | ||
} | ||
|
||
private renderMenu() { | ||
this.ulElement.innerHTML = ''; // Clear any existing content | ||
this.menuItems.forEach(item => { | ||
const liElement = document.createElement('li'); | ||
const aElement = document.createElement('a'); | ||
|
||
liElement.className = this.liClassName; | ||
aElement.innerText = item.name; | ||
|
||
aElement.addEventListener('click', () => { | ||
this.selectItem(aElement); | ||
item.callback(); | ||
}); | ||
|
||
liElement.appendChild(aElement); | ||
this.ulElement.appendChild(liElement); | ||
}); | ||
} | ||
|
||
private selectItem(selectedElement: HTMLAnchorElement) { | ||
// Remove 'current' ID from all <a> elements | ||
const items = this.ulElement.querySelectorAll('a'); | ||
items.forEach(item => item.removeAttribute('id')); | ||
|
||
// Add 'current' ID to the clicked <a> element | ||
selectedElement.id = 'current'; | ||
} | ||
|
||
public resetToFirstItem() { | ||
const firstItem = this.ulElement.querySelector('a'); | ||
if (firstItem) { | ||
this.selectItem(firstItem as HTMLAnchorElement); | ||
} | ||
} | ||
|
||
public selectMenuItemByName(name: string) { | ||
const item = this.menuItems.find(menuItem => menuItem.name === name); | ||
if (item) { | ||
const aElement = Array.from(this.ulElement.querySelectorAll('a')).find(a => a.innerText === name); | ||
if (aElement) { | ||
this.selectItem(aElement as HTMLAnchorElement); | ||
item.callback(); | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters