Skip to content

Commit ebfa15b

Browse files
committed
moved embed js from template to jsfile
1 parent a141e72 commit ebfa15b

9 files changed

Lines changed: 87 additions & 62 deletions

File tree

assets/js/index.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/**
2+
* @file index.js
3+
* This script is for the index template that is used by milestones.
4+
*/
5+
// Minimal content population using Bootstrap's built-in events
6+
document.addEventListener('DOMContentLoaded', function () {
7+
var milestoneModal = document.getElementById('milestoneModal');
8+
if (milestoneModal) {
9+
milestoneModal.addEventListener('show.bs.modal', function (event) {
10+
var triggerElement = event.relatedTarget;
11+
12+
// Check if this is a milestone link with data-milestone-id attribute
13+
var milestoneId = triggerElement.getAttribute('data-milestone-id');
14+
15+
if (milestoneId) {
16+
// This is a milestone link - find the anchor with matching ID
17+
var anchor = document.getElementById(milestoneId);
18+
if (anchor) {
19+
var col = anchor.closest('.col');
20+
if (col) {
21+
var colClone = col.cloneNode(true);
22+
// title - use button text
23+
var buttonText = triggerElement.textContent.trim();
24+
document.getElementById('milestoneModalLabel').textContent =
25+
buttonText || 'Milestone Details';
26+
// content
27+
var modalBody = document.getElementById('milestoneModalBody');
28+
modalBody.innerHTML = '';
29+
modalBody.appendChild(colClone);
30+
// cleanup duplicate header
31+
var headerInClone = colClone.querySelector('.card-header');
32+
if (headerInClone) {
33+
headerInClone.remove();
34+
}
35+
return; // Found and processed the milestone
36+
}
37+
}
38+
} else {
39+
// This is a direct milestone button click - use original logic
40+
var col = triggerElement.closest('.col');
41+
if (col) {
42+
var colClone = col.cloneNode(true);
43+
// title - use button text
44+
var buttonText = triggerElement.textContent.trim();
45+
document.getElementById('milestoneModalLabel').textContent =
46+
buttonText || 'Milestone Details';
47+
// content
48+
var modalBody = document.getElementById('milestoneModalBody');
49+
modalBody.innerHTML = '';
50+
modalBody.appendChild(colClone);
51+
// cleanup duplicate header
52+
var headerInClone = colClone.querySelector('.card-header');
53+
if (headerInClone) {
54+
headerInClone.remove();
55+
}
56+
}
57+
}
58+
});
59+
// clear content when modal closes
60+
milestoneModal.addEventListener('hidden.bs.modal', function () {
61+
document.getElementById('milestoneModalLabel').textContent = '';
62+
document.getElementById('milestoneModalBody').innerHTML = '';
63+
});
64+
}
65+
});

