Skip to content

Commit

Permalink
Merge pull request #106 from nishidayuya/anchor_for_line_number
Browse files Browse the repository at this point in the history
Implement line number anchor
  • Loading branch information
amatsuda authored Oct 29, 2023
2 parents 0838045 + eecec23 commit 3fa764a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 10 deletions.
27 changes: 25 additions & 2 deletions assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,29 @@ $(document).ready(function () {
}
});

// Set-up of anchor of linenumber
$('.source_table li[data-linenumber]').click(function () {
$('#cboxLoadedContent').scrollTop(this.offsetTop);
var new_anchor = curr_anchor.replace(/-.*/, '') + '-L' + $(this).data('linenumber');
window.location.replace(window.location.href.replace(/#.*/, '#' + new_anchor));
curr_anchor = new_anchor;
return false;
});

window.onpopstate = function (event) {
if (window.location.hash.substring(0, 2) == "#_") {
$.colorbox.close();
curr_anchor = window.location.hash.substring(1);
} else {
if ($('#colorbox').is(':hidden')) {
$('a.src_link[href="' + window.location.hash + '"]').colorbox({ open: true });
var anchor = window.location.hash.substring(1);
var ary = anchor.split('-L');
var source_file_id = ary[0];
var linenumber = ary[1];
$('a.src_link[href="#' + source_file_id + '"]').colorbox({ open: true });
if (linenumber !== undefined) {
$('#cboxLoadedContent').scrollTop($('#cboxLoadedContent .source_table li[data-linenumber="' + linenumber + '"]')[0].offsetTop);
}
}
}
};
Expand Down Expand Up @@ -106,8 +122,15 @@ $(document).ready(function () {

if (window.location.hash) {
var anchor = window.location.hash.substring(1);
if (anchor.length == 40) {
if (anchor.length === 40) {
$('a.src_link[href="#' + anchor + '"]').click();
} else if (anchor.length > 40) {
var ary = anchor.split('-L');
var source_file_id = ary[0];
var linenumber = ary[1];
$('a.src_link[href="#' + source_file_id + '"]').colorbox({ open: true });
// Scroll to anchor of linenumber
$('#' + source_file_id + ' li[data-linenumber="' + linenumber + '"]').click();
} else {
$('.group_tabs a.' + anchor.replace('_', '')).click();
}
Expand Down
5 changes: 5 additions & 0 deletions assets/stylesheets/screen.css
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@ td.strong {
border-left: 5px solid white;
}

.source_table pre li:hover {
cursor: pointer;
text-decoration: underline black;
}

.source_table pre li code {
white-space: pre;
white-space: pre-wrap;
Expand Down
2 changes: 1 addition & 1 deletion public/application.css

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions public/application.js

Large diffs are not rendered by default.

0 comments on commit 3fa764a

Please sign in to comment.