updateWrapperStates to hide unused regions.

This commit is contained in:
Michael Teeuw 2016-11-08 20:07:31 +01:00
parent df00a1e0a3
commit e4197012f6
2 changed files with 36 additions and 1 deletions

View File

@ -18,7 +18,7 @@ var config = {
},
{
module: "updatenotification",
position: "top_center"
position: "top_bar"
},
{
module: 'clock',

View File

@ -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.
*/