Skip to content

Instantly share code, notes, and snippets.

@bunnymatic
Last active October 9, 2015 06:48
Show Gist options
  • Select an option

  • Save bunnymatic/3456358 to your computer and use it in GitHub Desktop.

Select an option

Save bunnymatic/3456358 to your computer and use it in GitHub Desktop.
jquery plugin boilerplate in coffeescript Javascript version is here https://gist.github.com/bunnymatic/1048060
$.myPluginDefaults =
param1: 'default param1'
param2: []
$.fn.myPlugin = (method) ->
inArgs = arguments
methods =
init: (options) ->
localSettings = $.extend({},$.myPluginDefaults, options);
this.each () ->
# Method calling logic
if ( methods[method] )
return methods[ method ].apply( this, Array.prototype.slice.call( inArgs, 1 ));
else if ( typeof method == 'object' || ! method )
return methods.init.apply( this, inArgs );
else
$.error( 'Method ' + method + ' does not exist on jQuery.myPlugin' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment