Compare commits

..

No commits in common. "90a7651f4095436dfb97094b9e2e5456f92d7478" and "cc3157881aa374ad15a2ad85500318b9ceed5048" have entirely different histories.

6 changed files with 30 additions and 1621 deletions

14
.eslintrc.json Normal file
View file

@ -0,0 +1,14 @@
{
"extends": "airbnb-base",
"globals": {
"Module": true,
"Log": true,
"MM": true
},
"rules": {
"comma-dangle": "off",
"object-shorthand": "off",
"func-names": "off",
"space-before-function-paren": "off"
}
}

View file

@ -1,5 +1,8 @@
Module.register('MMM-pages', { Module.register('MMM-pages', {
// We require the older style of function declaration for compatibility
// reasons.
/** /**
* By default, we have don't pseudo-paginate any modules. We also exclude * By default, we have don't pseudo-paginate any modules. We also exclude
* the page indicator by default, in case people actually want to use the * the page indicator by default, in case people actually want to use the
@ -22,17 +25,18 @@ Module.register('MMM-pages', {
/** /**
* Apply any styles, if we have any. * Apply any styles, if we have any.
*/ */
getStyles() { getStyles: function () {
return ['pages.css']; return ['pages.css'];
}, },
/** /**
* Modulo that also works with negative numbers. * Modulo that also works with negative numbers.
* *
* @param {number} x The dividend * @param {number} x The dividend
* @param {number} n The divisor * @param {number} n The divisor
*/ */
mod(x, n) { mod: function (x, n) {
return ((x % n) + n) % n; return ((x % n) + n) % n;
}, },
@ -40,7 +44,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() { start: function () {
// Clamp homePage value to [0, num pages). // Clamp homePage value to [0, num pages).
if (this.config.homePage >= this.config.modules.length || this.config.homePage < 0) { if (this.config.homePage >= this.config.modules.length || this.config.homePage < 0) {
this.config.homePage = 0; this.config.homePage = 0;
@ -87,7 +91,7 @@ Module.register('MMM-pages', {
* @param {string} notification the notification ID * @param {string} notification the notification ID
* @param {number|string} payload the page to change to/by * @param {number|string} payload the page to change to/by
*/ */
notificationReceived(notification, payload) { notificationReceived: function (notification, payload) {
switch (notification) { switch (notification) {
case 'PAGE_CHANGED': case 'PAGE_CHANGED':
Log.log(`[MMM-pages] received a notification to change to page ${payload} of type ${typeof payload}.`); Log.log(`[MMM-pages] received a notification to change to page ${payload} of type ${typeof payload}.`);
@ -149,7 +153,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(amt, fallback) { changePageBy: function (amt, fallback) {
if (typeof amt !== 'number' && typeof fallback === 'undefined') { if (typeof amt !== 'number' && typeof fallback === 'undefined') {
Log.warn(`[MMM-pages] ${amt} is not a number!`); Log.warn(`[MMM-pages] ${amt} is not a number!`);
} }
@ -171,7 +175,7 @@ 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() { updatePages: function () {
// Update if there's at least one page. // Update if there's at least one page.
if (this.config.modules.length !== 0) { if (this.config.modules.length !== 0) {
this.animatePageChange(); this.animatePageChange();
@ -190,7 +194,7 @@ Module.register('MMM-pages', {
* @param {string} [targetPageName] the name of the hiddenPage we want to show. * @param {string} [targetPageName] the name of the hiddenPage we want to show.
* Optional and only used when we want to switch to a hidden page * Optional and only used when we want to switch to a hidden page
*/ */
animatePageChange(targetPageName) { animatePageChange: function (targetPageName) {
let lockStringObj = { lockString: this.identifier }; let lockStringObj = { lockString: this.identifier };
if (!this.config.useLockString) { if (!this.config.useLockString) {
// Passing in an undefined object is equivalent to not passing it in at // Passing in an undefined object is equivalent to not passing it in at
@ -227,7 +231,7 @@ Module.register('MMM-pages', {
* *
* @param {number} delay the delay, in milliseconds. * @param {number} delay the delay, in milliseconds.
*/ */
resetTimerWithDelay(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);
@ -271,8 +275,8 @@ Module.register('MMM-pages', {
* *
* @param {boolean} isRotating the parameter, if you want to pause or resume. * @param {boolean} isRotating the parameter, if you want to pause or resume.
*/ */
setRotation(isRotating) { setRotation: function (isRotating) {
const stateBaseString = isRotating ? 'resum' : 'paus'; const stateBaseString = (isRotating) ? "resum" : "paus";
if (isRotating === this.rotationPaused) { if (isRotating === this.rotationPaused) {
Log.warn(`[MMM-pages] was asked to ${stateBaseString}e but rotation is already ${stateBaseString}ed!`); Log.warn(`[MMM-pages] was asked to ${stateBaseString}e but rotation is already ${stateBaseString}ed!`);
} else { } else {
@ -292,7 +296,7 @@ Module.register('MMM-pages', {
* *
* @param {string} name the name of the hiddenPage we want to show * @param {string} name the name of the hiddenPage we want to show
*/ */
showHiddenPage(name) { showHiddenPage: function (name) {
// Only proceed if the named hidden page actually exists // Only proceed if the named hidden page actually exists
if (name in this.config.hiddenPages) { if (name in this.config.hiddenPages) {
this.animatePageChange(name); this.animatePageChange(name);

View file

@ -1,30 +0,0 @@
import eslintPluginJs from '@eslint/js';
import eslintPluginStylistic from '@stylistic/eslint-plugin';
import globals from 'globals';
const config = [
eslintPluginJs.configs.recommended,
eslintPluginStylistic.configs['recommended-flat'],
{
files: ['**/*.js', '**/*.mjs'],
},
{
languageOptions: {
globals: {
...globals.browser,
...globals.node,
Log: 'readonly',
MM: 'readonly',
Module: 'readonly',
},
},
rules: {
'@stylistic/brace-style': ['error', '1tbs', { allowSingleLine: true }],
'@stylistic/comma-dangle': ['error', 'only-multiline'],
'@stylistic/semi': ['error', 'always'],
'object-shorthand': ['error', 'always']
},
}
];
export default config;

1560
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -17,16 +17,5 @@
"bugs": { "bugs": {
"url": "https://github.com/edward-shen/MMM-pages/issues" "url": "https://github.com/edward-shen/MMM-pages/issues"
}, },
"homepage": "https://github.com/edward-shen/MMM-pages#readme", "homepage": "https://github.com/edward-shen/MMM-pages#readme"
"scripts": {
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"test": "npm run lint"
},
"devDependencies": {
"@eslint/js": "^9.16.0",
"@stylistic/eslint-plugin": "^2.11.0",
"eslint": "^9.16.0",
"globals": "^15.13.0"
}
} }

View file

@ -190,13 +190,5 @@ See also FAQ below.
Please make an issue. Thanks! Please make an issue. Thanks!
## Developer commands
If you want to contribute to this poject, pleases use the following commands to maintain code quality:
- `npm install` - Install development dependencies for linting.
- `npm run lint` - Run linting checks.
- `npm run lint:fix` - Fix linting issues. Please run this before committing.
[mm]: https://github.com/MagicMirrorOrg/MagicMirror [mm]: https://github.com/MagicMirrorOrg/MagicMirror
[page indicator]: https://github.com/edward-shen/MMM-page-indicator [page indicator]: https://github.com/edward-shen/MMM-page-indicator