From e4197012f65778f815cd73a6c7fab1a30ef3b92f Mon Sep 17 00:00:00 2001 From: Michael Teeuw Date: Tue, 8 Nov 2016 20:07:31 +0100 Subject: [PATCH] updateWrapperStates to hide unused regions. --- config/config.js.sample | 2 +- js/main.js | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/config/config.js.sample b/config/config.js.sample index c2607dbf..6b090cca 100644 --- a/config/config.js.sample +++ b/config/config.js.sample @@ -18,7 +18,7 @@ var config = { }, { module: "updatenotification", - position: "top_center" + position: "top_bar" }, { module: 'clock', diff --git a/js/main.js b/js/main.js index 984df4fd..a69e56c2 100644 --- a/js/main.js +++ b/js/main.js @@ -198,6 +198,8 @@ var MM = (function() { // the .display property. moduleWrapper.style.position = "fixed"; + updateWrapperStates(); + if (typeof callback === "function") { callback(); } }, speed); } @@ -241,6 +243,8 @@ var MM = (function() { moduleWrapper.style.position = "static"; moduleWrapper.style.opacity = 1; + updateWrapperStates(); + clearTimeout(module.showHideTimer); module.showHideTimer = setTimeout(function() { if (typeof callback === "function") { callback(); } @@ -249,6 +253,37 @@ var MM = (function() { } }; + /* updateWrapperStates() + * Checks for all positions if it has visible content. + * If not, if will hide the position to prevent unwanted margins. + * This method schould be called by the show and hide methods. + * + * Example: + * If the top_bar only contains the update notification. And no update is available, + * the update notification is hidden. The top bar still occupies space making for + * an ugly top margin. By using this function, the top bar will be hidden if the + * update notification is not visible. + */ + + var updateWrapperStates = function() { + var positions = ["top_bar", "top_left", "top_center", "top_right", "upper_third", "middle_center", "lower_third", "bottom_left", "bottom_center", "bottom_right", "bottom_bar", "fullscreen_above", "fullscreen_below"]; + + positions.forEach(function(position) { + var wrapper = selectWrapper(position); + var moduleWrappers = wrapper.getElementsByClassName("module"); + + var showWrapper = false; + Array.prototype.forEach.call(moduleWrappers, function(moduleWrapper) { + console.log(moduleWrapper, moduleWrapper.style.position); + if (moduleWrapper.style.position == "static") { + showWrapper = true; + } + }); + + wrapper.style.display = showWrapper ? "block" : "none"; + }); + }; + /* loadConfig() * Loads the core config and combines it with de system defaults. */