Last active
August 29, 2015 13:56
-
-
Save mkempe/8933385 to your computer and use it in GitHub Desktop.
Coffeescript template for jQuery Plugin + Class.
This file contains hidden or 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
class @Awesome | |
defaults: | |
isItAwesome: true | |
constructor: (element, options) -> | |
@element = $ element | |
@options = $.extend { }, @defaults, options | |
setup.call @ | |
return | |
setup = -> | |
console.log "It's awesome..." if @options.isItAwesome? | |
return |
This file contains hidden or 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
(($, window, document) -> | |
$.fn.extend awesome: (options, args...) -> | |
@each -> | |
element = $ @ | |
data = element.data 'awesome' | |
if data | |
data[options].apply data, args if data[options] | |
else | |
element.data 'awesome', (data = new Awesome @, options) | |
) jQuery, window, document |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Heavily inspired by https://gist.github.com/rjz/3610858.