Skip to content

Instantly share code, notes, and snippets.

@rogeruiz
Created July 13, 2012 15:47
Show Gist options
  • Select an option

  • Save rogeruiz/3105605 to your computer and use it in GitHub Desktop.

Select an option

Save rogeruiz/3105605 to your computer and use it in GitHub Desktop.
js-boilerplates
do ($ = jQuery) ->
# call your plugins here, man
return
// Generated by CoffeeScript 1.3.3
(function($) {})(jQuery);
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
// 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