From d2b7d1ea6fb0756dbdec3cac9c65ce7c2f48e5d4 Mon Sep 17 00:00:00 2001 From: Tom Maenan Read Cutting Date: Mon, 6 Nov 2017 10:53:07 +0000 Subject: [PATCH] Make CurrentTime work on an id basis The JavaScript that updates instances of CurrentTime work on an id basis, instead of a class basis. --- .../ViewModels/Hackathons/CurrentTime.swift | 29 ++++++++----------- .../ViewModels/Hackathons/Schedule.swift | 8 ++--- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/Sources/HaCWebsiteLib/ViewModels/Hackathons/CurrentTime.swift b/Sources/HaCWebsiteLib/ViewModels/Hackathons/CurrentTime.swift index c347fb7..d065813 100644 --- a/Sources/HaCWebsiteLib/ViewModels/Hackathons/CurrentTime.swift +++ b/Sources/HaCWebsiteLib/ViewModels/Hackathons/CurrentTime.swift @@ -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 + )) + ) } } diff --git a/Sources/HaCWebsiteLib/ViewModels/Hackathons/Schedule.swift b/Sources/HaCWebsiteLib/ViewModels/Hackathons/Schedule.swift index 3269a21..6fb940a 100644 --- a/Sources/HaCWebsiteLib/ViewModels/Hackathons/Schedule.swift +++ b/Sources/HaCWebsiteLib/ViewModels/Hackathons/Schedule.swift @@ -8,11 +8,11 @@ struct Schedule : Nodeable { return El.Ul.containing( schedule.map { El.Li.containing( - TextNode($0.key), - TextNode(" "), - TextNode($0.value) + $0.key, + " ", + $0.value ) } ) } -} \ No newline at end of file +}