Commit a9a5490c authored by Jens Ehlers's avatar Jens Ehlers
Browse files

#2 back and forward navigation

parent 9577511b
Pipeline #8050 passed with stage
in 1 minute and 9 seconds
...@@ -24,6 +24,11 @@ ...@@ -24,6 +24,11 @@
displayUnit(document.location.hash); displayUnit(document.location.hash);
$(".dropdown-item").on("click", function() { displayUnit('#'+$(this).attr("id")); }); $(".dropdown-item").on("click", function() { displayUnit('#'+$(this).attr("id")); });
// back and forward navigation
window.onhashchange = function() {
displayUnit(document.location.hash);
};
$("label").prepend("Abb.: "); $("label").prepend("Abb.: ");
$(".source").each(function() { $(".source").each(function() {
var source = $(this).html(); var source = $(this).html();
...@@ -41,7 +46,6 @@ ...@@ -41,7 +46,6 @@
var filename = $(this).attr('id'); var filename = $(this).attr('id');
$(this).load(filename + '.html', function() { // try this with $.get $(this).load(filename + '.html', function() { // try this with $.get
Prism.highlightAll(); Prism.highlightAll();
$(".navigate").on("click", function() { displayUnit($(this).attr("href")); });
// add repo links // add repo links
$("#" + filename + " .repo-link").each(function() { $("#" + filename + " .repo-link").each(function() {
...@@ -80,16 +84,8 @@ ...@@ -80,16 +84,8 @@
search($(this).val().toLowerCase()); search($(this).val().toLowerCase());
}); });
$('#search input').keypress(function(e) { $('#search input').keypress(function(e) {
if (e.which == 13) { // enter key if (e.which == 13) { // enter key
search($(this).val().toLowerCase()); search($(this).val().toLowerCase());
}
});
// literature links
$(document).on('click tap', 'a', function() {
var href = $(this).attr("href");
if (typeof href !== "undefined" && href.startsWith("#cite-")) {
displayUnit('#unit-goals');
} }
}); });
...@@ -114,10 +110,14 @@ ...@@ -114,10 +110,14 @@
function displayUnit(id) { function displayUnit(id) {
if (id == "#undefined") return; if (id == "#undefined") return;
document.location.hash = id; document.location.hash = id;
var id_nohash = id.substring(1);
$("[id^=content-unit-]").hide(); $("[id^=content-unit-]").hide();
var id_nohash = id.substring(1);
if (id.startsWith("#cite-")) id_nohash = 'unit-goals';
$("#content-"+id_nohash).show(); $("#content-"+id_nohash).show();
window.scrollTo(0, 0);
var top = (id.startsWith("#cite-") && $(id).offset() !== undefined) ? $(id).offset().top : 0;
window.scrollTo(0, top);
} }
function search(searchTerm) { function search(searchTerm) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment