mirror of
https://github.com/edward-shen/MMM-pages.git
synced 2024-11-21 17:54: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.
|
||||
*/
|
||||
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);
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue