mirror of
https://github.com/tcsenpai/Zundler.git
synced 2025-06-06 11:35:40 +00:00
Rename data -> global_context
This commit is contained in:
parent
9bb1e6f3ae
commit
b01c034420
@ -35,37 +35,37 @@ var createIframe = function() {
|
||||
}
|
||||
|
||||
var load_virtual_page = (function (path, get_params, anchor) {
|
||||
const data = window.data.file_tree[path];
|
||||
const data = window.global_context.file_tree[path];
|
||||
var iframe = createIframe();
|
||||
window.data.get_parameters = get_params;
|
||||
window.global_context.get_parameters = get_params;
|
||||
iframe.contentDocument.write(data);
|
||||
if (anchor) {
|
||||
iframe.contentDocument.location.hash = anchor;
|
||||
}
|
||||
window.data.current_path = path;
|
||||
window.global_context.current_path = path;
|
||||
window.history.pushState({path, get_params, anchor}, '', '#');
|
||||
});
|
||||
|
||||
window.onload = function() {
|
||||
// Set up the virtual file tree
|
||||
var FT = window.data.file_tree;
|
||||
var FT = window.global_context.file_tree;
|
||||
FT = _base64ToArrayBuffer(FT);
|
||||
FT = pako.inflate(FT)
|
||||
FT = new TextDecoder("utf-8").decode(FT);
|
||||
FT = JSON.parse(FT);
|
||||
window.data.file_tree = FT;
|
||||
window.global_context.file_tree = FT;
|
||||
|
||||
// Set up message listener
|
||||
window.addEventListener("message", (evnt) => {
|
||||
console.log("Received message in parent", evnt);
|
||||
if (evnt.data.action == 'set_title') {
|
||||
// iframe has finished loading and sent us its title
|
||||
// parent sets the title and responds with the data object
|
||||
// parent sets the title and responds with the global_context object
|
||||
window.document.title = evnt.data.argument;
|
||||
var iframe = document.getElementById(iFrameId);
|
||||
iframe.contentWindow.postMessage({
|
||||
action: "set_data",
|
||||
argument: window.data,
|
||||
argument: window.global_context,
|
||||
}, "*");
|
||||
} else if (evnt.data.action == 'virtual_click') {
|
||||
// user has clicked on a link in the iframe
|
||||
@ -94,5 +94,5 @@ window.onload = function() {
|
||||
});
|
||||
|
||||
// Load first page
|
||||
load_virtual_page(window.data.current_path, "", "");
|
||||
load_virtual_page(window.global_context.current_path, "", "");
|
||||
}
|
||||
|
@ -141,14 +141,14 @@ var is_virtual = function(url) {
|
||||
|
||||
var retrieve_file = function(path) {
|
||||
// console.log("Retrieving file: " + path);
|
||||
var file_tree = window.data.file_tree;
|
||||
var file_tree = window.global_context.file_tree;
|
||||
var file = file_tree[path];
|
||||
return file;
|
||||
};
|
||||
|
||||
var normalize_path = function(path) {
|
||||
// make relative paths absolute
|
||||
var result = window.data.current_path;
|
||||
var result = window.global_context.current_path;
|
||||
result = result.split('/');
|
||||
result.pop();
|
||||
result = result.concat(path.split('/'));
|
||||
@ -167,7 +167,7 @@ var normalize_path = function(path) {
|
||||
});
|
||||
|
||||
result = array.join('/');
|
||||
// console.log(`Normalized path: ${path} -> ${result} (@${window.data.current_path})`);
|
||||
// console.log(`Normalized path: ${path} -> ${result} (@${window.global_context.current_path})`);
|
||||
return result;
|
||||
};
|
||||
|
||||
@ -185,8 +185,8 @@ var fix_document = function() {
|
||||
window.addEventListener("message", (evnt) => {
|
||||
console.log("Received message in iframe", evnt);
|
||||
if (evnt.data.action == 'set_data') {
|
||||
window.data = evnt.data.argument;
|
||||
console.log("Received data from parent", window.data);
|
||||
window.global_context = evnt.data.argument;
|
||||
console.log("Received data from parent", window.global_context);
|
||||
// dynamically fix elements on this page
|
||||
try {
|
||||
fix_document();
|
||||
|
@ -7,7 +7,7 @@
|
||||
* creative.
|
||||
*
|
||||
* Here, we patch the `URLSearchParams` class so it returns the information
|
||||
* stored in `window.data.get_parameters`.
|
||||
* stored in `window.global_context.get_parameters`.
|
||||
*
|
||||
*/
|
||||
|
||||
@ -17,11 +17,11 @@ var myGet = function (arg) {
|
||||
const originalResult = originalGet.apply(this, [arg]);
|
||||
// If searchtools.js of sphinx is used
|
||||
if (
|
||||
window.data.get_parameters &&
|
||||
window.global_context.get_parameters &&
|
||||
(window.location.search === "") &&
|
||||
(Array.from(this.entries()).length == 0)
|
||||
) {
|
||||
const params = new URLSearchParams('?' + window.data.get_parameters);
|
||||
const params = new URLSearchParams('?' + window.global_context.get_parameters);
|
||||
const result = params.get(arg);
|
||||
// console.log("Return virtual get parameter:", arg, result);
|
||||
return result;
|
||||
|
@ -61,19 +61,19 @@ def embed_assets(index_file):
|
||||
|
||||
remote_resources = []
|
||||
|
||||
data = {
|
||||
global_context = {
|
||||
'current_path': base_name,
|
||||
'file_tree': file_tree,
|
||||
'remote_resources': remote_resources,
|
||||
}
|
||||
data = json.dumps(data)
|
||||
global_context = json.dumps(global_context)
|
||||
|
||||
result = """
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head><style>{style}</style></head>
|
||||
<body>{body}
|
||||
<script>window.data = {data}</script>
|
||||
<script>window.global_context = {global_context}</script>
|
||||
<script>{pako} //# sourceURL=pako.js</script>
|
||||
<script>{init_js}</script>
|
||||
</body></html>
|
||||
@ -82,7 +82,7 @@ def embed_assets(index_file):
|
||||
init_js=init_files['init.js'],
|
||||
pako=init_files['pako.min.js'],
|
||||
body=init_files['init.html'],
|
||||
data=data,
|
||||
global_context=global_context,
|
||||
)
|
||||
|
||||
with open(result_file, 'w') as fp:
|
||||
|
Loading…
x
Reference in New Issue
Block a user