Hi,
In order to make my code extendable, I would like to be able to invoke widgets based on parameters.
Example:
I would like to be able to have a generic invocation like this:
$('#my_div').my_widgets(type, options);
where
my_widgets would invoke the correct widget, depending on the "type" parameter.
My current implementation is as follows:
var _my_widgets = []; /* 'named' array that lists my widgets */
(function($){
$.widget("mobile.widget_1", $.mobile.widget, {
...
});
_my_widgets['type_1'] = $.mobile.widget_1;
/* -- widget dispatcher -- */
$.fn.my_widgets = function(type, option){
return _my_widgets[type].apply($(this), option);
};
})(jQuery);
Then the call:
$('#my_div').my_widgets('type_1', { } );
Everything works fine EXCEPT that inside the widget which is invoked, "this.element" does not refer to $('#my_div') but to an empty div.
What do I do wrong?