|
50 | 50 | resizeShortBlocks(); |
51 | 51 | $(window).on('resize', resizeShortBlocks); |
52 | 52 |
|
53 | | - function highlightSourceLines() { |
| 53 | + function highlightSourceLines(ev) { |
54 | 54 | var i, from, to, match = window.location.hash.match(/^#?(\d+)(?:-(\d+))?$/); |
55 | 55 | if (match) { |
56 | 56 | from = parseInt(match[1], 10); |
|
59 | 59 | if ($('#' + from).length === 0) { |
60 | 60 | return; |
61 | 61 | } |
62 | | - $('#' + from)[0].scrollIntoView(); |
| 62 | + if (ev === null) $('#' + from)[0].scrollIntoView(); |
63 | 63 | $('.line-numbers span').removeClass('line-highlighted'); |
64 | 64 | for (i = from; i <= to; ++i) { |
65 | 65 | $('#' + i).addClass('line-highlighted'); |
66 | 66 | } |
67 | 67 | } |
68 | 68 | } |
69 | | - highlightSourceLines(); |
| 69 | + highlightSourceLines(null); |
70 | 70 | $(window).on('hashchange', highlightSourceLines); |
71 | 71 |
|
72 | 72 | $(document).on('keyup', function(e) { |
|
778 | 778 | $("#main > .docblock").before(wrapper); |
779 | 779 | }); |
780 | 780 |
|
| 781 | + $('pre.line-numbers').on('click', 'span', function() { |
| 782 | + var prev_id = 0; |
| 783 | + |
| 784 | + function set_fragment(name) { |
| 785 | + if (history.replaceState) { |
| 786 | + history.replaceState(null, null, '#' + name); |
| 787 | + $(window).trigger('hashchange'); |
| 788 | + } else { |
| 789 | + location.replace('#' + name); |
| 790 | + } |
| 791 | + } |
| 792 | + |
| 793 | + return function(ev) { |
| 794 | + var cur_id = parseInt(ev.target.id); |
| 795 | + |
| 796 | + if (ev.shiftKey && prev_id) { |
| 797 | + if (prev_id > cur_id) { |
| 798 | + var tmp = prev_id; |
| 799 | + prev_id = cur_id; |
| 800 | + cur_id = tmp; |
| 801 | + } |
| 802 | + |
| 803 | + set_fragment(prev_id + '-' + cur_id); |
| 804 | + } else { |
| 805 | + prev_id = cur_id; |
| 806 | + |
| 807 | + set_fragment(cur_id); |
| 808 | + } |
| 809 | + }; |
| 810 | + }()); |
| 811 | + |
781 | 812 | }()); |
0 commit comments