on master help sign in
Find content in cat/index
commitc318af168a7abdfc1401e46ae4ca88de2d290a7c authorDevine Lu Linvega <aliceffekt@gmail.com> dateMon 29 Jul 2019, 08:59 (7 years ago) parent2d12097
1 file changed+20−9
scripts/wiki.js+20−9
scripts/wiki.js+20−9
@@ -9,8 +9,8 @@ function Wiki (sites) {
99 this._sidebar.id = 'sidebar'
1010 this._categories = document.createElement('ul')
1111 this._categories.id = 'categories'
12− this._names = document.createElement('div')
13− this._names.id = 'names'
12+ this._entry = document.createElement('div')
13+ this._entry.id = 'entry'
1414
1515 this.loc = ''
1616 this.index = {}
@@ -19,7 +19,7 @@ function Wiki (sites) {
1919 this.install = (host) => {
2020 console.log('Wiki', 'Installing..')
2121 this.fetch()
22− this._el.appendChild(this._names)
22+ this._el.appendChild(this._entry)
2323 this._sidebar.appendChild(this._categories)
2424 this._el.appendChild(this._sidebar)
2525 host.appendChild(this._el)
@@ -32,12 +32,23 @@ function Wiki (sites) {
3232
3333 this.refresh = () => {
3434 console.log(Object.keys(this.index).length + ' terms')
35− // Sidebar
36− let html = ''
37− for (const id in this.categories) {
38− html += `<li onclick='wiki.go("${id}")' class='${wiki.at(id) ? 'selected' : ''}'>${id} <span class='right'>${this.categories[id].length}</span></li>`
35+ // Main
36+ if (this.loc) {
37+ if (this.categories[this.index]) {
38+ let html = `term: ${this.loc}`
39+ this._entry.innerHTML = html
40+ } else if (this.categories[this.loc]) {
41+ let html = `category: ${this.loc}`
42+ this._entry.innerHTML = html
43+ } else {
44+ let html = `Unknown: ${this.loc}`
45+ this._entry.innerHTML = html
46+ }
47+ } else {
48+ this._entry.innerHTML = 'Click a /topic to get started.'
3949 }
40− this._categories.innerHTML = `${html}`
50+ // Sidebar
51+ this._categories.innerHTML = Object.keys(this.categories).reduce((acc, id) => { return `${acc}<li onclick='wiki.go("${id}")' class='${wiki.at(id) ? 'selected' : ''}'>${id} <span class='right'>${this.categories[id].length}</span></li>` }, '')
4152 }
4253
4354 this.go = (q) => {
@@ -46,7 +57,7 @@ function Wiki (sites) {
4657 }
4758
4859 this.at = (q = '') => {
49− return this.loc.toLowerCase() === q.toLowerCase()
60+ return this.loc.toUpperCase() === q.toUpperCase()
5061 }
5162
5263 this.fetch = () => {