-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make CurrentTime work on an id basis
The JavaScript that updates instances of CurrentTime work on an id basis, instead of a class basis.
- Loading branch information
Showing
2 changed files
with
16 additions
and
21 deletions.
There are no files selected for viewing
29 changes: 12 additions & 17 deletions
29
Sources/HaCWebsiteLib/ViewModels/Hackathons/CurrentTime.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,18 @@ | ||
import HaCTML | ||
import Foundation | ||
|
||
struct CurrentTime : Nodeable { | ||
static let className = "RealTimeClock" | ||
static let element = El.Span[Attr.className => CurrentTime.className].containing("Current Time") | ||
static var ScriptUsed = false | ||
let id = "CurrentTime\(UUID().description)" | ||
|
||
var node: Node { | ||
if(!CurrentTime.ScriptUsed) { | ||
CurrentTime.ScriptUsed = true | ||
return Fragment( | ||
CurrentTime.element, | ||
// TODO: get this script to be loaded from CurrentTime.js | ||
//Script(file: "CurrentTime.js", escapes: ["className": CurrentTime.className]).node | ||
El.Script.containing(TextNode( | ||
"function updateClock() { const current = new Date(); Array.from(document.getElementsByClassName(\"\(CurrentTime.className)\")).map(function(x) { x.innerHTML = current.getHours()+\":\"+ (current.getMinutes()<10?\"0\":\"\") + current.getMinutes(); });} updateClock(); setInterval(updateClock,1000);", | ||
escapeLevel: .unsafeRaw | ||
)) | ||
) | ||
} else { | ||
return CurrentTime.element | ||
} | ||
return Fragment( | ||
El.Span[Attr.id => id].containing("Current Time"), | ||
// TODO: get this script to be loaded from CurrentTime.js | ||
//Script(file: "CurrentTime.js", escapes: ["className": CurrentTime.className]).node | ||
El.Script.containing(TextNode( | ||
"function updateClock() { const current = new Date(); document.getElementById(\"\(id)\").innerHTML = current.getHours()+\":\"+ (current.getMinutes()<10?\"0\":\"\") + current.getMinutes(); } updateClock(); setInterval(updateClock,1000);", | ||
escapeLevel: .unsafeRaw | ||
)) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters