Created
October 10, 2014 12:35
-
-
Save visoft/cd9729a22c4fef5b73e1 to your computer and use it in GitHub Desktop.
Simple jQuery Plugin with CoffeeScript
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 | |
$.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