Skip to content

Instantly share code, notes, and snippets.

@DavidCramer
Created September 12, 2013 09:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DavidCramer/6534826 to your computer and use it in GitHub Desktop.
Save DavidCramer/6534826 to your computer and use it in GitHub Desktop.
Configure and use jQuery plugins with html attributes only
/* Attrify
Allows you to activate and configure jQuery plugins* via html attributes & without writing javascript.
* most, not all.
EXAMPLE:
<a class="attrify"
data-plugn="nivoLightbox"
data-effect="fade"
data-theme="default"
data-keyboardNav="true"
href="https://www.youtube.com/watch?v=L9szn1QQfas"
>View Youtube Video</a>
*/
(function($){
$.fn.attrify = function(){
if(typeof $(this)[this.data('plugin')] === 'function'){
$(this)[this.data('plugin')](this.data());
}
};
$('.attrify').attrify();
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment