From c2a97379cb1249bb6e24358cb61d5de9bf040faf Mon Sep 17 00:00:00 2001 From: Thomas Broust Date: Tue, 16 Mar 2021 11:38:29 +0100 Subject: [PATCH] Fix for Electron 11 --- .../wwwroot/assets/imports.js | 49 ++++++++++++++----- ElectronNET-API-Demos/wwwroot/assets/nav.js | 12 +++-- 2 files changed, 47 insertions(+), 14 deletions(-) diff --git a/ElectronNET-API-Demos/wwwroot/assets/imports.js b/ElectronNET-API-Demos/wwwroot/assets/imports.js index 1c5a703..a1c2f23 100644 --- a/ElectronNET-API-Demos/wwwroot/assets/imports.js +++ b/ElectronNET-API-Demos/wwwroot/assets/imports.js @@ -1,12 +1,39 @@ -const links = document.querySelectorAll('link[rel="import"]') +// copy from https://github.com/electron/electron-api-demos/pull/466/ -// Import and add each page to the DOM -Array.prototype.forEach.call(links, function (link) { - let template = link.import.querySelector('.task-template') - let clone = document.importNode(template.content, true) - if (link.href.match('about.html')) { - document.querySelector('body').appendChild(clone) - } else { - document.querySelector('.content').appendChild(clone) - } -}) +function includeHTML() { + var links, i, elmnt, href, request; + /* Loop through a collection of all HTML elements: */ + links = document.querySelectorAll('link[rel="import"]'); + // console.log(links) + for (i = 0; i < links.length; i++) { + elmnt = links[i]; + /*search for elements with a certain atrribute:*/ + href = elmnt.getAttribute('href'); + // console.log(href) + if (href) { + /* Make an HTTP request using the attribute value as the file name: */ + request = new XMLHttpRequest(); + request.onreadystatechange = function () { + if (this.readyState == 4) { + if (this.status == 200) { elmnt.innerHTML = this.responseText; } + if (this.status == 404) { elmnt.innerHTML = "Page not found."; } + // console.log(elmnt) // + let template = elmnt.querySelector('.task-template') + let clone = document.importNode(template.content, true) + if (href.match('about')) { + document.querySelector('body').appendChild(clone) + } else { + document.querySelector('.content').appendChild(clone) + } + elmnt.remove(); + includeHTML(); + } + } + request.open("GET", href, false); // `false` makes the request synchronous + request.send(); + /* Exit the function: */ + return; + } + } +} +includeHTML(); \ No newline at end of file diff --git a/ElectronNET-API-Demos/wwwroot/assets/nav.js b/ElectronNET-API-Demos/wwwroot/assets/nav.js index 64bb05d..d224505 100644 --- a/ElectronNET-API-Demos/wwwroot/assets/nav.js +++ b/ElectronNET-API-Demos/wwwroot/assets/nav.js @@ -15,8 +15,11 @@ function handleSectionTrigger(event) { event.target.classList.add('is-selected'); // Display the current section - const sectionId = event.target.dataset.section + '-section' - document.getElementById(sectionId).classList.add('is-shown'); + const sectionId = event.target.dataset.section + '-section'; + const section = document.getElementById(sectionId); + if (!!section) { + section.classList.add('is-shown'); + } } function activateDefaultSection () { @@ -61,7 +64,10 @@ function hideAllSectionsAndDeselectButtons () { function displayAbout() { hideNav(); - document.querySelector('#about-modal').classList.add('is-shown') + const modal = document.querySelector('#about-modal'); + if (!!modal) { + modal.classList.add('is-shown'); + } } function hideNav() {