How gyxobka/plugin-spoiler works
Project Type and Purpose
• This is a lightweight front-end UI plugin (“plugin-spoiler”) written in JavaScript with accompanying SCSS for styling.
• Its purpose is to scan DOM elements marked by data attributes (data-spoilers, data-spoiler, data-spoiler-accordeon) and provide open/close “spoiler” behavior, configurable at runtime.
Main Components
a. Spoiler Module (js/Spoiler/Spoiler.js & SpoilerComponent.js)
• Spoiler.js: core class that initializes and manages multiple SpoilerComponent instances.
• SpoilerComponent.js: encapsulates one spoiler element’s behavior (open, close, toggle).
b. Styling (scss/spoiler.scss)
c. Host Application & Build System
• Webpack (or any bundler) imports the Spoiler module and bundles JS+SCSS into the final frontend assets.
d. DOM / HTML Structure
• Your page HTML: parent containers with data attributes, child title and content elements.
Relationships & Interactions
• On page load or manual init(), Spoiler scans the DOM for [data-spoilers] blocks.
• SpoilerComponent toggles CSS classes, triggers height transitions as defined in spoiler.scss.
• Configuration object (passed to the Spoiler constructor) merges with defaults to adjust behavior globally.
Architectural Patterns & Principles
• Modular: each SpoilerComponent encapsulates state & behavior for a single spoiler.
• Configuration over convention: data attributes + optional constructor options drive dynamic behavior.
• Separation of concerns: JS classes handle behavior, SCSS handles styling.
• No framework lock-in: Plain ES6 module can be plugged into any frontend stack.