https://github.com/zeecoder/z-dom-config
A solution to load JSON configuration from DOM attributes.
https://github.com/zeecoder/z-dom-config
Last synced: 10 months ago
JSON representation
A solution to load JSON configuration from DOM attributes.
- Host: GitHub
- URL: https://github.com/zeecoder/z-dom-config
- Owner: ZeeCoder
- License: mit
- Created: 2015-06-10T10:58:10.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-08-18T14:11:59.000Z (over 10 years ago)
- Last Synced: 2025-01-27T13:14:15.600Z (12 months ago)
- Language: JavaScript
- Size: 191 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# z-dom-config
[](https://travis-ci.org/ZeeCoder/z-dom-config)
[](http://badge.fury.io/js/z-dom-config)
This module helps loading JSON configuration from `data-*` attributes.
Since it's a CommonJS module, it must be used alongside with [Browserify](http://browserify.org/), or
something similar, like [WebPacker](http://webpack.github.io/).
## Example, explanation
```html
```
```js
var dom_config = require('z-dom-config');
// Loads and parses the "data-configuration" attribute, then deep-merges the
// results with the object given as the default configuration if given.
// Note: If the string is not a valid JSON string, then a console error is shown
// and an empty object will be used instead of the attribute's contents.
dom_config.load(
// jQuery is optional, it works with `document.getElementById('target-element')` too
$('#target-element'),
'configuration',
{
bool_value: true,
something_else: 42
}
);
// -> {bool_value: false, something_else: 42}
```
## License
[MIT](LICENSE)