Send URL updates to the UI when pages are loaded.

This commit is contained in:
CalDescent
2023-02-17 15:40:06 +00:00
parent 3077810ea8
commit 5b7e9666dc
3 changed files with 35 additions and 6 deletions

View File

@@ -10,7 +10,7 @@ function handleResponse(event, response) {
return;
}
// Handle emmpty or missing responses
// Handle empty or missing responses
if (response == null || response.length == 0) {
response = "{\"error\": \"Empty response\"}"
}
@@ -151,7 +151,6 @@ window.addEventListener("message", (event) => {
case "LINK_TO_QDN_RESOURCE":
if (data.service == null) data.service = "WEBSITE"; // Default to WEBSITE
window.location = buildResourceUrl(data.service, data.name, data.identifier, data.path);
response = true;
break;
case "SEARCH_QDN_RESOURCES":
@@ -279,6 +278,13 @@ window.addEventListener("message", (event) => {
return;
}
if (response == null) {
// Pass to parent (UI), in case they can fulfil this request
event.data.requestedHandler = "UI";
parent.postMessage(event.data, '*', [event.ports[0]]);
return;
}
handleResponse(event, response);
}, false);
@@ -317,6 +323,19 @@ else if (document.attachEvent) {
document.attachEvent('onclick', interceptClickEvent);
}
/**
* Send current page details to UI
*/
document.addEventListener('DOMContentLoaded', () => {
qortalRequest({
action: "QDN_RESOURCE_DISPLAYED",
service: qdnService,
name: qdnName,
identifier: qdnIdentifier,
path: qdnPath
});
});
/**
* Intercept image loads from the DOM
*/