If you have a variable number of jQuery plugins of the format:
(function($){
$.fn.toolSet_themeOne = function () {
// params
};
})(jQuery);
(function($){
$.fn.toolSet_themeTwo = function () {
// params
};
})(jQuery);
Where each plugin's definition is not guaranteed to be the same and is likely to contain some degree of variation in name after the underscore, h开发者_高级运维ow could these be applied in a situation such as this:
var themeApply = function (jQueryCollection, objSettings, pluginName) {
// this does not work and reports pluginName is not a function
jQueryCollection.pluginName(objSettings);
// $.fn[pluginName] is reported as a function
};
I thought to use another question as a guide, but don't see how to scope it correctly. Any pointers would be greatly appreciated.
Thank you :)
EDIT: For those wondering what function is inside, this is an example (learned from another SO answer for which I cannot find an immediate refrence:
(function($){
$.fn.toolSet_themeOne = function () {
var methods = [
update: update
];
var init = function (options) {
// normal jquery initialisation here
};
var update = function (data) {
// do something with data
// if not initialising, but calling after initialisation
};
// what do we do on initialisation?
if(arguments.length > 0) {
if('string' === typeof(arguments[0]) && 'undefined' !== typeof(methods[arguments[0]])) {
var args = Array.prototype.slice.call(arguments);
args = args.shift();
methods[arguments[0]].apply(this,args);
} else if('object' === typeof(arguments[0])) {
init.apply(this, arguments);
}
} else {
init.apply(this, arguments);
}
return this;
};
})(jQuery);
Does jQueryCollection[pluginName](objSettings)
not work?
精彩评论