From daa30a0edd5766215c5afa7c5e9d8c31ab7e12b3 Mon Sep 17 00:00:00 2001 From: Geert Selderslaghs Date: Thu, 2 Jan 2025 17:01:13 +0100 Subject: [PATCH] refactor(Cards) auto init unitialized cards #565 --- src/cards.ts | 11 +++++++++++ src/index.ts | 1 + 2 files changed, 12 insertions(+) diff --git a/src/cards.ts b/src/cards.ts index 110c80ede5..ebe714ee90 100644 --- a/src/cards.ts +++ b/src/cards.ts @@ -173,4 +173,15 @@ export class Cards extends Component implements Openable { } this._removeRevealCloseEventHandlers(); }; + + static Init() { + if (typeof document !== 'undefined') + // Handle initialization of static cards. + document.addEventListener('DOMContentLoaded', () => { + const cards = document.querySelectorAll('.card'); + cards.forEach((el) => { + if (el && (el['M_Card'] == undefined)) this.init((el as HTMLElement)); + }); + }); + } } diff --git a/src/index.ts b/src/index.ts index e8b227939a..4842b11aa8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -138,3 +138,4 @@ Forms.Init(); Chips.Init(); Waves.Init(); Range.Init(); +Cards.Init();