Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
firestar300 committed Dec 17, 2024
2 parents b538bdd + dfffa73 commit 3b67a4a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
5 changes: 3 additions & 2 deletions examples/accessible-accordion/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ Accordion.initFromPreset();
| `forceExpand` | boolean | `true` | If true, the accordion has at least one panel opened. |
| `hasAnimation` | boolean | `false` | If true, the panel has a slideDown / slideUp animation. |
| `mediaQuery` | null or matchMedia object | `null` | Set dropdown for a specific media query. |
| `onClose` | null or function | `null` | Opened panel callback. |
| `onOpen` | null or function | `null` | Closed panel callback. |
| `onInit` | null or function | `null` | Event when component is initialized. |
| `onClose` | null or function | `null` | Event when a panel is opened. |
| `onOpen` | null or function | `null` | Event when a panel is closed. |
| `onReachBreakpoint` | null or function | `null` | Event when the media query is reached if `mediaQuery` option is filled. |
| `panelSelector` | string | `.accordion__panel` | The selector of the panels. |
| `prefixId` | string | `accordion` | The prefix id of the component. |
Expand Down
3 changes: 3 additions & 0 deletions examples/accessible-accordion/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,9 @@ <h2>Code</h2>
'#accordion-demo-5': { closedDefault: true },
'#accordion-demo-6': {
forceExpand: false,
onInit: function(el) {
console.log(`${el.id} initialized`)
},
onClose: function(panel) {
alert(`${panel.id} closed`)
},
Expand Down
12 changes: 9 additions & 3 deletions src/classes/Accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,22 @@ class Accordion extends AbstractDomElement {
* @author Milan Ricoul
*/
init() {
this.active = true

const el = this._element
const { closedDefault, mediaQuery, onReachBreakpoint, panelSelector, prefixId, triggerSelector } = this._settings
const { closedDefault, mediaQuery, onInit, onReachBreakpoint, panelSelector, prefixId, triggerSelector } = this._settings
const pattern = /\d+/g
const triggers = el.querySelectorAll(triggerSelector)
const panels = el.querySelectorAll(panelSelector)
const id = randomId()

el.dataset.id = id

if (onInit && !this.active) {
this.active = true
onInit.bind(this)(el)
}

this.active = true

if (mediaQuery && onReachBreakpoint && pattern.test(mediaQuery.media)) {
if (mediaQuery.media.includes('min')) {
this.hasReachBreakpoint = window.innerWidth > parseInt(mediaQuery.media.match(pattern)[0]) ? 'above' : 'below'
Expand Down Expand Up @@ -427,6 +432,7 @@ Accordion.defaults = {
forceExpand: true,
hasAnimation: false,
mediaQuery: null,
onInit: null,
onReachBreakpoint: null,
onOpen: null,
onClose: null,
Expand Down

0 comments on commit 3b67a4a

Please sign in to comment.