Currently, the only supported call pattern in this plugin is to send an object literal containing settings to overwrite the default values. For instance:.
$('.element').pwstabs({ effect: 'scalein', defaultTab: 2 });
This call pattern is defined as follows:
$.fn[pluginName] = function ( options ) { return this.each(function () { new Plugin( this, options ); }); };
As you can see, the parameter dictionary is sent as the only parameter of the constructor function Plugin () to create the plugin and initialize it.
In order to support the call pattern that you need, you will have to modify this method to support call patterns and (initialization using the object literal, but also call any method with a lot of parameters, for example, setting your method parameters).
Here is an improved function that will handle both call patterns. In addition, it will also save the plugin instance on the element, so you can access existing settings, etc. On subsequent calls (for example, changing settings) on the same element.
$.fn[pluginName] = function (options) { // get the arguments var args = $.makeArray(arguments), after = args.slice(1); return this.each(function () { // check if there is an existing instance related to element var instance = $.data(this, pluginName); if (instance) { if (instance[options]) { instance[options].apply(instance, after); } else { $.error('Method ' + options + ' does not exist on Plugin'); } } else { // create the plugin var plugin = new Plugin(this, options); // Store the plugin instance on the element $.data(this, pluginName, plugin); return plugin; } }); }
This will allow you to call the plugin on request:
$('.element').pwstabs('options','effect','slidedown');
However, this means that you have the "options" method in the Plugin prototype, so be sure to add it:
Plugin.prototype = { options: function (option, val) { this.settings[option] = val; },
As you can see, parameter parameters simply set a new option in an existing instance. Very simple and efficient. The new parameter will be selected by the tag handler and voila!
Here is a jsFiddle example with sample code if you are having problems implementing what I have described so far:
http://jsfiddle.net/7whs3u1n/6/
Update . I significantly improved my answer to get rid of unnecessary things, included more detailed information and a full implementation that works (check the script above);) I hope this answers your question!
Adding state to your plugin was not easy, but when you have free time, check out an alternative mechanism for writing plugins with state jQuery with state called jQuery widget factory :
http://learn.jquery.com/plugins/stateful-plugins-with-widget-factory/
In the future, you might consider rewriting your plugin to use the factory widget. This will undoubtedly make your code simpler;)