Highlight line numbers of the lines referred to in the url hash

This commit is contained in:
Jordi Boggiano 2013-10-02 19:32:13 +02:00 committed by Alex Crichton
parent aaeb7605c9
commit 1501d65112
2 changed files with 22 additions and 0 deletions

View File

@ -121,6 +121,9 @@ body {
.content pre.line-numbers { float: left; border: none; }
.line-numbers span { color: #c67e2d; }
.line-numbers .line-highlighted {
background-color: #fff871;
}
.content .highlighted {
cursor: pointer;

View File

@ -31,6 +31,25 @@
resizeShortBlocks();
$(window).on('resize', resizeShortBlocks);
function highlightSourceLines() {
var i, from, to, match = window.location.hash.match(/^#?(\d+)(?:-(\d+))?$/);
if (match) {
from = parseInt(match[1], 10);
to = Math.min(50000, parseInt(match[2] || match[1], 10));
from = Math.min(from, to);
if ($('#' + from).length === 0) {
return;
}
$('#' + from)[0].scrollIntoView();
$('.line-numbers span').removeClass('line-highlighted');
for (i = from; i <= to; i += 1) {
$('#' + i).addClass('line-highlighted');
}
}
}
highlightSourceLines();
$(window).on('hashchange', highlightSourceLines);
$(document).on('keyup', function (e) {
if (document.activeElement.tagName === 'INPUT') {
return;