Created
July 13, 2012 15:47
-
-
Save rogeruiz/3105605 to your computer and use it in GitHub Desktop.
js-boilerplates
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
| do ($ = jQuery) -> | |
| # call your plugins here, man | |
| 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
| // Generated by CoffeeScript 1.3.3 | |
| (function($) {})(jQuery); |
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
| do ($ = jQuery) -> | |
| # Create Namespace if the it isn't already bound to jQuery | |
| $.Namespace = {} if !$.Namespace | |
| # Plugin function | |
| $.Namespace.pluginName = (el, options) -> | |
| # create a reference for the plugin's scope | |
| base = @ | |
| # store references of jQuery element and DOM element | |
| base.$el = $(el) | |
| base.el = el | |
| # private methods | |
| base.init = -> | |
| # copy and override the plugin's defaultOptions with the passed in options | |
| base.opt = $.extend({}, $.Namespace.pluginName.defaultOptions, options) | |
| # pass references into callbacks | |
| base.opt.$el = base.$el | |
| base.opt.el = base.el | |
| # initialization code here, brother | |
| base.opt.onInit() if $.isFunction(base.opt.onInit) | |
| base.doSomethingElse = -> | |
| base.doAnotherThing = -> | |
| # run init | |
| do base.init | |
| # public methods | |
| _public = { | |
| doSomethingOutside: -> | |
| base.doSomethingElse() | |
| base.doAnotherThing() | |
| return | |
| } | |
| $.Namespace.pluginName.defaultOptions = { | |
| onInit: undefined | |
| } | |
| $.fn.Namespace_pluginName = (options) -> | |
| @each -> | |
| do new $.Namespace.pluginName @, options | |
| return | |
| 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
| // Generated by CoffeeScript 1.3.3 | |
| (function($) { | |
| if (!$.Namespace) { | |
| $.Namespace = {}; | |
| } | |
| $.Namespace.pluginName = function(el, options) { | |
| var base, _public; | |
| base = this; | |
| base.$el = $(el); | |
| base.el = el; | |
| base.init = function() { | |
| base.opt = $.extend({}, $.Namespace.pluginName.defaultOptions, options); | |
| base.opt.$el = base.$el; | |
| base.opt.el = base.el; | |
| if ($.isFunction(base.opt.onInit)) { | |
| return base.opt.onInit(); | |
| } | |
| }; | |
| base.doSomethingElse = function() {}; | |
| base.doAnotherThing = function() {}; | |
| base.init(); | |
| return _public = { | |
| doSomethingOutside: function() { | |
| base.doSomethingElse(); | |
| base.doAnotherThing(); | |
| } | |
| }; | |
| }; | |
| $.Namespace.pluginName.defaultOptions = { | |
| onInit: void 0 | |
| }; | |
| $.fn.Namespace_pluginName = function(options) { | |
| return this.each(function() { | |
| new $.Namespace.pluginName(this, options)(); | |
| }); | |
| }; | |
| })(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment