Skip to content

Commit d91656a

Browse files
committed
don't scroll when clicking on line numbers
1 parent e13b9d6 commit d91656a

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

Diff for: root/static/js/syntaxhighlighter.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,19 @@ $(function () {
150150

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

0 commit comments

Comments
 (0)