mhulse / jquery-kerplop

Move stuff from one place to another.
http://mhulse.github.io/jquery-kerplop/demo/
Apache License 2.0
2 stars 0 forks source link

Convert data attribute to #14

Open mhulse opened 11 years ago

mhulse commented 11 years ago
data-kerplop='{"from" : "xxx", "to" : "xxx"}'

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 multiple data- attributes?

Some more info here:

http://webdesign.tutsplus.com/tutorials/htmlcss-tutorials/all-you-need-to-know-about-the-html5-data-attribute/

mhulse commented 10 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.