Skip to content

Commit

Permalink
HTML include started to implement.
Browse files Browse the repository at this point in the history
  • Loading branch information
msyk committed Nov 7, 2024
1 parent 2443ef3 commit 62a4bc0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/js/INTER-Mediator-Page.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ let INTERMediatorOnPage = {
isRequired2FA: false,
authedUser: null,
userNameJustASCII: true,
including: false,
includingParts: [],

get authCount() {
this._authCount = IMLibLocalContext.getValue('_im_authcount')
Expand Down
23 changes: 21 additions & 2 deletions src/js/INTER-Mediator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
*/
Expand Down

0 comments on commit 62a4bc0

Please sign in to comment.