diff --git a/MMM-pages.js b/MMM-pages.js index 713f6b1..ea9097c 100644 --- a/MMM-pages.js +++ b/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': diff --git a/readme.md b/readme.md index 6832b05..cbc11c8 100644 --- a/readme.md +++ b/readme.md @@ -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