handler/app/app.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,7 @@ type SRI struct {
987987
EditArtifact string // Artifact Editor JS verification hash.
988988
EditAssets string // Editor Assets JS verification hash.
989989
EditForApproval string // Editor For Approval JS verification hash.
990+
IndexJS string
990991
Jsdos6JS string // js-dos v6 verification hash.
991992
DosboxJS string // DOSBox Emscripten verification hash.
992993
Layout string // Layout CSS verification hash.
@@ -1055,6 +1056,11 @@ func (s *SRI) Verify(fs embed.FS) error { //nolint:funlen
10551056
if err != nil {
10561057
return fmt.Errorf("%s: %w", name, err)
10571058
}
1059+
name = names[IndexJS]
1060+
s.IndexJS, err = helper.Integrity(name, fs)
1061+
if err != nil {
1062+
return fmt.Errorf("%s: %w", name, err)
1063+
}
10581064
name = names[Jsdos6JS]
10591065
s.Jsdos6JS, err = helper.Integrity(name, fs)
10601066
if err != nil {

handler/app/asset.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const (
2121
EditForApproval // EditForApproval is the path to the minified Editor for-approval JS file.
2222
Htmx // Htmx is the path to the minified htmx AJAX JS file.
2323
HtmxRespTargets // HtmxRespTargets is the path to the minified response targets extension file.
24+
IndexJS // IndexJS is the path to the minified JS file used by the index template.
2425
Jsdos6JS // Jsdos6JS is the path to the minified js-dos v6 JS file.
2526
Layout // Layout is the path to the minified layout CSS file.
2627
LayoutJS // LayoutJS is the path to the minified layout JS file.
@@ -49,6 +50,7 @@ func Hrefs() *Paths {
4950
EditForApproval: "/js/editor-forapproval.min.js",
5051
Htmx: "/js/htmx.v2.min.js", // renamed on 21-Jul-25 "/js/htmx.min.js",
5152
HtmxRespTargets: "/js/htmx.v2.ext-response-targets.min.js", // "/js/htmx-response-targets.min.js",
53+
IndexJS: "/js/index.min.js",
5254
Jsdos6JS: "/js/js-dos.js",
5355
Layout: "/css/layout.min.css",
5456
LayoutJS: "/js/layout.min.js",

handler/app/context.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,6 +1189,7 @@ func Index(c echo.Context, sl *slog.Logger) error {
11891189
}
11901190
const name = "index"
11911191
data := empty(c)
1192+
// note: if the title get's changed, the indexJS conditional in layout.tmpl needs updating
11921193
data["title"] = "Introduction and milestones"
11931194
data["canonical"] = "/"
11941195
data["h1"] = "The subcultures of obsolete microcomputers"

handler/app/template.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,9 @@ func (t *Templ) FuncClosures(db *sql.DB) *template.FuncMap { //nolint:funlen
269269
"initialisms": func(s string) string {
270270
return initialism.Join(initialism.Path(s))
271271
},
272+
"indexJS": func() string {
273+
return hrefs[IndexJS]
274+
},
272275
"jsdos6JS": func() string {
273276
return hrefs[Jsdos6JS]
274277
},
@@ -335,6 +338,9 @@ func (t *Templ) FuncClosures(db *sql.DB) *template.FuncMap { //nolint:funlen
335338
"sri_htmxRespTargets": func() string {
336339
return t.Subresource.HtmxRespTargets
337340
},
341+
"sri_indexJS": func() string {
342+
return t.Subresource.IndexJS
343+
},
338344
"sri_jsdos6JS": func() string {
339345
return t.Subresource.Jsdos6JS
340346
},

public/js/index.min.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

runner/runner.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ func NamedJS() []string {
3232
"chiptune-player",
3333
"editor-forapproval",
3434
"htmx-response-targets",
35+
"index",
3536
"votes-pouet",
3637
}
3738
}

view/app/index.tmpl

Lines changed: 1 addition & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,7 @@ BUT SOON WILL HAVE BOTH 86-DOS AND CP/M-86. JOE
528528
Milestone Modal Pop-up
529529
When a milestone title or date is clicked, this modal pops up with a copy of the milestone content.
530530
This allows for easier readability due to the use of the "lead" class for the font.
531+
This modal is handled by assets/js/index.js
531532
*/}}
532533
<div class="modal fade" id="milestoneModal" tabindex="-1" aria-labelledby="milestoneModalLabel" aria-hidden="true">
533534
<div class="modal-dialog modal-xl modal-dialog-centered modal-dialog-scrollable">
@@ -545,68 +546,6 @@ BUT SOON WILL HAVE BOTH 86-DOS AND CP/M-86. JOE
545546
</div>
546547
</div>
547548
</div>
548-
<script>
549-
// Minimal content population using Bootstrap's built-in events
550-
document.addEventListener('DOMContentLoaded', function() {
551-
var milestoneModal = document.getElementById('milestoneModal');
552-
if (milestoneModal) {
553-
milestoneModal.addEventListener('show.bs.modal', function(event) {
554-
var triggerElement = event.relatedTarget;
555-
556-
// Check if this is a milestone link with data-milestone-id attribute
557-
var milestoneId = triggerElement.getAttribute('data-milestone-id');
558-
559-
if (milestoneId) {
560-
// This is a milestone link - find the anchor with matching ID
561-
var anchor = document.getElementById(milestoneId);
562-
if (anchor) {
563-
var col = anchor.closest('.col');
564-
if (col) {
565-
var colClone = col.cloneNode(true);
566-
// title - use button text
567-
var buttonText = triggerElement.textContent.trim();
568-
document.getElementById('milestoneModalLabel').textContent = buttonText || 'Milestone Details';
569-
// content
570-
var modalBody = document.getElementById('milestoneModalBody');
571-
modalBody.innerHTML = '';
572-
modalBody.appendChild(colClone);
573-
// cleanup duplicate header
574-
var headerInClone = colClone.querySelector('.card-header');
575-
if (headerInClone) {
576-
headerInClone.remove();
577-
}
578-
return; // Found and processed the milestone
579-
}
580-
}
581-
} else {
582-
// This is a direct milestone button click - use original logic
583-
var col = triggerElement.closest('.col');
584-
if (col) {
585-
var colClone = col.cloneNode(true);
586-
// title - use button text
587-
var buttonText = triggerElement.textContent.trim();
588-
document.getElementById('milestoneModalLabel').textContent = buttonText || 'Milestone Details';
589-
// content
590-
var modalBody = document.getElementById('milestoneModalBody');
591-
modalBody.innerHTML = '';
592-
modalBody.appendChild(colClone);
593-
// cleanup duplicate header
594-
var headerInClone = colClone.querySelector('.card-header');
595-
if (headerInClone) {
596-
headerInClone.remove();
597-
}
598-
}
599-
}
600-
});
601-
// clear content when modal closes
602-
milestoneModal.addEventListener('hidden.bs.modal', function() {
603-
document.getElementById('milestoneModalLabel').textContent = '';
604-
document.getElementById('milestoneModalBody').innerHTML = '';
605-
});
606-
}
607-
});
608-
</script>
609-
610549
{{- end}}
611550
</div>
612551
{{- end}}

view/app/layout.tmpl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,9 @@
359359
<script defer src="{{ htmxRespTargets }}?{{ sri_htmxRespTargets }}" integrity="{{ sri_htmxRespTargets }}" crossorigin="anonymous"></script>
360360
{{- /* Do not defer, or async load the Bootstrap 5.x JS */}}
361361
<script src="{{ bootstrap5JS }}?{{ sri_bootstrap5JS }}" integrity="{{ sri_bootstrap5JS }}" crossorigin="anonymous"></script>
362+
{{- if eq $metatitle "Introduction and milestones" }}
363+
<script defer src="{{ indexJS }}?{{ sri_indexJS }}" integrity="{{ sri_indexJS }}" crossorigin="anonymous"></script>
364+
{{- end}}
362365
{{- if $pouet}}
363366
<script async src="{{ pouet }}?{{ sri_pouet }}" integrity="{{ sri_pouet }}" crossorigin="anonymous"></script>
364367
{{- end}}

0 commit comments

Comments
 (0)