From 0845c6ea90e4f1e2ebeabf95d1d9cf9133758f46 Mon Sep 17 00:00:00 2001 From: Parnic Date: Mon, 7 Jan 2019 22:41:11 -0600 Subject: [PATCH] Added support for specifying image div id This enables multiple Unsplash modules to load and function side-by-side which is necessary when you want, for example, to use a profile switcher to display different collections at different times. Fixes #1 --- MMM-Unsplash.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/MMM-Unsplash.js b/MMM-Unsplash.js index a47c222..d3f51de 100644 --- a/MMM-Unsplash.js +++ b/MMM-Unsplash.js @@ -6,7 +6,8 @@ Module.register("MMM-Unsplash", { height: 1920, orientation: "portrait", apiKey: "", - updateInterval: 1800 + updateInterval: 1800, + divName: "mmm-unsplash-placeholder" }, start: function() { @@ -27,16 +28,16 @@ Module.register("MMM-Unsplash", { req.addEventListener("load", function() { if (this.status == 200) { var obj = JSON.parse(this.responseText) - var img1 = document.getElementById("mmm-unsplash-placeholder1") - var img2 = document.getElementById("mmm-unsplash-placeholder2") + var img1 = document.getElementById(self.config.divName + "1") + var img2 = document.getElementById(self.config.divName + "2") img1.addEventListener("load", function() { fade(img1, self.config.opacity, function() { - img1.id = "mmm-unsplash-placeholder2" + img1.id = self.config.divName + "2" }) fade(img2, 0, function() { - img2.id = "mmm-unsplash-placeholder1" + img2.id = self.config.divName + "1" }) }) @@ -56,7 +57,7 @@ Module.register("MMM-Unsplash", { getDom: function() { var wrapper = document.createElement("div") - wrapper.innerHTML = "" + wrapper.innerHTML = "" return wrapper } })