Scroll when the anchor change and is linking outside of the displayed content
This commit is contained in:
parent
c42d846add
commit
c5275027c3
1 changed files with 7 additions and 9 deletions
|
@ -149,7 +149,7 @@ function createSourceSidebar() {
|
||||||
|
|
||||||
var lineNumbersRegex = /^#?(\d+)(?:-(\d+))?$/;
|
var lineNumbersRegex = /^#?(\d+)(?:-(\d+))?$/;
|
||||||
|
|
||||||
function highlightSourceLines(scrollTo, match) {
|
function highlightSourceLines(match) {
|
||||||
if (typeof match === "undefined") {
|
if (typeof match === "undefined") {
|
||||||
match = window.location.hash.match(lineNumbersRegex);
|
match = window.location.hash.match(lineNumbersRegex);
|
||||||
}
|
}
|
||||||
|
@ -170,11 +170,9 @@ function highlightSourceLines(scrollTo, match) {
|
||||||
if (!elem) {
|
if (!elem) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (scrollTo) {
|
var x = document.getElementById(from);
|
||||||
var x = document.getElementById(from);
|
if (x) {
|
||||||
if (x) {
|
x.scrollIntoView();
|
||||||
x.scrollIntoView();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
onEachLazy(document.getElementsByClassName("line-numbers"), function(e) {
|
onEachLazy(document.getElementsByClassName("line-numbers"), function(e) {
|
||||||
onEachLazy(e.getElementsByTagName("span"), function(i_e) {
|
onEachLazy(e.getElementsByTagName("span"), function(i_e) {
|
||||||
|
@ -198,7 +196,7 @@ var handleSourceHighlight = (function() {
|
||||||
y = window.scrollY;
|
y = window.scrollY;
|
||||||
if (searchState.browserSupportsHistoryApi()) {
|
if (searchState.browserSupportsHistoryApi()) {
|
||||||
history.replaceState(null, null, "#" + name);
|
history.replaceState(null, null, "#" + name);
|
||||||
highlightSourceLines(true);
|
highlightSourceLines();
|
||||||
} else {
|
} else {
|
||||||
location.replace("#" + name);
|
location.replace("#" + name);
|
||||||
}
|
}
|
||||||
|
@ -230,7 +228,7 @@ var handleSourceHighlight = (function() {
|
||||||
window.addEventListener("hashchange", function() {
|
window.addEventListener("hashchange", function() {
|
||||||
var match = window.location.hash.match(lineNumbersRegex);
|
var match = window.location.hash.match(lineNumbersRegex);
|
||||||
if (match) {
|
if (match) {
|
||||||
return highlightSourceLines(false, match);
|
return highlightSourceLines(match);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -238,7 +236,7 @@ onEachLazy(document.getElementsByClassName("line-numbers"), function(el) {
|
||||||
el.addEventListener("click", handleSourceHighlight);
|
el.addEventListener("click", handleSourceHighlight);
|
||||||
});
|
});
|
||||||
|
|
||||||
highlightSourceLines(true);
|
highlightSourceLines();
|
||||||
|
|
||||||
window.createSourceSidebar = createSourceSidebar;
|
window.createSourceSidebar = createSourceSidebar;
|
||||||
})();
|
})();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue