Created
June 24, 2009 06:11
-
-
Save charliek/135044 to your computer and use it in GitHub Desktop.
JQuery Template v1
This file contains 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
(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