From 62a4bc0cb07baa27b7f4b70ee1d05ee52530a0cb Mon Sep 17 00:00:00 2001 From: Masayuki Nii Date: Thu, 7 Nov 2024 19:21:34 +0900 Subject: [PATCH] HTML include started to implement. --- src/js/INTER-Mediator-Page.js | 2 ++ src/js/INTER-Mediator.js | 23 +++++++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/js/INTER-Mediator-Page.js b/src/js/INTER-Mediator-Page.js index 9d0594da1..609421d1c 100644 --- a/src/js/INTER-Mediator-Page.js +++ b/src/js/INTER-Mediator-Page.js @@ -104,6 +104,8 @@ let INTERMediatorOnPage = { isRequired2FA: false, authedUser: null, userNameJustASCII: true, + including: false, + includingParts: [], get authCount() { this._authCount = IMLibLocalContext.getValue('_im_authcount') diff --git a/src/js/INTER-Mediator.js b/src/js/INTER-Mediator.js index 485803894..f5ec4023d 100644 --- a/src/js/INTER-Mediator.js +++ b/src/js/INTER-Mediator.js @@ -63,7 +63,7 @@ const INTERMediator = { * @public * @type {object} */ - navigationLabel: [null, null, null, null, null, null, null, null, false], + navigationLabel: [null, null, null, null, null, null, null, null, null, null, null], /** * Storing the id value of linked elements. * @private @@ -601,7 +601,7 @@ const INTERMediator = { INTERMediator.elementIds = [] // Restoring original HTML Document from backup data. - const bodyNode = document.getElementsByTagName('BODY')[0] + const bodyNode = await INTERMediator.insertHTMLParts(document.getElementsByTagName('BODY')[0]) if (INTERMediator.rootEnclosure === null) { INTERMediator.rootEnclosure = bodyNode.innerHTML } else { @@ -649,6 +649,25 @@ const INTERMediator = { } } + async function insertHTMLParts(rootNode) { + if (!INTERMediatorOnPage.including) { + return rootNode; + } + const attr = "data-im-include" + const jsProtocol = "javascript:" + const nodes = rootNode.querySelectorAll(`[${attr}]`) + for node in nodes { + const incAttr = node.getAttribute89(attr).trim() + if incAttr.indexOf(jsProtocol) === 0 { + const key = incAttr.substring(jsProtocol.length).trim() + const insertParts = INTERMediatorOnPage.includingParts[key] + node.innerHTML = insertParts + } else { + + } + } + return rootNode + } /** -------------------------------------------------------------------- * Seeking nodes and if a node is an enclosure, proceed repeating. */