An open API service indexing awesome lists of open source software.

https://github.com/code-mike-code/js-gallery-slider-refactored

The original slider was functional but built with older JavaScript syntax and global functions. My job was to rebuild it into a clean, maintainable class-based module, making full use of ECMAScript 2015+ features
https://github.com/code-mike-code/js-gallery-slider-refactored

arrow-functions babel constructor es6-javascript javascript js-classes webpack

Last synced: 10 days ago
JSON representation

The original slider was functional but built with older JavaScript syntax and global functions. My job was to rebuild it into a clean, maintainable class-based module, making full use of ECMAScript 2015+ features

Awesome Lists containing this project

README

        

# JavaScript: ECMAScript 2015+ – Gallery Slider Refactor

### See the live version of [ECMAScript Gallery Slider](https://code-mike-code.github.io/js-gallery-slider-refactored/)

This project is part of my learning path with the mentor program at devmentor.pl. The goal was to refactor a legacy image slider by applying modern JavaScript standards (ES6+), modular structure, and proper code separation.

## πŸ”„ Project Overview
The original slider was functional but built with older JavaScript syntax and global functions. My job was to rebuild it into a clean, maintainable class-based module, making full use of ECMAScript 2015+ features such as:

β€’ class and constructor
β€’ arrow functions
β€’ destructuring
β€’ default parameters
β€’ spread/rest syntax
β€’ module exports/imports

The new structure allows for easier debugging, maintenance, and further scalability.

## 🧱 Key Concepts Applied
### 🧩 Class-Based Architecture
The core logic now lives in a single class:
```
import JSSlider from './modules/JSSlider';

const jsSlider = new JSSlider('.gallery__item');
jsSlider.run();
```

This class encapsulates all behaviors, internal state, and DOM interactions, following the Single Responsibility Principle.

![](./assets/img/img1.png)

## πŸ”Œ Modular Code with Webpack
To ensure browser compatibility (for all major browsers post-2016 with >1% market share), the entire project is bundled with Webpack.

Webpack handles:

ES6+ transpilation via Babel

Module bundling

Static file serving (images/CSS) during development
```
// webpack.config.js
module.exports = {
// ...
devServer: {
static: './',
},
}
```

Β 

## πŸ” Custom Events Integration
Just like the original implementation, the refactored version relies on a custom event system for interactivity:

js-slider-img-click

js-slider-img-next

js-slider-img-prev

js-slider-close

js-slider-start (NEW)

js-slider-stop (NEW)

These events promote decoupling, make debugging easier, and are useful for future event-based integrations.

## 🧠 Internal Features & Improvements
Grouped images by dynamic data-slider-group-name

Navigation with arrow buttons (looped cycling supported)

Automatic slideshow start/stop on hover events

Internal this.imagesList property shared across methods (instead of parameter passing)

## πŸš€ Additional Functionality
Task 1 – Property-based Internal State
Instead of passing DOM elements to every method, key variables like image lists and current indexes are stored directly in the class instance (e.g. this.imagesList, this.currentGroup).

Task 2 – Auto Slideshow with Event Control
Introduced two new custom events:

β€’ js-slider-start: triggers slideshow autoplay after clicking an image or leaving arrow hover

β€’ js-slider-stop: pauses slideshow when hovering over arrows

Edge cases (like multiple hover entries or restarts) were handled with timers and flags.

Β 

## πŸ’‘ Technologies

Β 

## πŸ”— See also
If you're interested in JavaScript-based UI projects, check out my other project: [Excursions Order Panel](https://code-mike-code.github.io/excursions-order-panel/)

Β 

## πŸ’Ώ Installation
1. Clone the repository

2. Run npm install

3. Start development server:

```
npm start
```

Β 

## 🏁 Summary

β€’ This project gave me hands-on experience in:
β€’ Refactoring real-world legacy code using modern JS
β€’ Using Webpack and Babel for browser support
β€’ Structuring scalable UI components with classes and modules
β€’ Managing state and behavior using Custom Events
β€’ Applying software engineering best practices like encapsulation, SRP, and DRY

Β 

## πŸ™‹β€β™‚οΈ Let’s Connect!
Got feedback, questions, or just want to talk about frontend stuff? I'm happy to hear from you!

Β 

## πŸ‘ Thanks / Credits
Special thanks to devmentor.pl for providing this real-world exercise and mentorship support.

Β