mirror of
https://github.com/edward-shen/MMM-pages.git
synced 2024-11-21 09:44:29 -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
|
* @param {number} payload the page to change to
|
||||||
*/
|
*/
|
||||||
notificationReceived: function(notification, payload) {
|
notificationReceived: function(notification, payload) {
|
||||||
|
const isValidPayload = typeof payload === 'number';
|
||||||
switch (notification) {
|
switch (notification) {
|
||||||
case 'PAGE_CHANGED':
|
case 'PAGE_CHANGED':
|
||||||
Log.log(`${this.name} recieved a notification`
|
Log.log(`${this.name} recieved a notification`
|
||||||
+ `to change to page ${payload} of type ${typeof payload}`);
|
+ `to change to page ${payload} of type ${typeof payload}`);
|
||||||
if (typeof payload === 'number') {
|
if (isValidPayload) {
|
||||||
this.curPage = payload;
|
this.curPage = payload;
|
||||||
} else {
|
} else {
|
||||||
Log.error('Was asked to change to an invalid number!');
|
Log.error('Was asked to change to an invalid number!');
|
||||||
|
@ -70,12 +71,18 @@ Module.register('MMM-pages', {
|
||||||
break;
|
break;
|
||||||
case 'PAGE_INCREMENT':
|
case 'PAGE_INCREMENT':
|
||||||
Log.log(`${this.name} recieved a notification to increment pages!`);
|
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);
|
this.updatePages(true);
|
||||||
break;
|
break;
|
||||||
case 'PAGE_DECREMENT':
|
case 'PAGE_DECREMENT':
|
||||||
Log.log(`${this.name} recieved a notification to decrement pages!`);
|
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);
|
this.updatePages(true);
|
||||||
break;
|
break;
|
||||||
case 'DOM_OBJECTS_CREATED':
|
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.
|
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
|
Sending a `PAGE_INCREMENT` or `PAGE_DECREMENT` without any parameters will
|
||||||
(or with, but it will be ignored) to have the module change the displayed page
|
increase or decrease the page by one. Attaching a valid payload to the
|
||||||
by one.
|
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
|
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
|
config in the config file. There is no way to dynamically change the pages you
|
||||||
|
|
Loading…
Reference in a new issue