diff options
Diffstat (limited to 'js/src')
| -rw-r--r-- | js/src/dom/manipulator.js | 12 | ||||
| -rw-r--r-- | js/src/util/config.js | 3 |
2 files changed, 13 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/, '') diff --git a/js/src/util/config.js b/js/src/util/config.js index 19d02955d..f6c194276 100644 --- a/js/src/util/config.js +++ b/js/src/util/config.js @@ -38,8 +38,11 @@ class Config { } _mergeConfigObj(config, element) { + const jsonConfig = isElement(element) ? Manipulator.getDataAttribute(element, 'config') : {} // try to parse + return { ...this.constructor.Default, + ...(typeof jsonConfig === 'object' ? jsonConfig : {}), ...(isElement(element) ? Manipulator.getDataAttributes(element) : {}), ...(typeof config === 'object' ? config : {}) } |
