Open mhulse opened 11 years ago
Super sick way of merging JSON data-
attribute with a plugin's defaults
:
HTML:
<section class="ion" data-ion-options='{"allowMultiple" : true}'>...</section>
JS:
defaults { allowMultiple : false }, // ...
// ... later:
settings = $.extend(true, {}, defaults, options, $this.data('ionOptions')); // Merge defaults, options and data attribute options.
// ... later:
if ( ! data.settings.allowMultiple) { ... }
Code comes from an accordion plugin I'm working on.
Kinda nicer than having to have multiple data attributes.
Example found here:
http://www.sluniverse.com/ffn/index.php/2011/02/using-html5s-data-attributes-with-jquery/
Not sure why I did not think of that before.
Question is, is it preferable to use json in a
data-
attribute over multipledata-
attributes?Some more info here:
http://webdesign.tutsplus.com/tutorials/htmlcss-tutorials/all-you-need-to-know-about-the-html5-data-attribute/