From c017c9f4ab9883b86cd945bac774e53e62c0bb5b Mon Sep 17 00:00:00 2001 From: Edward Shen Date: Tue, 7 Apr 2020 11:52:39 -0400 Subject: [PATCH] Implemented notification on every page change. Fixes #29. --- MMM-pages.js | 17 +++++++++-------- readme.md | 8 ++++++-- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/MMM-pages.js b/MMM-pages.js index fe2aa46..248b655 100644 --- a/MMM-pages.js +++ b/MMM-pages.js @@ -20,7 +20,7 @@ Module.register('MMM-pages', { /** * Apply any styles, if we have any. */ - getStyles: function() { + getStyles: function () { return ['pages.css']; }, @@ -31,7 +31,7 @@ Module.register('MMM-pages', { * @param {number} x The dividend * @param {number} n The divisor */ - mod: function(x, n) { + mod: function (x, n) { return ((x % n) + n) % n; }, @@ -39,7 +39,7 @@ Module.register('MMM-pages', { * Pseudo-constructor for our module. Makes sure that values aren't negative, * and sets the default current page to 0. */ - start: function() { + start: function () { this.curPage = 0; // Compatibility @@ -64,7 +64,7 @@ Module.register('MMM-pages', { * @param {string} notification the notification ID * @param {number} payload the page to change to/by */ - notificationReceived: function(notification, payload) { + notificationReceived: function (notification, payload) { switch (notification) { case 'PAGE_CHANGED': Log.log('[Pages]: received a notification ' @@ -108,7 +108,7 @@ Module.register('MMM-pages', { * @param {number} fallback the fallback value to use. Accepts negative * numbers. */ - changePageBy: function(amt, fallback) { + changePageBy: function (amt, fallback) { if (typeof amt !== 'number') { Log.warn(`[Pages]: ${amt} is not a number!`); } @@ -130,11 +130,12 @@ Module.register('MMM-pages', { * Handles hiding the current page's elements and showing the next page's * elements. */ - updatePages: function() { + updatePages: function () { // Update iff there's at least one page. if (this.config.modules.length !== 0) { this.animatePageChange(); this.resetTimerWithDelay(this.config.rotationDelay); + this.sendNotification('NEW_PAGE', this.curPage); } else { Log.error("[Pages]: Pages aren't properly defined!"); } }, @@ -143,7 +144,7 @@ Module.register('MMM-pages', { * assumes that there is a discrepancy between the page currently being shown * and the page that is meant to be shown. */ - animatePageChange: function() { + animatePageChange: function () { const self = this; // Hides all modules not on the current page. This hides any module not @@ -174,7 +175,7 @@ Module.register('MMM-pages', { * * @param {number} delay the delay, in milliseconds. */ - resetTimerWithDelay: function(delay) { + resetTimerWithDelay: function (delay) { if (this.config.rotationTime > 0) { // This timer is the auto rotate function. clearInterval(this.timer); diff --git a/readme.md b/readme.md index 0c9aa74..b0675b6 100644 --- a/readme.md +++ b/readme.md @@ -78,7 +78,7 @@ 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 -to have the module change the displayed page by one. If you attach a payload to +to have the module change the displayed page by one. If you attach a payload to these commands, it will attempt to the nth next page or nth previous page. This module keeps internal track of how many pages you have, defined by your @@ -91,10 +91,14 @@ enforce what page other modules should indicate. This is intentional, because any other module that needs a page change notification should be receiving from the notification system. -Finally, if you want to know what page you're currently on, send a `QUERY_PAGE_NUMBER` +If you want to know what page you're currently on, send a `QUERY_PAGE_NUMBER` notification. The module will respond with a `PAGE_NUMBER_IS` notification, with the payload of the current page number. +This module also sends a `NEW_PAGE` notification on every page update. The +payload is identical to as if one sent a `QUERY_PAGE_NUMBER` notification. A +separate notification tag is used for compatibility reasons. + ## FAQ - Help! My module is (above/below) another module in the same region but I want