on master help sign in
Clickable categories
commit2d120978fe46ae46276d0609f614a056b7348a33 authorDevine Lu Linvega <aliceffekt@gmail.com> dateMon 29 Jul 2019, 08:51 (7 years ago) parente9834ee
1 file changed+12−4
scripts/wiki.js+12−4
scripts/wiki.js+12−4
@@ -12,6 +12,7 @@ function Wiki (sites) {
1212 this._names = document.createElement('div')
1313 this._names.id = 'names'
1414
15+ this.loc = ''
1516 this.index = {}
1617 this.categories = {}
1718
@@ -31,16 +32,23 @@ function Wiki (sites) {
3132
3233 this.refresh = () => {
3334 console.log(Object.keys(this.index).length + ' terms')
34−
35− // Cats
36−
35+ // Sidebar
3736 let html = ''
3837 for (const id in this.categories) {
39− html += `<li>${id} <span class='right'>${this.categories[id].length}</span></li>`
38+ html += `<li onclick='wiki.go("${id}")' class='${wiki.at(id) ? 'selected' : ''}'>${id} <span class='right'>${this.categories[id].length}</span></li>`
4039 }
4140 this._categories.innerHTML = `${html}`
4241 }
4342
43+ this.go = (q) => {
44+ this.loc = q
45+ this.refresh()
46+ }
47+
48+ this.at = (q = '') => {
49+ return this.loc.toLowerCase() === q.toLowerCase()
50+ }
51+
4452 this.fetch = () => {
4553 console.log('Wiki', 'Fetching..')
4654 for (const site of sites) {