-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathheader-element.js
More file actions
67 lines (64 loc) · 2.33 KB
/
header-element.js
File metadata and controls
67 lines (64 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import {TelepathicElement} from "../telepathic-element/telepathic-element.js";
export default class HeaderElement extends TelepathicElement{
static describe(){ return `HeaderElement is used to provide a consistent header that is databound and themeable`};
constructor(){
super(null,true);
this.headerText = `Play with telepathic-elements`;
}
init(){return};
async onReady(){
if(this.getAttribute("nav-map")){
this.navMapFileName = this.getAttribute("nav-map");
}else{
this.navMapFileName = 'navigation.json';
}
await this.parseNavFile(this.navMapContents);
await this.makeNav();
await this.update();
}
//Call this to start the chain of events from a new file
async parseNavFile(navMapFileName){
if(navMapFileName){
this.navMapFileName = navMapFileName;
}
this.navMap = await this.loadFileJSON(this.navMapFileName);
console.log("navMap: ",this.navMap);
return this;
}
//Call this to start the chain of events from a new navMap object
makeNav(navMap){
if(navMap){
this.navMap = navMap;
}
//A navMap is an array of navItems in their Object form
//Each element contains, .name, .loc, .priority, .visibility, .text
this.navItems = [];
for(let item of this.navMap){
let li = document.createElement("li");
li.setAttribute("class","nav-item");
let a = document.createElement("a");
a.setAttribute("href",item.url);
a.innerHTML = item.txt;
li.appendChild(a);
this.navItems.push(li);
}
return this;
}
update(){
this.header = this.$.querySelector('header');
this.navUpper = this.header.querySelector('nav');
this.nav = this.navUpper.querySelector("#nav-menu-ul");
if(!this.nav){
this.nav = document.createElement('ul');
this.navUpper.appendChild(this.nav);
}
while(this.nav.firstChild) {
this.nav.removeChild(this.nav.firstChild);
}
for(let navItem of this.navItems){
console.log("Setting: ",navItem);
this.nav.appendChild(navItem);
console.log("this.nav: ",this.nav);
}
}
}