git ssb

30+

cel / git-ssb-web



Commit 4cd0e7ebc99a154fda9b7d201aaf74a5dd9ba62f

Highlight element targeted by location hash

Charles Lehner committed on 4/2/2016, 3:04:17 AM
Parent: e92c15b1dae34409fb4c17abf69cce004e58f89c

Files changed

index.jschanged
static/styles.csschanged
index.jsView
@@ -416,8 +416,22 @@
416416 }
417417 }
418418 }.toString() + ')()'
419419
420+var hashHighlightScript = '<script>(' + function () {
421+ var activeEl
422+ function onHashChange() {
423+ var el = document.getElementById(location.hash.substr(1))
424+ if (activeEl)
425+ activeEl.classList.remove('active-hash')
426+ if (el)
427+ el.classList.add('active-hash')
428+ activeEl = el
429+ }
430+ onHashChange()
431+ window.addEventListener('hashchange', onHashChange, false)
432+}.toString() + ')()</script>'
433+
420434 var msgTypes = {
421435 'git-repo': true,
422436 'git-update': true,
423437 'issue': true
@@ -717,9 +731,9 @@
717731 buf = buf.toString('utf8')
718732 if (err) return cb(err)
719733 cb(null, (ext == 'md' || ext == 'markdown')
720734 ? markdown(buf, repo)
721- : renderCodeTable(buf, ext))
735+ : renderCodeTable(buf, ext) + hashHighlightScript)
722736 })
723737 })
724738 }
725739
@@ -1349,9 +1363,9 @@
13491363 encodeLink([repo.id, 'blob', commitId].concat(item.path))))
13501364 })
13511365 }, 4)
13521366 ),
1353- pull.once('</section>'),
1367+ pull.once('</section>' + hashHighlightScript),
13541368 ])
13551369 }
13561370
13571371 function htmlLineDiff(filename, anchor, oldStr, newStr, blobHref, rawHref) {
static/styles.cssView
@@ -339,8 +339,9 @@
339339 .code td {
340340 padding: 0 1ex 0;
341341 }
342342
343+tr.active-hash,
343344 .code tr:hover {
344345 background-color: #fff8d2;
345346 }
346347

Built with git-ssb-web