Skip to content

Instantly share code, notes, and snippets.

@bsboris
Created October 22, 2013 20:59
Show Gist options
  • Select an option

  • Save bsboris/7108046 to your computer and use it in GitHub Desktop.

Select an option

Save bsboris/7108046 to your computer and use it in GitHub Desktop.
jQuery plugin boilerplate for CoffeeScript.
(($, window) ->
class PluginName
constructor: (el, options) ->
@options = $.extend({}, $.fn.pluginName.defaults, options)
@$el = $(el)
_fireCallback: (callback, thisValue, args...) -> callback.apply(thisValue, args) if typeof callback is 'function'
$.fn.pluginName = (option, args...) ->
@each ->
$this = $(this)
data = $this.data('pluginName')
$this.data 'pluginName', (data = new PluginName(this, option)) if !data
data[option].apply(data, args) if typeof option is 'string' and option[0] isnt '_' and typeof data[option] is 'function'
$.fn.pluginName.defaults =
optionA: true
) window.jQuery, window
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment