Skip to content

Instantly share code, notes, and snippets.

@charliek
Created June 24, 2009 06:11
Show Gist options
  • Save charliek/135044 to your computer and use it in GitHub Desktop.
Save charliek/135044 to your computer and use it in GitHub Desktop.
JQuery Template v1
(function($) {
$.fn.myplugin = function(options){
// build main options before element iteration
var opts = $.extend({}, $.fn.myplugin.defaults, options);
// return the jQuery object for chaining
return this.each(function() {
var $this = $(this);
// build element specific options using the meta tag if availible
var o = $.meta ? $.extend({}, opts, $this.data()) : opts;
// do plugin specific code ...
debug("this is awsome");
});
};
// private functions
function debug(msg){
if (window.console && window.console.log)
window.console.log(msg);
}
// public 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