public
Last active

jQuery UI unobtrusive

  • Download Gist
jquery-ui.unobtrusive.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
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);
});
});

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.