From e45e3d5a6254471cfbfb13a1c448a03678311f54 Mon Sep 17 00:00:00 2001 From: Matt Walsh Date: Fri, 18 Sep 2020 14:59:58 -0500 Subject: [PATCH] functional checkboxes --- server/scripts/modules/travelforecast.js | 8 +++++- server/scripts/modules/weatherdisplay.js | 33 +++++++++++++++++------- server/styles/index.css | 1 + version.js | 2 +- 4 files changed, 32 insertions(+), 12 deletions(-) diff --git a/server/scripts/modules/travelforecast.js b/server/scripts/modules/travelforecast.js index 63dc7b5..bab6114 100644 --- a/server/scripts/modules/travelforecast.js +++ b/server/scripts/modules/travelforecast.js @@ -79,10 +79,16 @@ class TravelForecast extends WeatherDisplay { this.longCanvas.width = 640; this.longCanvas.height = 1728; this.longContext = this.longCanvas.getContext('2d'); + this.longCanvasGifs = []; } // set up variables const cities = this.data; + // clean up existing gifs + this.gifs.forEach(gif => gif.pause()); + // delete the gifs + this.gifs.length = 0; + this.longContext.clearRect(0,0,this.longCanvas.width,this.longCanvas.height); // draw the "long" canvas with all cities @@ -120,7 +126,7 @@ class TravelForecast extends WeatherDisplay { const xHigh = (560 - (highString.length * 20)); draw.text(this.longContext, 'Star4000 Large', '24pt', '#FFFF00', xHigh, y, highString, 2); - this.gifs.push(await utils.image.superGifAsync({ + this.longCanvasGifs.push(await utils.image.superGifAsync({ src: city.icon, loop_delay: 100, auto_play: true, diff --git a/server/scripts/modules/weatherdisplay.js b/server/scripts/modules/weatherdisplay.js index dbefeec..244c6c5 100644 --- a/server/scripts/modules/weatherdisplay.js +++ b/server/scripts/modules/weatherdisplay.js @@ -30,18 +30,20 @@ class WeatherDisplay { this.navBaseCount = 0; this.screenIndex = -1; // special starting condition - if (elemId !== 'progress') this.addCheckbox(elemId, defaultEnabled); + // create the canvas, also stores this.elemId + this.createCanvas(elemId); + + if (elemId !== 'progress') this.addCheckbox(defaultEnabled); if (this.enabled) { this.setStatus(STATUS.loading); } else { this.setStatus(STATUS.disabled); } - this.createCanvas(elemId); } - addCheckbox(elemId, defaultEnabled = true) { + addCheckbox(defaultEnabled = true) { // get the saved status of the checkbox - let savedStatus = window.localStorage.getItem(`${elemId}Enabled`); + let savedStatus = window.localStorage.getItem(`${this.elemId}Enabled`); if (savedStatus === null) savedStatus = defaultEnabled; if (savedStatus === 'true' || savedStatus === true) { this.enabled = true; @@ -49,18 +51,26 @@ class WeatherDisplay { this.enabled = false; } + // refresh (or initially store the state of the checkbox) + window.localStorage.setItem(`${this.elemId}Enabled`, this.enabled); + // create a checkbox in the selected displays area - const checkbox = `