Inline Data Types
jQuery introduced html5 data attributes parsing in version 1.4.4. All whitelabel plugins use this feature
The element could look like this:
<div class="className"></div>
Normally you call a plugin this way:
$('.className').wl_Pluginname()
To pass some options you can add an object:
$('.className').wl_Pluginname({ foo:true, bar:123, fooBar:'abc' })
pass options directly within the markup:
<div class="className" data-foo="true" data-bar="123" data-foo-bar="abc"></div>
This works with all whitelabel Plugins
What's the advantage of this technique?
if you have more elements you can initialize once with different options:
<div class="className" data-foo="true" data-bar="123" data-foo-bar="abc"></div> <div class="className" data-foo="false" data-bar="456" data-foo-bar="def"></div> <div class="className" data-foo="null" data-bar="789" data-foo-bar="ghi"></div>
$('.className').wl_Pluginname()
Precedence
Data attributes overwrite object attributes:<div class="className"></div> <div class="className" data-foo="true"></div> $('.className').wl_Pluginname({ foo:false })
$('.className').eq(0).data('wl_Pluginname').foo === false $('.className').eq(1).data('wl_Pluginname').foo === true
Object attributes overwrites default values