Skip to content

Instantly share code, notes, and snippets.

@charliek
Created July 17, 2009 22:42
Show Gist options
  • Save charliek/149322 to your computer and use it in GitHub Desktop.
Save charliek/149322 to your computer and use it in GitHub Desktop.
JQuery Template v2
(function($) {
$.fn.myplugin = function(options){
// support mutltiple elements
if (this.length > 1){
this.each(function() { $(this).myplugin(options) });
return this;
}
// private variables
var opts = $.extend({}, $.fn.myplugin.defaults, options);
// private functions
var log = function(msg){
if (window.console && window.console.log)
window.console.log(msg);
};
// public functions
this.init = function(){
return this;
};
this.doSomething = function(num){
};
return this.init();
};
// class functions
$.fn.myplugin.do_something = function(txt) {
return '<strong>' + txt + '</strong>';
};
// plugin defaults set publicly so that they can be changed globally.
$.fn.myplugin.defaults = {
foreground: 'red',
background: 'yellow'
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment