2017-06-18 13:24:04 -07:00
|
|
|
Module.register("MMM-pages", {
|
|
|
|
defaults: {
|
|
|
|
modules: [],
|
|
|
|
excludes: ["MMM-page-indicator"],
|
|
|
|
animationTime: 1000,
|
2017-10-20 21:51:54 -07:00
|
|
|
rotationTime: 0,
|
|
|
|
rotationDelay: 10000
|
2017-06-18 13:24:04 -07:00
|
|
|
},
|
2017-10-20 21:51:54 -07:00
|
|
|
|
|
|
|
getStyles: function () {
|
2017-06-18 13:24:04 -07:00
|
|
|
return ["pages.css"];
|
|
|
|
},
|
2017-10-20 21:51:54 -07:00
|
|
|
|
|
|
|
start: function () {
|
2017-06-18 13:24:04 -07:00
|
|
|
this.curPage = 0;
|
2017-10-20 21:51:54 -07:00
|
|
|
|
|
|
|
// Disable rotation if an invalid input is given
|
|
|
|
this.config.rotationTime = Math.max(this.config.rotationTime, 0);
|
|
|
|
this.config.rotationDelay = Math.max(this.config.rotationDelay, 0);
|
|
|
|
|
|
|
|
Log.log(this.config.rotationTime + "|" + this.config.rotationDelay);
|
2017-06-18 13:24:04 -07:00
|
|
|
},
|
2017-10-20 21:51:54 -07:00
|
|
|
|
|
|
|
notificationReceived: function (notification, payload, sender) {
|
2017-06-18 13:24:04 -07:00
|
|
|
if (notification === "PAGE_CHANGED") {
|
|
|
|
Log.log(this.name + " recieved a notification to change to page " + payload);
|
|
|
|
this.curPage = payload;
|
2017-10-20 21:51:54 -07:00
|
|
|
this.updatePages(true);
|
2017-06-18 13:24:04 -07:00
|
|
|
} 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++ }
|
2017-10-20 21:51:54 -07:00
|
|
|
this.updatePages(true);
|
2017-06-18 13:24:04 -07:00
|
|
|
} 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-- }
|
2017-10-20 21:51:54 -07:00
|
|
|
this.updatePages(true);
|
2017-06-18 13:24:04 -07:00
|
|
|
} else if (notification === "DOM_OBJECTS_CREATED") {
|
|
|
|
Log.log(this.name + " recieved that all objects are created; will now hide things!");
|
2017-10-20 21:51:54 -07:00
|
|
|
this.updatePages(true);
|
|
|
|
|
2017-06-18 13:24:04 -07:00
|
|
|
this.sendNotification("MAX_PAGES_CHANGED", this.config.modules.length);
|
|
|
|
}
|
|
|
|
},
|
2017-10-20 21:51:54 -07:00
|
|
|
|
|
|
|
|
2017-06-18 14:16:45 -07:00
|
|
|
// TODO: Add slide-left/right animation
|
2017-10-20 21:51:54 -07:00
|
|
|
updatePages: function (manuallyCalled) {
|
2017-06-18 13:24:04 -07:00
|
|
|
if (this.config.modules.length !== 0) {
|
2017-10-20 21:51:54 -07:00
|
|
|
Log.log("updatePages was called with manuallyCalled = " + manuallyCalled);
|
|
|
|
const self = this;
|
|
|
|
MM.getModules()
|
2017-06-18 13:24:04 -07:00
|
|
|
.exceptWithClass(this.config.excludes)
|
|
|
|
.exceptWithClass(this.config.modules[this.curPage])
|
2017-08-26 23:43:31 -07:00
|
|
|
.enumerate(module => { module.hide(this.config.animationTime / 2, { lockString: this.identifier }) });
|
2017-10-20 21:51:54 -07:00
|
|
|
|
|
|
|
setTimeout(function () {
|
2017-06-18 13:24:04 -07:00
|
|
|
MM.getModules()
|
|
|
|
.withClass(self.config.modules[self.curPage])
|
2017-10-20 21:51:54 -07:00
|
|
|
.enumerate(module => {
|
|
|
|
module.show(self.config.animationTime / 2,
|
|
|
|
{ lockString: self.identifier });
|
|
|
|
});
|
2017-06-18 13:24:04 -07:00
|
|
|
}, this.config.animationTime / 2);
|
2017-10-20 21:51:54 -07:00
|
|
|
|
|
|
|
if (manuallyCalled && this.config.rotationTime > 0) {
|
|
|
|
Log.log("manually updated page! setting delay before resume timer!");
|
|
|
|
|
|
|
|
clearInterval(this.timer);
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
self.timer = setInterval(() => {
|
|
|
|
// Incrementing page
|
|
|
|
if (self.curPage === self.config.modules.length - 1) {
|
|
|
|
self.curPage = 0;
|
|
|
|
} else { self.curPage++ }
|
|
|
|
self.sendNotification("PAGE_INCREMENT");
|
|
|
|
self.updatePages(false);
|
|
|
|
}, self.config.rotationTime, false);
|
|
|
|
}, this.config.rotationDelay);
|
|
|
|
}
|
2017-06-18 13:24:04 -07:00
|
|
|
} else { Log.error("Pages aren't properly defined!") }
|
2017-10-20 21:51:54 -07:00
|
|
|
|
2017-06-18 13:24:04 -07:00
|
|
|
},
|
2017-10-20 21:51:54 -07:00
|
|
|
|
2017-06-18 13:24:04 -07:00
|
|
|
});
|