У меня есть плагин jQuery, и я хочу иметь возможность изменять параметры на лету, как в этом примере: $('.element').pwstabs('options','effect',scale)
или что-то похожее на него. Я пытался добавить update: function
, пытался добавить Plugin.prototype.update
, но до сих пор не могу понять, как это сделать :)
Вот структура плагина:
;(function ($, window, document, undefined) {
var pluginName = "pwstabs",
defaults = {
effect: 'scaleout',
defaultTab: 1,
containerWidth: '100%',
tabsPosition: 'horizontal',
horizontalPosition: 'top',
verticalPosition: 'left',
responsive: false,
theme: '',
rtl: false,
controlls: false,
next: '',
prev: '',
first: '',
last: '',
auto: false,
play: '',
pause: ''
};
function Plugin(element, options) {
this.element = $(element);
this.$elem = $(this.element);
this.settings = $.extend({}, defaults, options);
this._defaults = defaults;
this._name = pluginName;
this.init();
}
Plugin.prototype = {
init: function(){
// Here's the code for the plugin
}
};
$.fn[pluginName] = function ( options ) {
return this.each(function () {
new Plugin( this, options );
});
};
})(jQuery, window, document);
Итак, теперь я использую плагин, например:
$('.element').pwstabs({
effect: 'scalein',
defaultTab: 2
});
И когда я нажимаю кнопку, я хочу изменить эффект, скажем, на scaleout
. С кодом вроде:
$('.button').click(function(){
$('.element').pwstabs('options','effect','scalein');
});
Итак, как мне реализовать это в плагине?
init
, если плагин уже инициирован , принять изменения параметров без повторного вызоваinit
? Добавить.data("init", true)
к элементу, если плагин уже запущен в элементе, принять изменения параметров без повторного вызоваinit
? - person guest271314   schedule 08.02.2015