Implemented notification on every page change.

Fixes #29.
This commit is contained in:
Edward Shen 2020-04-07 11:52:39 -04:00
parent 22a1e543b6
commit c017c9f4ab
Signed by: edward
GPG key ID: 19182661E818369F
2 changed files with 15 additions and 10 deletions

View file

@ -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);

View file

@ -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