From a32494a7cb35078fa65e8bbafeaa7560effec2de Mon Sep 17 00:00:00 2001 From: Clemens Richter Date: Wed, 1 Aug 2018 23:51:29 +0200 Subject: [PATCH] added clock option --- Countdown-Dateien/countdown.js | 10 ++++++- slideshow.html | 9 +++--- slideshow.js | 55 ++++++++++++++++++++++++++++++++-- 3 files changed, 67 insertions(+), 7 deletions(-) diff --git a/Countdown-Dateien/countdown.js b/Countdown-Dateien/countdown.js index 793f3f5..edf03ee 100644 --- a/Countdown-Dateien/countdown.js +++ b/Countdown-Dateien/countdown.js @@ -35,7 +35,15 @@ function cd_CountBack(secs) this.DisplayStr = this.DisplayStr.replace(/%%S%%/g, this.Calcage(secs,1,60)); document.getElementById(this.Div).innerHTML = this.DisplayStr; - if (this.CountActive) setTimeout(this.obj +".CountBack(" + (secs-1) + ")", 990); +// if (this.CountActive) setTimeout(this.obj +".CountBack(" + (secs-1) + ")", 990); + let obj = this; + if (obj.CountActive) { + setTimeout(function(){ + obj.CountBack(secs-1) + },990 + ); + } + } function cd_Setup() { diff --git a/slideshow.html b/slideshow.html index 34d92be..1601fee 100644 --- a/slideshow.html +++ b/slideshow.html @@ -12,6 +12,10 @@ +
+ countdown
+ clock
+
@@ -32,10 +36,7 @@ diff --git a/slideshow.js b/slideshow.js index 0a231ce..dc8cfe0 100644 --- a/slideshow.js +++ b/slideshow.js @@ -104,12 +104,25 @@ let files = Array.from(document.getElementById("filePicker").files); let img = document.getElementById("mainImage"); let delay = document.getElementById("delayPicker").value; let cache = makeCache(files,50); +let mode = document.querySelector('input[name="modeSelector"]:checked').value; setTimeout(displayImage,delay,cache,img,delay); console.log(cd2) -cd2.TargetDate = dateInput.value; -cd2.Setup(); +if (mode==="countdown"){ + cd2.Div = "clock2"; + cd2.DisplayFormat = "%%D%% %%H%% : %%M%% : %%S%%" + + cd2.TargetDate = dateInput.value; + cd2.Setup(); +} +if (mode==="clock"){ + cd2 = new clock("cd2"); + cd2.Div = "clock2"; + cd2.DisplayFormat = "%%H%% : %%M%%" + cd2.Setup(); +} + }; @@ -132,3 +145,41 @@ tag.setAttribute('src', "testimages/1.jpg"); tag.setAttribute('style', "display:block"); document.getElementById("mainImage").replaceWith(tag) */ +function clock(obj) +{ + this.obj = obj; + this.Div = "clock"; + this.BackColor = "white"; + this.ForeColor = "black"; + this.TargetDate = "11/22/2013 5:00 AM"; + this.DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds."; + this.CountActive = true; + + this.DisplayStr; + + this.Update = cl_Update; + this.Setup = cl_Setup; +} + +function cl_Update() +{ + let d = new Date() + this.DisplayStr = this.DisplayFormat.replace(/%%D%%/g,""); + this.DisplayStr = this.DisplayStr.replace(/%%H%%/g, d.getHours()); + this.DisplayStr = this.DisplayStr.replace(/%%M%%/g, d.getMinutes()); + this.DisplayStr = this.DisplayStr.replace(/%%S%%/g,""); + + document.getElementById(this.Div).innerHTML = this.DisplayStr; + let obj = this; + if (obj.CountActive) { + setTimeout(function(){ + obj.Update() + },1000 + ); + } +} +function cl_Setup() +{ + this.Update(); +} +