This repository was archived by the owner on Oct 1, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathmenu.js
More file actions
164 lines (156 loc) · 3.95 KB
/
menu.js
File metadata and controls
164 lines (156 loc) · 3.95 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
const menu = {
'Home': {
'text': 'Home',
'href': 'index.html'
},
'Helpful-Material': {
'text': 'Helpful Material',
'href': 'helpful-material.html'
},
'Contributors': {
'text': 'Contributors',
'href': 'contributors.html'
},
'Tools': {
'text': 'Tools',
'href': 'tools.html',
'id': 'tools'
},
'Others': {
'Star Collector': {
'text': 'Star Collector',
'href': 'star-collector.html'
},
/*'Brazilian-Friends': {
'text': 'Brazilian Friends',
'href': 'brazilian-friends.html'
},
'Potato': {
'text': 'Potato',
'href': 'potato.html'
},*/
'Fireworks': {
'text': 'Fireworks',
'href': 'Fireworks.html',
'id': 'fireworks'
},
/*'Learn': {
'text': 'Learn!',
'href': 'wow.html',
'id': 'learn'
},
'4otakus': {
'text': '4otakus',
'href': '4otakus.html',
'id': '4otakus'
},
'Bubble': {
'text': 'Bubble',
'href': 'bubble.html',
'id': 'Bubble'
},
'Canoi': {
'text': 'Canoi',
'href': 'canoi.html',
'id': 'Canoi'
},*/
'Colorgame': {
'text': 'Colorgame',
'href': 'colorgame.html',
'id': 'Colorgame'
},
/*'Foxy': {
'text': 'Foxy',
'href': 'foxy.html',
'id': 'Foxy'
},*/
/*'cold-hacktomber': {
'text': 'cold-hacktomber',
'href': 'cold-hacktomber.html',
'id': 'cold-hacktomber'
},*/
'Gifheaven': {
'text': 'Gif Heaven',
'href': 'gifheaven.html',
'id': 'Gifheaven'
},
'Snek': {
'text': 'Snek',
'href': 'snek.html',
'id': 'Snek'
},
'Spooky': {
'text': 'Spooky',
'href': 'spooky.html',
'id': 'Spooky'
},
/*'Values': {
'text': 'Values',
'href': 'values.html',
'id': 'Values'
},*/
/*'Wow': {
'text': 'Wow',
'href': 'wow.html',
'id': 'Wow'
},*/
'Flappy': {
'text': 'Flappy Game',
'href': 'Flappy.html',
'id': 'Flappy'
},
'Stay Dry': {
'text': 'Stay Dry',
'href': '/dry',
'id': 'dry'
},
'Fancy CSS effects': {
'text': 'Fancy CSS',
'href': 'fancyCSS.html',
'id': 'fancy'
},
'Generative Art Canvas': {
'text': 'Generative Art Canvas',
'href': 'genart.html',
'id': 'generative'
}
}
}
function buildMenuHTML (obj = {}) {
var html = ''
var path = window.location.pathname.split('/')
var currentPage = path[path.length - 1] === '' ? '/' : path[path.length - 1]
var isIndexPage = currentPage === '/' || currentPage === 'index.html';
Object.entries(obj).forEach(([key, item]) => {
if (key == 'Others') {
html += '<li class="dropdown">'
html += '<a class="nav-link nested-dropdown" href="#" id="Others" onclick="return false;"> Others ▼ </a>'
html += '<div class="dropdown-content">'
// if(isIndexPage){
// html += '<div class="nav-item">'
// html += '<button class="nav-link nav-invert-btn" id="invert-btn">Invert</button>'
// html += '</div>'
// }
Object.entries(item).forEach(([key, item]) => {
let isCurrent = (currentPage === item.href)
html += '<div class="nav-item' + (isCurrent ? ' active' : '') + '">'
html += '<a class="nav-link" href="' + item.href + '"' + (item.id ? ' id="' + item.id + '"' : '') + '>' + item.text + '</a>'
html += '</div>'
})
html += '</div>'
} else {
if (currentPage.indexOf('.html') == -1) {
currentPage = currentPage.concat('.html');
}
let isCurrent = (currentPage === item.href)
html += '<li class="nav-item' + (isCurrent ? ' active' : '') + '">'
html += '<a class="nav-link" href="' + item.href + '"' + (item.id ? ' id="' + item.id + '"' : '') + '>' + item.text + '</a>'
html += '</li>'
}
})
document.getElementById('menu').innerHTML = html
}
function buildMenu () {
return buildMenuHTML(menu)
}
buildMenu()