Last active
December 11, 2015 05:29
-
-
Save markupboy/4552507 to your computer and use it in GitHub Desktop.
coffeescript version of thie highly configurable plugin pattern - http://markdalgleish.com/2011/05/creating-highly-configurable-jquery-plugins/
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 Plugin | |
constructor: (elem, options) -> | |
@elem = elem | |
@$elem = $(elem) | |
@options = options | |
@metadata = @$elem.data('plugin-options') | |
@ | |
defaults: | |
message: 'Hello world!' | |
init: -> | |
@config = $.extend {}, @defaults, @options, @metadata | |
@displayMessage() | |
@ | |
displayMessage: -> | |
alert @config.message | |
Plugin.defaults = Plugin.prototype.defaults; | |
$.fn.plugin = (options) -> | |
@each -> | |
(new Plugin @, options).init() | |
window.Plugin = Plugin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment