Skip to content

Feature Updates to Original Version#18

Open
shbatm wants to merge 245 commits into
barnabycolby:masterfrom
shbatm:master
Open

Feature Updates to Original Version#18
shbatm wants to merge 245 commits into
barnabycolby:masterfrom
shbatm:master

Conversation

@shbatm
Copy link
Copy Markdown

@shbatm shbatm commented May 9, 2018

New: Slide Indicators and Navigation Buttons can be enabled (see config settings)
New: Modules can be moved to different positions and CSS classes applied to them for each slide.
New: Multiple instances of a module can be used on different slides.
New: Integration with MMM-KeyBindings for keyboard and bluetooth remote navigation.

shbatm and others added 30 commits May 15, 2017 12:00
Typo in advanced slides carousel.
Fixes other typo in Readme.
The following vulnerabilities are fixed with an upgrade:
- https://snyk.io/vuln/npm:braces:20180219

Latest report for shbatm/mmm-carousel:
https://snyk.io/test/github/shbatm/mmm-carousel
[Snyk Update] New fixes for 2 vulnerable dependency paths
KristjanESPERANTO and others added 30 commits November 14, 2025 18:31
Replace confusing bind/call pattern where modules array was used as `this`
context with a clean object-oriented approach:

- Remove global carouselInstance variable (no longer needed)
- buildModulesContext() now returns clean context object instead of
  mutating array with properties
- moduleTransition() uses this.modulesContext instead of array-as-this
- Extract selectWrapper() as standalone method
- Simplify showModulesForSlide() to use for...of loops
- manualTransition as arrow function closure

Benefits:
- Clearer code: this always refers to carousel instance
- Better separation: modules array vs configuration object
- More maintainable: standard OOP pattern
- Easier to understand: no "clever" bind/call tricks
Replace mixed setInterval/setTimeout approach with recursive setTimeout
pattern for cleaner and more maintainable timer management.

Changes:
- Remove all setInterval usage, use only setTimeout
- Remove all clearInterval calls, only clearTimeout needed
- Centralize timer logic in scheduleNextTransition()
- Remove setupAutomaticTransitions() helper (no longer needed)
- Schedule next transition after fade completes in moduleTransition()
- Simplify restartTimer() to delegate to scheduleNextTransition()
- Remove unused defaultTimer from context object
- Remove timer parameter from buildModulesContext()

Benefits:
- Single timer type = simpler code
- No timer type confusion (interval vs timeout)
- All timer modes handled in one place
- More flexible per-transition timing
- No setInterval drift issues
- Replace parseInt() with Number() for cleaner type conversion
- Add explicit validation using Number.isInteger() and bounds checking
- Use guard clause pattern instead of try/catch blocks
- Simplify object validation (payload && payload.slide)
- Reduce from 18 to 16 lines while improving robustness
Bumps [actions/checkout](https://github.com/actions/checkout) from 5 to 6.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](actions/checkout@v5...v6)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
In positional mode, setUpTransitionTimers was called in a loop for each
enabled position, but the context was stored in a single shared variable,
causing each iteration to overwrite the previous position's context.

Fixed by using closure-captured context in setInterval for each position,
ensuring all enabled positions rotate independently.
Add built-in keyboard navigation that works without MMM-KeyBindings,
making carousel control more accessible out-of-the-box.

Features:
- New config option `enableKeyboardControl` (default: false)
- Keyboard shortcuts:
  - Arrow Right/Left: next/previous slide
  - Arrow Down: pause/resume rotation
  - Home or 0: jump to home slide
  - 1-9: jump to slide 1-9 (key "1" = first slide)
- Only works in 'global' or 'slides' mode (not 'positional')
- Smart bounds checking prevents navigation to non-existent slides
- Ignores keypresses in input fields

Improvements:
- Split keyboard logic into separate methods for better maintainability
  (getMaxSlideIndex, handleKeyboardEvent, setupNativeKeyboardHandler)
- Added null-check in updatePause() to prevent crash when carousel
  container doesn't exist
- Added guards in validKeyPress() for positional mode and
  uninitialized manualTransition

Demo configs:
- Added demo.config.global.js for global mode demonstration
- Updated demo.config.slides.js to actually use slides mode
- Updated demo.config.positional.js (removed KeyBindings, added note)
- Added npm scripts: demo:global, demo:slides, demo:positional

Documentation:
- Updated README with enableKeyboardControl option and keyboard shortcuts
- Clarified that native keyboard control only works in global/slides modes
- Updated "Additional features" section to highlight native keyboard control

Technical notes:
- Uses capture phase (addEventListener with true) for reliable event handling
- Only preventDefault() (no stopPropagation()) to avoid blocking other modules
- Handler stored as instance variable to allow future cleanup if needed
- No dependency on MMM-KeyBindings for basic keyboard navigation
…uleInSlide

Add optional chaining (?.) when accessing module.data.config.carouselId to
prevent TypeError crashes when modules don't have a data property.

Previously, the code would throw "Cannot read properties of undefined
(reading 'config')" when checking carouselId on modules without data.
Now it safely returns undefined and the module matches by name anyway.
Extract calculateIndicatorIds() from updateSlideIndicators() to separate
business logic from DOM manipulation. This pure function calculates all
element IDs for slide indicators and navigation controls based on current
index and boundaries.

Benefits:
- calculateIndicatorIds() is now fully testable without DOM mocking
- updateSlideIndicators() is simpler and focused on DOM updates only
- Edge cases (first/last/single slide) are covered by unit tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.