mirror of
https://github.com/edward-shen/MMM-pages.git
synced 2024-12-22 08:45:09 -08:00
added support for changing by a certain amount of pages
This commit is contained in:
parent
2d0eb22a6d
commit
f4fc53fa19
2 changed files with 14 additions and 6 deletions
13
MMM-pages.js
13
MMM-pages.js
|
@ -55,11 +55,12 @@ Module.register('MMM-pages', {
|
|||
* @param {number} payload the page to change to
|
||||
*/
|
||||
notificationReceived: function(notification, payload) {
|
||||
const isValidPayload = typeof payload === 'number';
|
||||
switch (notification) {
|
||||
case 'PAGE_CHANGED':
|
||||
Log.log(`${this.name} recieved a notification`
|
||||
+ `to change to page ${payload} of type ${typeof payload}`);
|
||||
if (typeof payload === 'number') {
|
||||
if (isValidPayload) {
|
||||
this.curPage = payload;
|
||||
} else {
|
||||
Log.error('Was asked to change to an invalid number!');
|
||||
|
@ -70,12 +71,18 @@ Module.register('MMM-pages', {
|
|||
break;
|
||||
case 'PAGE_INCREMENT':
|
||||
Log.log(`${this.name} recieved a notification to increment pages!`);
|
||||
this.curPage = this.mod(this.curPage + 1, this.config.modules.length);
|
||||
this.curPage = this.mod(
|
||||
this.curPage + (isValidPayload) ? payload : 1,
|
||||
this.config.modules.length
|
||||
);
|
||||
this.updatePages(true);
|
||||
break;
|
||||
case 'PAGE_DECREMENT':
|
||||
Log.log(`${this.name} recieved a notification to decrement pages!`);
|
||||
this.curPage = this.mod(this.curPage - 1, this.config.modules.length);
|
||||
this.curPage = this.mod(
|
||||
this.curPage - (isValidPayload) ? payload : 1,
|
||||
this.config.modules.length
|
||||
);
|
||||
this.updatePages(true);
|
||||
break;
|
||||
case 'DOM_OBJECTS_CREATED':
|
||||
|
|
|
@ -76,9 +76,10 @@ this.sendNotification("PAGE_CHANGED", 2);
|
|||
```
|
||||
This would cause the module to change show that you are on page 3.
|
||||
|
||||
You can also just send `PAGE_INCREMENT` or `PAGE_DECREMENT` without any payloads
|
||||
(or with, but it will be ignored) to have the module change the displayed page
|
||||
by one.
|
||||
Sending a `PAGE_INCREMENT` or `PAGE_DECREMENT` without any parameters will
|
||||
increase or decrease the page by one. Attaching a valid payload to the
|
||||
aforementioned notifications will increase or decrease the pages by that amount.
|
||||
Remember that this module **strictly checks** for a number.
|
||||
|
||||
This module keeps internal track of how many pages you have, defined by your
|
||||
config in the config file. There is no way to dynamically change the pages you
|
||||
|
|
Loading…
Reference in a new issue