Commit 4cd0e7ebc99a154fda9b7d201aaf74a5dd9ba62f
Highlight element targeted by location hash
Charles Lehner committed on 4/2/2016, 3:04:17 AMParent: e92c15b1dae34409fb4c17abf69cce004e58f89c
Files changed
index.js | changed |
static/styles.css | changed |
index.js | ||
---|---|---|
@@ -416,8 +416,22 @@ | ||
416 | 416 | } |
417 | 417 | } |
418 | 418 | }.toString() + ')()' |
419 | 419 | |
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 | + | |
420 | 434 | var msgTypes = { |
421 | 435 | 'git-repo': true, |
422 | 436 | 'git-update': true, |
423 | 437 | 'issue': true |
@@ -717,9 +731,9 @@ | ||
717 | 731 | buf = buf.toString('utf8') |
718 | 732 | if (err) return cb(err) |
719 | 733 | cb(null, (ext == 'md' || ext == 'markdown') |
720 | 734 | ? markdown(buf, repo) |
721 | - : renderCodeTable(buf, ext)) | |
735 | + : renderCodeTable(buf, ext) + hashHighlightScript) | |
722 | 736 | }) |
723 | 737 | }) |
724 | 738 | } |
725 | 739 | |
@@ -1349,9 +1363,9 @@ | ||
1349 | 1363 | encodeLink([repo.id, 'blob', commitId].concat(item.path)))) |
1350 | 1364 | }) |
1351 | 1365 | }, 4) |
1352 | 1366 | ), |
1353 | - pull.once('</section>'), | |
1367 | + pull.once('</section>' + hashHighlightScript), | |
1354 | 1368 | ]) |
1355 | 1369 | } |
1356 | 1370 | |
1357 | 1371 | function htmlLineDiff(filename, anchor, oldStr, newStr, blobHref, rawHref) { |
Built with git-ssb-web