Created
September 11, 2012 17:42
-
-
Save jackboberg/3700168 to your computer and use it in GitHub Desktop.
coffeescript boilerplate jQuery plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ = 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