Skip to content

Commit e059bf4

Browse files
committed
don't scroll when clicking on line numbers
1 parent ded2ec9 commit e059bf4

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

root/static/js/syntaxhighlighter.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,19 @@ $(function () {
151151

152152
if (source.length) {
153153
source.find('.syntaxhighlighter .gutter .line').each(function(i, el) {
154+
var line = $(el);
154155
var res;
155-
if (res = el.className.match(/(^|\s)number(\d+)(\s|$)/)) {
156-
var id = 'L' + res[2];
157-
$(el).contents().wrap('<a href="#'+id+'" id="'+id+'"></a>');
156+
if (res = line.attr('class').match(/(^|\s)number(\d+)(\s|$)/)) {
157+
var linenr = res[2];
158+
var id = 'L' + linenr;
159+
line.contents().wrap('<a href="#'+id+'" id="'+id+'"></a>');
160+
var link = line.children('a');
161+
link.click(function(e) {
162+
e.preventDefault();
163+
link.removeAttr('id');
164+
document.location.hash = '#' + id;
165+
link.attr('id', id);
166+
});
158167
}
159168
});
160169

0 commit comments

Comments
 (0)