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?
lets say you have list, list2, and superList... let's call "publicMethod" on for each of them:
$.fn.callWidgetMethod = function(method) {
var $this = this,
args = Array.prototype.slice.call(arguments, 1);
// loop though the data and check each piece of data to
// see if it has the method
$.each(this.data(), function(key, val) {
if ($.isFunction(val[method])) {
$this[key].apply($this, args);
// break out of the loop
return false;
}
});
}
$("#some-element").list();
$("#another-element").list2();
$("#hydrogen").superList();
$("#some-element").callWidgetMethod("publicMethod");
$("#another-element").callWidgetMethod("publicMethod");
$("#hydrogen").callWidgetMethod("publicMethod");