Skip to content

Instantly share code, notes, and snippets.

@gigi81
Last active September 29, 2015 12:38
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 gigi81/1601992 to your computer and use it in GitHub Desktop.
Save gigi81/1601992 to your computer and use it in GitHub Desktop.
jQuery UI unobtrusive
jQuery(document).ready(function () {
jQuery('[data-widget]').each(function () {
var widget = jQuery(this).attr('data-widget');
var optionsAttribute = jQuery(this).attr('data-widget-options');
var options = (optionsAttribute != null) ? eval('({' + optionsAttribute + '})') : null;
// Sanity check: can't directly check that it's truly a _widget_, but
// can at least verify that it's a defined function on jQuery:
if (typeof jQuery.fn[widget] !== 'function') {
throw new Error("Could not find '" + widget + "' jQuery UI widget");
}
jQuery(this)[widget](options);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment