Closed Burnallover closed 4 years ago
Module.register('MMM-pages', {
// We require the older style of function declaration for compatibility // reasons.
/**
sister module. We also don't rotate out modules by default. */ defaults: { modules: [], excludes: [], // Keep for compatibility fixed: ['MMM-page-indicator'], animationTime: 1000, rotationTime: 0, rotationFirstpage:0, rotationDelay: 10000
},
/**
Apply any styles, if we have any. */ getStyles: function () { return ['pages.css']; },
/**
@param {number} n The divisor */ mod: function (x, n) { return ((x % n) + n) % n; },
/**
and sets the default current page to 0. */ start: function () { this.curPage = 0; this.rotationPaused = false;
// Compatibility if (this.config.excludes.length) { Log.warn('[Pages]: The config option "excludes" is deprecated. Please use "fixed" instead.'); this.config.fixed = this.config.excludes; }
// Disable rotation if an invalid input is given this.config.rotationTime = Math.max(this.config.rotationTime, 0); this.config.rotationDelay = Math.max(this.config.rotationDelay, 0); this.config.rotationFirstpage = Math.max(this.config.rotationFirstpage, 0); },
/**
@param {number} payload the page to change to/by */ notificationReceived: function (notification, payload) { switch (notification) { case 'PAGE_CHANGED': Log.log('[Pages]: received a notification '
to change to page ${payload} of type ${typeof payload}
);
this.curPage = payload;
this.updatePages();
break;
case 'PAGE_INCREMENT':
Log.log('[Pages]: received a notification to increment pages!');
this.changePageBy(payload, 1);
this.updatePages();
break;
case 'PAGE_DECREMENT':
Log.log('[Pages]: received a notification to decrement pages!');
// We can't just pass in -payload for situations where payload is null
// JS will coerce -payload to -0.
this.changePageBy(payload ? -payload : payload, -1);
this.updatePages();
break;
case 'DOM_OBJECTS_CREATED':
Log.log('[Pages]: received that all objects are created;'/**
numbers.
*/
changePageBy: function (amt, fallback) {
if (typeof amt !== 'number') {
Log.warn([Pages]: ${amt} is not a number!
);
}
if (typeof amt === 'number' && !Number.isNaN(amt)) { this.curPage = this.mod( this.curPage + amt, this.config.modules.length ); } else if (typeof fallback === 'number') { this.curPage = this.mod( this.curPage + fallback, this.config.modules.length ); } },
/**
elements. */ updatePages: function () { // Update iff there's at least one page. if (this.config.modules.length !== 0) { this.animatePageChange(); if (!this.rotationPaused) { this.resetTimerWithDelay(this.config.rotationDelay); } this.sendNotification('NEW_PAGE', this.curPage); } else { Log.error("[Pages]: Pages aren't properly defined!"); } },
/**
and the page that is meant to be shown. */ animatePageChange: function () { const self = this;
// Hides all modules not on the current page. This hides any module not // meant to be shown. MM.getModules() .exceptWithClass(this.config.fixed) .exceptWithClass(this.config.modules[this.curPage]) .enumerate(module => module.hide( self.config.animationTime / 2, { lockString: self.identifier } ));
// Shows all modules meant to be on the current page, after a small delay. setTimeout(() => { MM.getModules() .withClass(self.config.modules[self.curPage]) .enumerate((module) => { module.show( self.config.animationTime / 2, { lockString: self.identifier } ); }); }, this.config.animationTime / 2); },
/**
@param {number} delay the delay, in milliseconds. */ resetTimerWithDelay: function (delay) { if (this.config.rotationTime > 0) { // This timer is the auto rotate function. clearInterval(this.timer); // This is delay timer after manually updating. clearInterval(this.delayTimer); const self = this;
this.delayTimer = setTimeout(() => { self.timer = setInterval(() => { self.sendNotification('PAGE_INCREMENT'); self.changePageBy(1); self.updatePages(); }, self.config.rotationTime); }, delay); }if (this.config.rotationFirstpage > 0) { // This timer is the auto rotate function. clearInterval(this.timer); // This is delay timer after manually updating. clearInterval(this.delayTimer); const self = this;
this.delayTimer = setTimeout(() => { self.timer = setInterval(() => { self.sendNotification('PAGE_CHANGED', 0); self.changePageBy(-this.curPage); self.updatePages(); }, self.config.rotationFirstpage); }, delay); } }, });
Hello, first of all thank you for your great job! I'm not a developer, i searched a way to Return to first page after a delimited time, but without the automatic loop option of your module.
i have a first page with generic information, and some other page with confidential information. i manually change page with alexa and want the Mirror automatically return to the first page after 30 second.
hi resolved my problem by modifying your JS but i'm sure there is a more "cleanly" method. Here is what i did :
Sorry for my english :-\
regards Kevin