[jQuery] jQuery plugin scope
if(jQuery) (function($) {
// plugin definition
$.fn.hilight = function (options) {
debug(this);
// build main options before element iteration
var options = $.extend({}, $.fn.hilight.defaults, options);
// iterate and reformat each matched element
return this.each(function () {
var $this = $(this);
// build element specific options
var opts = $.meta ? $.extend({}, options, $this.data()) :
options;
// update element styles
$this.css({
backgroundColor: opts.background,
color: opts.foreground
});
var markup = $this.html();
// call our format function
markup = $.fn.hilight.format(markup);
$this.html(markup);
});
};
// private function for debugging
function debug ($obj) {
if (window.console && window.console.log) window.console.log
('hilight selection count: ' + $obj.size());
};
// define and expose our format function
$.fn.hilight.format = function (txt) {
return '<strong>' + txt + '</strong>';
};
// plugin defaults
$.fn.hilight.defaults = {
foreground: 'red',
background: 'yellow'
};
})(jQuery);
this is the code from the the article http://www.learningjquery.com/2007/10/a-plugin-development-pattern
now my questions are how do I invoke the format and debug functions
from within the several parts of the code and specially how can I
invoke the options var inside the format and debug functions?
been trying all I can think of and still I cant seem to figure it out.
Can anyone point me in the right direction?
Thanks