mirror of
https://github.com/edward-shen/MMM-pages.git
synced 2024-12-22 00:35:09 -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
71
MMM-pages.js
71
MMM-pages.js
|
@ -3,58 +3,87 @@ 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);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
|
||||
|
||||
// TODO: Add slide-left/right animation
|
||||
updatePages: function() {
|
||||
updatePages: function (manuallyCalled) {
|
||||
if (this.config.modules.length !== 0) {
|
||||
MM.getModules()
|
||||
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!") }
|
||||
|
||||
},
|
||||
|
||||
|
||||
});
|
||||
|
|
10
readme.md
10
readme.md
|
@ -21,7 +21,7 @@ git clone https://github.com/edward-shen/MMM-pages.git
|
|||
Configure the module in your config.js file.
|
||||
|
||||
\<self-promotion>
|
||||
To display what page you're on, I'd highly recommend checking out my [page indicator module][page indicator].
|
||||
To display what page you're on, I'd highly recommend checking out my [page indicator module][page indicator].
|
||||
\<\\self-promotion>
|
||||
|
||||
## Using the module
|
||||
|
@ -48,8 +48,10 @@ 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.
|
||||
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.
|
||||
|
||||
## Regarding notifications
|
||||
|
||||
|
@ -72,11 +74,11 @@ This module sends one notification, `MAX_PAGES_CHANGED` to assist display module
|
|||
- Help! My module is (above/below) another module in the same region but I want it to be somewhere else!
|
||||
|
||||
The order of your `config.js` determines your module location. If you have two modules, both with `position:bottom_bar`, the one that is first listed will appear on top. The rest will appear in the same order you defined them in. If you want this module to be at the very bottom, define this module as the last module in your `config.js` file. If you want it to be on top in that region, make sure no other module is defined before it that has the same region.
|
||||
|
||||
|
||||
- Can I make a pull request?
|
||||
|
||||
Please do! Feel free; I love improvements!
|
||||
|
||||
|
||||
- I want more config options!
|
||||
|
||||
Please make an issue. Thanks!
|
||||
|
|
Loading…
Reference in a new issue