mirror of
https://github.com/edward-shen/MMM-pages.git
synced 2024-11-22 02:04:29 -08:00
added automatic page rotation
forgot to add scope of max function fixed reference issuese with setInterval moved manual call inside fo check added debugging lol scoping issue moved null check to inside updatePages Forgot to access config before accessing config variables forgot to increment the apge when automatically updating fixed config check fixed conditional moved page incrementation into nested function added notification that the page incremented fixed readme
This commit is contained in:
parent
f48cebf4ab
commit
ba0aa4696a
2 changed files with 56 additions and 25 deletions
53
MMM-pages.js
53
MMM-pages.js
|
@ -3,37 +3,44 @@ Module.register("MMM-pages", {
|
|||
modules: [],
|
||||
excludes: ["MMM-page-indicator"],
|
||||
animationTime: 1000,
|
||||
|
||||
rotationTime: 0,
|
||||
rotationDelay: 10000
|
||||
},
|
||||
|
||||
getStyles: function() {
|
||||
getStyles: function () {
|
||||
return ["pages.css"];
|
||||
},
|
||||
|
||||
start: function() {
|
||||
start: function () {
|
||||
this.curPage = 0;
|
||||
|
||||
// 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);
|
||||
},
|
||||
|
||||
notificationReceived: function(notification, payload, sender) {
|
||||
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();
|
||||
this.updatePages(true);
|
||||
} 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();
|
||||
this.updatePages(true);
|
||||
} 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();
|
||||
this.updatePages(true);
|
||||
} else if (notification === "DOM_OBJECTS_CREATED") {
|
||||
Log.log(this.name + " recieved that all objects are created; will now hide things!");
|
||||
this.updatePages();
|
||||
this.updatePages(true);
|
||||
|
||||
this.sendNotification("MAX_PAGES_CHANGED", this.config.modules.length);
|
||||
}
|
||||
|
@ -41,20 +48,42 @@ Module.register("MMM-pages", {
|
|||
|
||||
|
||||
// TODO: Add slide-left/right animation
|
||||
updatePages: function() {
|
||||
updatePages: function (manuallyCalled) {
|
||||
if (this.config.modules.length !== 0) {
|
||||
Log.log("updatePages was called with manuallyCalled = " + manuallyCalled);
|
||||
const self = this;
|
||||
MM.getModules()
|
||||
.exceptWithClass(this.config.excludes)
|
||||
.exceptWithClass(this.config.modules[this.curPage])
|
||||
.enumerate(module => { module.hide(this.config.animationTime / 2, { lockString: this.identifier }) });
|
||||
|
||||
let self = this;
|
||||
setTimeout(function() {
|
||||
setTimeout(function () {
|
||||
MM.getModules()
|
||||
.withClass(self.config.modules[self.curPage])
|
||||
.enumerate(module => { module.show(self.config.animationTime / 2, { lockString: self.identifier }) });
|
||||
.enumerate(module => {
|
||||
module.show(self.config.animationTime / 2,
|
||||
{ lockString: self.identifier });
|
||||
});
|
||||
}, this.config.animationTime / 2);
|
||||
|
||||
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);
|
||||
}
|
||||
} else { Log.error("Pages aren't properly defined!") }
|
||||
|
||||
},
|
||||
|
||||
});
|
||||
|
|
|
@ -48,6 +48,8 @@ Option|Description
|
|||
`modules`|A 2D String array of what each module should be on which page. Note that all entries must take their class name (e.g. this module's class name is `MMM-pages`, while the default modules may just have `newsfeed`, without the `MMM-` prefix.<br/>**Expected Value type:** `[ [String, String, ...], [String, String, ...], ...]`.
|
||||
`excludes`|Which modules should show up all the time.<br/>**Expected Value type:** `[ String, String, ... ]`.
|
||||
`animationTime`|Fading animation time. Set to `0` for instant change. Value is in millis.<br/>**Expected Value type:** `int`.
|
||||
`rotationTime`|Time, in milliseconds (1 second = 1000 milliseconds), between automatic page changes.<br/>**Expected Value type:** `int`.<br/>**Default value:** `0`
|
||||
`delayTime`|Time, in milliseconds, of how long should a manual page change linger before returning to automatic page changing. In other words, how long should the timer wait for after you manually change a page. This does include the animation time, so you may wish to increase it by a few seconds or so to account for the animation time.<br/>**Expected Value type:** `int`.<br/>**Default value:** `10000`
|
||||
|
||||
For the `module` configuration option, the first element of the outer array should consist of elements that should be on the first page. The second element should consist of elements that should be on the second page, and so forth.
|
||||
|
||||
|
|
Loading…
Reference in a new issue