Skip to content

Commit 3e27644

Browse files
Merge pull request #23 from cosmo0/electron-11
Fix for Electron 11
2 parents ee85615 + c2a9737 commit 3e27644

File tree

2 files changed

+47
-14
lines changed

2 files changed

+47
-14
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,39 @@
1-
const links = document.querySelectorAll('link[rel="import"]')
1+
// copy from https://github.com/electron/electron-api-demos/pull/466/
22

3-
// Import and add each page to the DOM
4-
Array.prototype.forEach.call(links, function (link) {
5-
let template = link.import.querySelector('.task-template')
6-
let clone = document.importNode(template.content, true)
7-
if (link.href.match('about.html')) {
8-
document.querySelector('body').appendChild(clone)
9-
} else {
10-
document.querySelector('.content').appendChild(clone)
11-
}
12-
})
3+
function includeHTML() {
4+
var links, i, elmnt, href, request;
5+
/* Loop through a collection of all HTML elements: */
6+
links = document.querySelectorAll('link[rel="import"]');
7+
// console.log(links)
8+
for (i = 0; i < links.length; i++) {
9+
elmnt = links[i];
10+
/*search for elements with a certain atrribute:*/
11+
href = elmnt.getAttribute('href');
12+
// console.log(href)
13+
if (href) {
14+
/* Make an HTTP request using the attribute value as the file name: */
15+
request = new XMLHttpRequest();
16+
request.onreadystatechange = function () {
17+
if (this.readyState == 4) {
18+
if (this.status == 200) { elmnt.innerHTML = this.responseText; }
19+
if (this.status == 404) { elmnt.innerHTML = "Page not found."; }
20+
// console.log(elmnt) // <link ref="import" href="sections/windows/crash-hang.html">
21+
let template = elmnt.querySelector('.task-template')
22+
let clone = document.importNode(template.content, true)
23+
if (href.match('about')) {
24+
document.querySelector('body').appendChild(clone)
25+
} else {
26+
document.querySelector('.content').appendChild(clone)
27+
}
28+
elmnt.remove();
29+
includeHTML();
30+
}
31+
}
32+
request.open("GET", href, false); // `false` makes the request synchronous
33+
request.send();
34+
/* Exit the function: */
35+
return;
36+
}
37+
}
38+
}
39+
includeHTML();

ElectronNET-API-Demos/wwwroot/assets/nav.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ function handleSectionTrigger(event) {
1515
event.target.classList.add('is-selected');
1616

1717
// Display the current section
18-
const sectionId = event.target.dataset.section + '-section'
19-
document.getElementById(sectionId).classList.add('is-shown');
18+
const sectionId = event.target.dataset.section + '-section';
19+
const section = document.getElementById(sectionId);
20+
if (!!section) {
21+
section.classList.add('is-shown');
22+
}
2023
}
2124

2225
function activateDefaultSection () {
@@ -61,7 +64,10 @@ function hideAllSectionsAndDeselectButtons () {
6164

6265
function displayAbout() {
6366
hideNav();
64-
document.querySelector('#about-modal').classList.add('is-shown')
67+
const modal = document.querySelector('#about-modal');
68+
if (!!modal) {
69+
modal.classList.add('is-shown');
70+
}
6571
}
6672

6773
function hideNav() {

0 commit comments

Comments
 (0)