@@ -45,20 +45,27 @@ function Wiki (sites) {
45 const html = `${this.templateTerm(this.loc, this.byName[this.loc])}<br />${this.templateRelated(this.loc)}`
45 const html = `${this.templateTerm(this.loc, this.byName[this.loc])}<br />${this.templateRelated(this.loc)}`
46 this._entry.innerHTML = html
46 this._entry.innerHTML = html
48− const html = `Unknown: ${this.loc}. Retun <a onclick='wiki.go("")'>home</a>, or try a <a onclick='wiki.go("${this.random()}")'>random page</a>.`
48+ const html = `Unknown: ${this.loc}. Retun <a href='#'>home</a>, or try a <a href='${this.random()}'>random page</a>.`
49 this._entry.innerHTML = html
49 this._entry.innerHTML = html
52− const random = this.random()
53− this._entry.innerHTML = `Click a /topic to get started, or try a <a href='#${random.toUrl()}' onclick='wiki.go("${random}")'>random page</a>.<br />The wiki contains ${Object.keys(this.byName).length} terms, in ${Object.keys(this.byCat).length} categories, by ${Object.keys(this.byAuthor).length} authors.`
52+ this._entry.innerHTML = `Click a /topic to get started, or try a <a href='#${this.random()}'>random page</a>.<br />The wiki contains ${Object.keys(this.byName).length} terms, in ${Object.keys(this.byCat).length} categories, by ${Object.keys(this.byAuthor).length} authors.`
55 // Sidebar
54 // Sidebar
56− this._categories.innerHTML = Object.keys(this.byCat).reduce((acc, id) => { return this.byCat[id].length > 5 ? `${acc}<li onclick='wiki.go("${id}")' class='${wiki.at(id) ? 'selected' : ''}'>${id.substr(0, 20)} <span class='right'>${this.byCat[id].length}</span></li>` : acc }, `<li onclick='wiki.go("")' class='${wiki.at() ? 'selected' : ''}'>home <span class='right'>${Object.keys(this.byName).length}</span></li>`)
55+ this._categories.innerHTML = Object.keys(this.byCat).reduce((acc, id) =>
56+ { return this.byCat[id].length > 5
57+ ? `${acc}<li ${wiki.at(id) ? 'class="selected"' : ''}>
58+ <a href='#${id}' data-msgs='${this.byCat[id].length}'>${id}</a>
61+ } , `<li ${wiki.at() ? 'class="selected"' : ''}>
62+ <a href='#' data-msgs='${Object.keys(this.byName).length}'>home</a>
59− this.go = (q = window.location.hash.substr(1).replace(/\+/g, ' ').toUpperCase()) => {
67+ this.go = () => {
61− window.location.hash = q.toUrl()
68+ this.loc = decodeURIComponent( window.location.hash.substr(1) ).toUpperCase()
62 this.refresh()
69 this.refresh()
@@ -81,7 +88,12 @@ function Wiki (sites) {
82 this.templateRelated = (name) => {
89 this.templateRelated = (name) => {
83 const relatedWords = this.related(name)
90 const relatedWords = this.related(name)
84− const html = `<ul class='col3'>${relatedWords.reduce((acc, item, id) => { return `${acc}<li onclick='wiki.go("${item.name}")' class='${wiki.at(item.name) ? 'selected' : ''}'>${item.name.toLowerCase()}</li>` }, '')}</ul>`
91+ const html = `<ul class='col3'>${relatedWords.reduce( (acc, item, id) =>
92+ { return `${acc}<li ${wiki.at(item.name) ? 'class="selected"' : ''}>
93+ <a href='#${item.name.toLowerCase()}'>${item.name.toLowerCase()}</a>
85 return html
97 return html
@@ -135,4 +147,8 @@ function Wiki (sites) {
137 String.prototype.toUrl = function () { return this.toLowerCase().replace(/ /g, '+').replace(/[^0-9a-z+:\-./~]/gi, '').trim() }
149 String.prototype.toUrl = function () { return this.toLowerCase().replace(/ /g, '+').replace(/[^0-9a-z+:\-./~]/gi, '').trim() }
151+ window.onload = this.go
152+ window.onhashchange = this.go