Skip to content

Instantly share code, notes, and snippets.

@scottgonzalez
Created July 20, 2011 19:58
Show Gist options
  • Select an option

  • Save scottgonzalez/1095783 to your computer and use it in GitHub Desktop.

Select an option

Save scottgonzalez/1095783 to your computer and use it in GitHub Desktop.
$.fn.widget = function( widget, options ) {
var isMethodCall = typeof widget === "string",
widgetName = widget.prototype.name,
args = [].slice.call( arguments, 2 );
return this.each( isMethodCall ?
function() {
var instance = $( this ).data( name );
instance[ options ].apply( instance, args );
} :
function() {
widget( options, this );
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment