JQuery - Widget Public Methods
- by Steve
If I create a JQuery widget (code example below), and then define a "public" method, is there any other way to call the method other than using the following form?
$("#list").list("publicMethod");
I would like to create a series of widgets that all define the same methods (basically implementing the same interface), and be able to call the method without knowing anything about which widget I currently am invoking the method on. In the current form, I need to know that I am executing the method on the "list" widget.
Below is an example of creating a widget with the "public" method.
(function($) {
var items = [];
var itemFocusIdx = 0;
$.widget("ui.list", {
// Standard stuff
options : { ... },
_create : function() { ... },
destroy : function() { ... },
// My Public Methods
publicMethod : function() { ... }
...
});
}(jQuery));