[jQuery] plugin creation question
hi!
while working on a plugin and following Mike Alsup's plugin pattern (
http://www.learningjquery.com/2007/10/a-plugin-development-pattern),
i'm stuck trying to reference an external function inside the plugin:
i have an externally accessible configuration object to store options
's default values.
$.fn.jqUploader.defaults = {
onIni: initializeUploader(),
// more options...
};
as you can see, i associate a named function to the onIni property of
the defaults object. Here is that function, completely external to the
plugin code.
function initializeUploader(){
$(this).parents('form').find('input[type="submit"]').hide();
$(this).css({background: 'red'});
}
now, in my main loop through each selected element, i want the user to
be able to overwrite on a case by case these defaults, via the meta
data plugin or a passed object
var opts = $.extend({}, $.fn.jqUploader.defaults, options);
return this.each(function(index){
$this = $(this);
// make jqUploader compatible with metadata plugin
$this.options = $.meta ? $.extend({}, opts, $this.data()) : opts;
/* PROBLEM IS HERE */
$this.options.onIni;
});
Problem is: the onIni function is called, but the command inside the
function is not performed "elem has no properties" which means that
$(this) refers to nothing i guess.
I think the reason is because it does not know anymore what is
referenced by $(this).
So, can someone kindly explain me what i'm doing wrong?
Thanks a lot,
Alexandre
--
Alexandre Plennevaux