on master help sign in
Merge pull request #249 from dym-sh/master

[wiki] fixed sidebar and navigation

commit66a27369f7f3155bb489fab8dfff24df4d928da4 authorChris <ckipp@pm.me> dateThu 8 Aug 2019, 18:17 (7 years ago) parentc000e9e2b9ddf9
2 files changed+29−8
links/main.css+5 scripts/wiki.js+24−8
links/main.css+5
@@ -86,6 +86,11 @@ body #wiki { background: #ccc; color:#333; }
8686body #wiki #entry { max-width: calc(100% - 230px); margin-bottom: 30px; line-height: 15px }
8787body #wiki #entry a { text-decoration: underline; }
8888body #wiki #sidebar { overflow-y: scroll; height: calc(100% - 15px); }
89+body #wiki #sidebar a { display: inline-block; width: 120px; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; padding: 7px; }
90+body #wiki #sidebar li { line-height: 7px; }
91+body #wiki #sidebar li:before { display: none; }
92+body #wiki #sidebar a:before { content: '/'; }
93+body #wiki #sidebar a:after { content: attr(data-msgs) " msgs"; position: absolute; right: 20px; color:#555; }
8994body #wiki ul.term { border-bottom: 0px; margin-bottom: 0px; padding-bottom: 0px}
9095body #wiki ul.term li { margin-bottom: 5px }
9196body #wiki ul.term li.name { margin-bottom: 5px }
scripts/wiki.js+24−8
@@ -45,20 +45,27 @@ function Wiki (sites) {
4545 const html = `${this.templateTerm(this.loc, this.byName[this.loc])}<br />${this.templateRelated(this.loc)}`
4646 this._entry.innerHTML = html
4747 } else {
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>.`
4949 this._entry.innerHTML = html
5050 }
5151 } else {
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.`
5453 }
5554 // 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>
59+ </li>`
60+ : acc
61+ } , `<li ${wiki.at() ? 'class="selected"' : ''}>
62+ <a href='#' data-msgs='${Object.keys(this.byName).length}'>home</a>
63+ </li>`
64+ )
5765 }
5866
59− this.go = (q = window.location.hash.substr(1).replace(/\+/g, ' ').toUpperCase()) => {
60− this.loc = q
61− window.location.hash = q.toUrl()
67+ this.go = () => {
68+ this.loc = decodeURIComponent( window.location.hash.substr(1) ).toUpperCase()
6269 this.refresh()
6370 }
6471
@@ -81,7 +88,12 @@ function Wiki (sites) {
8188
8289 this.templateRelated = (name) => {
8390 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>
94+ </li>`
95+ }, '') }
96+ </ul>`
8597 return html
8698 }
8799
@@ -135,4 +147,8 @@ function Wiki (sites) {
135147 }
136148
137149 String.prototype.toUrl = function () { return this.toLowerCase().replace(/ /g, '+').replace(/[^0-9a-z+:\-./~]/gi, '').trim() }
150+
151+ window.onload = this.go
152+ window.onhashchange = this.go
138153}
154+