Skip to content

Instantly share code, notes, and snippets.

@MauricioKruijer
Created May 28, 2013 12:06
Show Gist options
  • Save MauricioKruijer/5662284 to your computer and use it in GitHub Desktop.
Save MauricioKruijer/5662284 to your computer and use it in GitHub Desktop.
;(function($, window, document, undefined){
var defaults = {
label: 'yeahhhhh'
};
var methods = {
"init": function (options) {
options = $.extend({}, defaults, options);
// Do whatever
},
"myFunc": function (options) {
// Do whatever
}
};
$.fn.pluggg = function(options) {
var args = arguments;
var argss = Array.prototype.slice.call(args, 1);
return this.each(function() {
var $this = $(this); // Might make sense to ignore this and just pass `this` to the following things
if (methods[method]) {
methods[method].apply($this, argss);
}
else if (typeof method === "object" || !method) {
methods.init.apply($this, args);
}
else {
$.error("Method " + method + " does not exist on jQuery.pollServer");
}
});
};
})(jQuery, window, document);
/*
http://stackoverflow.com/a/13131363
So to call init, you can either use $("#a").pluggg({stuff: "stuff"}); or $("#a").pluggg("init", {stuff: "stuff"});. To call myFunc, you'd use the second example for init, but use "myFunc". Does that all make sense?
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment