mirror of
https://github.com/edward-shen/MMM-pages.git
synced 2024-11-22 02:04:29 -08:00
parent
22a1e543b6
commit
c017c9f4ab
2 changed files with 15 additions and 10 deletions
17
MMM-pages.js
17
MMM-pages.js
|
@ -20,7 +20,7 @@ Module.register('MMM-pages', {
|
||||||
/**
|
/**
|
||||||
* Apply any styles, if we have any.
|
* Apply any styles, if we have any.
|
||||||
*/
|
*/
|
||||||
getStyles: function() {
|
getStyles: function () {
|
||||||
return ['pages.css'];
|
return ['pages.css'];
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ Module.register('MMM-pages', {
|
||||||
* @param {number} x The dividend
|
* @param {number} x The dividend
|
||||||
* @param {number} n The divisor
|
* @param {number} n The divisor
|
||||||
*/
|
*/
|
||||||
mod: function(x, n) {
|
mod: function (x, n) {
|
||||||
return ((x % n) + n) % 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,
|
* Pseudo-constructor for our module. Makes sure that values aren't negative,
|
||||||
* and sets the default current page to 0.
|
* and sets the default current page to 0.
|
||||||
*/
|
*/
|
||||||
start: function() {
|
start: function () {
|
||||||
this.curPage = 0;
|
this.curPage = 0;
|
||||||
|
|
||||||
// Compatibility
|
// Compatibility
|
||||||
|
@ -64,7 +64,7 @@ Module.register('MMM-pages', {
|
||||||
* @param {string} notification the notification ID
|
* @param {string} notification the notification ID
|
||||||
* @param {number} payload the page to change to/by
|
* @param {number} payload the page to change to/by
|
||||||
*/
|
*/
|
||||||
notificationReceived: function(notification, payload) {
|
notificationReceived: function (notification, payload) {
|
||||||
switch (notification) {
|
switch (notification) {
|
||||||
case 'PAGE_CHANGED':
|
case 'PAGE_CHANGED':
|
||||||
Log.log('[Pages]: received a notification '
|
Log.log('[Pages]: received a notification '
|
||||||
|
@ -108,7 +108,7 @@ Module.register('MMM-pages', {
|
||||||
* @param {number} fallback the fallback value to use. Accepts negative
|
* @param {number} fallback the fallback value to use. Accepts negative
|
||||||
* numbers.
|
* numbers.
|
||||||
*/
|
*/
|
||||||
changePageBy: function(amt, fallback) {
|
changePageBy: function (amt, fallback) {
|
||||||
if (typeof amt !== 'number') {
|
if (typeof amt !== 'number') {
|
||||||
Log.warn(`[Pages]: ${amt} is not a 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
|
* Handles hiding the current page's elements and showing the next page's
|
||||||
* elements.
|
* elements.
|
||||||
*/
|
*/
|
||||||
updatePages: function() {
|
updatePages: function () {
|
||||||
// Update iff there's at least one page.
|
// Update iff there's at least one page.
|
||||||
if (this.config.modules.length !== 0) {
|
if (this.config.modules.length !== 0) {
|
||||||
this.animatePageChange();
|
this.animatePageChange();
|
||||||
this.resetTimerWithDelay(this.config.rotationDelay);
|
this.resetTimerWithDelay(this.config.rotationDelay);
|
||||||
|
this.sendNotification('NEW_PAGE', this.curPage);
|
||||||
} else { Log.error("[Pages]: Pages aren't properly defined!"); }
|
} 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
|
* assumes that there is a discrepancy between the page currently being shown
|
||||||
* and the page that is meant to be shown.
|
* and the page that is meant to be shown.
|
||||||
*/
|
*/
|
||||||
animatePageChange: function() {
|
animatePageChange: function () {
|
||||||
const self = this;
|
const self = this;
|
||||||
|
|
||||||
// Hides all modules not on the current page. This hides any module not
|
// 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.
|
* @param {number} delay the delay, in milliseconds.
|
||||||
*/
|
*/
|
||||||
resetTimerWithDelay: function(delay) {
|
resetTimerWithDelay: function (delay) {
|
||||||
if (this.config.rotationTime > 0) {
|
if (this.config.rotationTime > 0) {
|
||||||
// This timer is the auto rotate function.
|
// This timer is the auto rotate function.
|
||||||
clearInterval(this.timer);
|
clearInterval(this.timer);
|
||||||
|
|
|
@ -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
|
any other module that needs a page change notification should be receiving from
|
||||||
the notification system.
|
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,
|
notification. The module will respond with a `PAGE_NUMBER_IS` notification,
|
||||||
with the payload of the current page number.
|
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
|
## FAQ
|
||||||
|
|
||||||
- Help! My module is (above/below) another module in the same region but I want
|
- Help! My module is (above/below) another module in the same region but I want
|
||||||
|
|
Loading…
Reference in a new issue