mirror of
https://github.com/tcsenpai/Zundler.git
synced 2025-06-07 03:55:26 +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 True if it worked
|
||||||
// return False if loading indicator should be removed right away
|
// return False if loading indicator should be removed right away
|
||||||
const file = window.global_context.file_tree[path];
|
const file = window.global_context.file_tree[path];
|
||||||
const data = file.data;
|
|
||||||
var iframe = createIframe();
|
var iframe = createIframe();
|
||||||
|
|
||||||
|
const data = file.data;
|
||||||
window.global_context.get_parameters = get_params;
|
window.global_context.get_parameters = get_params;
|
||||||
if (file.mime_type == 'text/html') {
|
if (file.mime_type == 'text/html') {
|
||||||
iframe.setAttribute("srcdoc", data);
|
iframe.setAttribute("srcdoc", data);
|
||||||
if (anchor) {
|
|
||||||
iframe.contentDocument.location.hash = anchor;
|
|
||||||
}
|
|
||||||
window.global_context.current_path = path;
|
window.global_context.current_path = path;
|
||||||
|
window.global_context.anchor = anchor;
|
||||||
window.history.pushState({path, get_params, anchor}, '', '#');
|
window.history.pushState({path, get_params, anchor}, '', '#');
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -64,6 +64,7 @@ var virtual_click = function(evnt) {
|
|||||||
} else {
|
} else {
|
||||||
console.error("Invalid element", el);
|
console.error("Invalid element", el);
|
||||||
}
|
}
|
||||||
|
|
||||||
path = normalize_path(path);
|
path = normalize_path(path);
|
||||||
|
|
||||||
window.parent.postMessage({
|
window.parent.postMessage({
|
||||||
@ -88,6 +89,8 @@ var fix_links = function() {
|
|||||||
var fix_link = function(a) {
|
var fix_link = function(a) {
|
||||||
if (is_virtual(a.getAttribute('href'))) {
|
if (is_virtual(a.getAttribute('href'))) {
|
||||||
a.addEventListener('click', virtual_click);
|
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: "",
|
argument: "",
|
||||||
}, '*');
|
}, '*');
|
||||||
}
|
}
|
||||||
|
if (window.global_context.anchor) {
|
||||||
|
document.location.href = "about:srcdoc#" + window.global_context.anchor;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user