mirror of
https://github.com/tcsenpai/Zundler.git
synced 2025-06-06 11:35:40 +00:00
Fix anchor links
This commit is contained in:
parent
351582e055
commit
eb0e4110a8
@ -59,15 +59,14 @@ var load_virtual_page = (function (path, get_params, anchor) {
|
||||
// return True if it worked
|
||||
// return False if loading indicator should be removed right away
|
||||
const file = window.global_context.file_tree[path];
|
||||
const data = file.data;
|
||||
var iframe = createIframe();
|
||||
|
||||
const data = file.data;
|
||||
window.global_context.get_parameters = get_params;
|
||||
if (file.mime_type == 'text/html') {
|
||||
iframe.setAttribute("srcdoc", data);
|
||||
if (anchor) {
|
||||
iframe.contentDocument.location.hash = anchor;
|
||||
}
|
||||
window.global_context.current_path = path;
|
||||
window.global_context.anchor = anchor;
|
||||
window.history.pushState({path, get_params, anchor}, '', '#');
|
||||
return true;
|
||||
} else {
|
||||
|
@ -64,6 +64,7 @@ var virtual_click = function(evnt) {
|
||||
} else {
|
||||
console.error("Invalid element", el);
|
||||
}
|
||||
|
||||
path = normalize_path(path);
|
||||
|
||||
window.parent.postMessage({
|
||||
@ -88,6 +89,8 @@ var fix_links = function() {
|
||||
var fix_link = function(a) {
|
||||
if (is_virtual(a.getAttribute('href'))) {
|
||||
a.addEventListener('click', virtual_click);
|
||||
} else if (a.getAttribute('href').startsWith('#')) {
|
||||
a.setAttribute('href', "about:srcdoc" + a.getAttribute('href'))
|
||||
}
|
||||
};
|
||||
|
||||
@ -210,6 +213,9 @@ window.addEventListener("message", (evnt) => {
|
||||
argument: "",
|
||||
}, '*');
|
||||
}
|
||||
if (window.global_context.anchor) {
|
||||
document.location.href = "about:srcdoc#" + window.global_context.anchor;
|
||||
}
|
||||
}
|
||||
}, false);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user