Skip to content

Instantly share code, notes, and snippets.

@jackboberg
Created September 11, 2012 17:42
Show Gist options
  • Save jackboberg/3700168 to your computer and use it in GitHub Desktop.
Save jackboberg/3700168 to your computer and use it in GitHub Desktop.
coffeescript boilerplate jQuery plugin
$ = jQuery
pluginName = 'test'
methods =
init: (opts)->
defaults =
foo: 'bar'
bar: 'foo'
options = $.extend defaults, opts
return @.each ->
data = $(@).data pluginName
if not data
$(@).data pluginName,
opts: options
other: 'foobar'
methods.put.apply @
put: ->
console.log @
$.fn[pluginName] = ( method ) ->
if methods[method]
return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ))
else if typeof method is 'object' or not method
return methods.init.apply this, arguments
else
$.error 'Method ' + method + ' does not exist on jQuery.' + pluginName
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment