Skip to content

Instantly share code, notes, and snippets.

@visoft
Created October 10, 2014 12:35
Show Gist options
  • Save visoft/cd9729a22c4fef5b73e1 to your computer and use it in GitHub Desktop.
Save visoft/cd9729a22c4fef5b73e1 to your computer and use it in GitHub Desktop.
Simple jQuery Plugin with CoffeeScript
$ = jQuery
$.myPlugin = (element) ->
plugin = this
plugin.init = ->
# Do stuff here
# initialize the plugin
plugin.init()
# return the plugin, otherwise we can't chain commands
plugin
$.fn.myPlugin = ->
@each ->
if undefined is $(this).data('myPlugin')
plugin = new $.myPlugin(this)
$(this).data 'myPlugin', plugin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment