Skip to content

Commit

Permalink
Added posibility to use an ID:s for each module.
Browse files Browse the repository at this point in the history
  • Loading branch information
Snille committed Feb 9, 2017
1 parent 16cc81b commit ee7d3c0
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions MMM-Modulebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ Module.register("MMM-Modulebar",{

return menu;
},


// Creates the buttons.
createButton: function (self, name, data, placement) {
// Creates the span elemet to contain all the buttons.
Expand All @@ -63,16 +65,26 @@ Module.register("MMM-Modulebar",{
item.style.minHeight = self.config.minHeight;
// Collects all modules loaded in MagicMirror.
var modules = MM.getModules();
// When a button is clicked, the module either gets hidden or shown depending on current module status.
item.addEventListener("click", function () {
// When a button is clicked, the module either gets hidden or shown depending on current module status.
item.addEventListener("click", function () {
for (var i = 0; i < modules.length; i++) {
if (modules[i].name === name) {
if (modules[i].hidden) {
modules[i].show(self.config.animationSpeed, {force: self.config.allowForce});
console.log("Showing "+modules[i].name);
}else{
modules[i].hide(self.config.animationSpeed, {force: self.config.allowForce});
console.log("Hiding "+modules[i].name);
var idnr = modules[i].data.identifier.split("_");
// Checks if idnum is set in config.js. If it is, it only hides that module, if not hides all modules with the same name.
if (idnr[1] == data.idnum || data.idnum == null) {
if (modules[i].hidden) {
/* // Working on this... :)
if (data.showUrl != null) {
var result = data.showUrl;
console.log(result);
}
*/
modules[i].show(self.config.animationSpeed, {force: self.config.allowForce});
console.log("Showing "+modules[i].name+" ID: "+idnr[1]);
}else{
modules[i].hide(self.config.animationSpeed, {force: self.config.allowForce});
console.log("Hiding "+modules[i].name+" ID: "+idnr[1]);
}
}
}
}
Expand Down

0 comments on commit ee7d3c0

Please sign in to comment.