MMM-pages/MMM-pages.js

61 lines
2.3 KiB
JavaScript
Raw Normal View History

2017-06-18 13:24:04 -07:00
Module.register("MMM-pages", {
defaults: {
modules: [],
excludes: ["MMM-page-indicator"],
animationTime: 1000,
},
getStyles: function() {
return ["pages.css"];
},
start: function() {
this.curPage = 0;
},
notificationReceived: function(notification, payload, sender) {
if (notification === "PAGE_CHANGED") {
Log.log(this.name + " recieved a notification to change to page " + payload);
this.curPage = payload;
this.updatePages();
} else if (notification === "PAGE_INCREMENT") {
Log.log(this.name + " recieved a notification to increment pages!");
if (this.curPage === this.config.modules.length - 1) {
this.curPage = 0;
} else { this.curPage++ }
this.updatePages();
} else if (notification === "PAGE_DECREMENT") {
Log.log(this.name + " recieved a notification to decrement pages!");
if (this.curPage === 0) {
this.curPage = this.config.modules.length - 1;
} else { this.curPage-- }
this.updatePages();
} else if (notification === "DOM_OBJECTS_CREATED") {
Log.log(this.name + " recieved that all objects are created; will now hide things!");
this.updatePages();
this.sendNotification("MAX_PAGES_CHANGED", this.config.modules.length);
}
},
2017-06-18 14:16:45 -07:00
// TODO: Add slide-left/right animation
2017-06-18 13:24:04 -07:00
updatePages: function() {
if (this.config.modules.length !== 0) {
MM.getModules()
.exceptWithClass(this.config.excludes)
.exceptWithClass(this.config.modules[this.curPage])
.enumerate(module => { module.hide(this.config.animationTime / 2, { lockString: this.identifier }) });
2017-06-18 13:24:04 -07:00
let self = this;
setTimeout(function() {
MM.getModules()
.withClass(self.config.modules[self.curPage])
.enumerate(module => { module.show(self.config.animationTime / 2, { lockString: self.identifier }) });
2017-06-18 13:24:04 -07:00
}, this.config.animationTime / 2);
} else { Log.error("Pages aren't properly defined!") }
},
});