diff options
| author | GeoSot <[email protected]> | 2022-04-21 21:41:43 +0300 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-04-21 21:41:43 +0300 |
| commit | 584600bda36ac13ea325617783216d6c6a331c08 (patch) | |
| tree | 053f97d3e8401864aca9c0b8e180a3d2c089b4be /js/src/dom | |
| parent | 01cffa682249965eafa581058dd993853d82b3c4 (diff) | |
| download | bootstrap-584600bda36ac13ea325617783216d6c6a331c08.tar.xz bootstrap-584600bda36ac13ea325617783216d6c6a331c08.zip | |
Manipulator: Add JSON parse support (#35077)
Support parsing JSON from each component's main element using the `data-bs-config` attribute.
The `bs-config` attribute will be reserved and omitted during `getDataAttributes` parsing.
With this commit, every component, will create its config object, using:
* defaults
* data-bs-config
* the rest of data attributes
* configuration object given during instance initialization
Co-authored-by: XhmikosR <[email protected]>
Co-authored-by: Mark Otto <[email protected]>
Co-authored-by: Mark Otto <[email protected]>
Diffstat (limited to 'js/src/dom')
| -rw-r--r-- | js/src/dom/manipulator.js | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/js/src/dom/manipulator.js b/js/src/dom/manipulator.js index 5e6ad92ae..2d96d65fc 100644 --- a/js/src/dom/manipulator.js +++ b/js/src/dom/manipulator.js @@ -22,7 +22,15 @@ function normalizeData(value) { return null } - return value + if (typeof value !== 'string') { + return value + } + + try { + return JSON.parse(decodeURIComponent(value)) + } catch { + return value + } } function normalizeDataKey(key) { @@ -44,7 +52,7 @@ const Manipulator = { } const attributes = {} - const bsKeys = Object.keys(element.dataset).filter(key => key.startsWith('bs')) + const bsKeys = Object.keys(element.dataset).filter(key => key.startsWith('bs') && !key.startsWith('bsConfig')) for (const key of bsKeys) { let pureKey = key.replace(/^bs/, '') |
