Skip to content

Commit 80d277d

Browse files
Merge pull request #7 from MurdoMaclachlan/dev
Patch to fix additional scripts not running
2 parents 2e34303 + 1540892 commit 80d277d

File tree

6 files changed

+35
-24
lines changed

6 files changed

+35
-24
lines changed

pages/accounts.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -406,9 +406,9 @@ <h2>
406406
<div id="footer-container">
407407
<!-- Footer will be inserted here -->
408408
</div>
409+
<div id="scripts">
410+
<!-- Scripts (secondary scripts inserted during constructor runtime) -->
411+
<script id="constructor" src="../scripts/js/constructor.js"></script>
412+
</div>
409413
</body>
410-
411-
<!-- Scripts (secondary scripts inserted during constructor runtime) -->
412-
<script id="constructor" src="../scripts/js/constructor.js"></script>
413-
414414
</html>

pages/blog.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
<div id="footer-container">
3232
<!-- Footer will be inserted here -->
3333
</div>
34+
<div id="scripts">
35+
<!-- Scripts (secondary scripts inserted during constructor runtime) -->
36+
<script id="constructor" src="../scripts/js/constructor.js"></script>
37+
</div>
3438
</body>
35-
36-
<!-- Scripts (secondary scripts inserted during constructor runtime) -->
37-
<script id="constructor" src="../scripts/js/constructor.js"></script>
38-
3939
</html>

pages/endeavours.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ <h2><a id="#writing" href="#writing">Writing</a></h2>
118118
<div id="footer-container">
119119
<!-- Footer will be inserted here -->
120120
</div>
121+
<div id="scripts">
122+
<!-- Scripts (secondary scripts inserted during constructor runtime) -->
123+
<script id="constructor" src="../scripts/js/constructor.js"></script>
124+
</div>
121125
</body>
122-
123-
<!-- Scripts (secondary scripts inserted during constructor runtime) -->
124-
<script id="constructor" src="../scripts/js/constructor.js"></script>
125-
126126
</html>

pages/home.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ <h2><a id="#about-me" href="#about-me">About Me</a></h2>
6868
<div id="footer-container">
6969
<!-- Footer will be inserted here -->
7070
</div>
71+
<div id="scripts">
72+
<!-- Scripts (secondary scripts inserted during constructor runtime) -->
73+
<script id="constructor" src="../scripts/js/constructor.js"></script>
74+
</div>
7175
</body>
72-
73-
<!-- Scripts (secondary scripts inserted during constructor runtime) -->
74-
<script id="constructor" src="../scripts/js/constructor.js"></script>
75-
7676
</html>

pages/legal.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ <h2><a id="#licensing" href="#licensing">Licensing</a></h2>
6767
<div id="footer-container">
6868
<!-- Footer will be inserted here -->
6969
</div>
70+
<div id="scripts">
71+
<!-- Scripts (secondary scripts inserted during constructor runtime) -->
72+
<script id="constructor" src="../scripts/js/constructor.js"></script>
73+
</div>
7074
</body>
71-
72-
<!-- Scripts (secondary scripts inserted during constructor runtime) -->
73-
<script id="constructor" src="../scripts/js/constructor.js"></script>
74-
7575
</html>

scripts/js/constructor.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ var structures = {
4949
</section>
5050
</footer>`
5151
}
52-
var secondaryScripts =
53-
`<script src="../scripts/js/themes.js"></script>
54-
<script src="../scripts/js/events.js"></script>`;
52+
var secondaryScripts = [
53+
"../scripts/js/themes.js",
54+
"../scripts/js/events.js"
55+
];
5556

5657
construct();
5758

@@ -66,7 +67,9 @@ function construct() {
6667
processSelectedButton();
6768

6869
// Insert other universal scripts
69-
insertSnippet("afterend", "constructor", secondaryScripts)
70+
for (let i = 0; i < secondaryScripts.length; i++) {
71+
insertScript(secondaryScripts[i])
72+
}
7073
}
7174

7275
// Inserts an HTML snippet at a given position relative to a unique element
@@ -75,6 +78,14 @@ function insertSnippet(position, id, snippet) {
7578
element.insertAdjacentHTML(position, snippet);
7679
}
7780

81+
// Inserts a script tag at the given location
82+
function insertScript(source) {
83+
let script = document.createElement('script');
84+
let location = document.getElementById('scripts');
85+
script.src = source;
86+
location.appendChild(script);
87+
}
88+
7889
// Marks one of the nav buttons as selected if the page is a primary one
7990
function processSelectedButton() {
8091
let title = document.title.split(" | ")[1].toLowerCase();

0 commit comments

Comments
 (0)