したがって、ユーザーが新しいコンテンツをdiv(プレースホルダー)に広告する場合に使用される更新メソッドを備えたプラグインがあります。最初は問題なく、プラグインはプラグインのユーザー定義オプションを使用しますが、ユーザーが実行するとupdate メソッドを使用すると、定義済みのオプションではなくデフォルトのオプションが使用されます。
プラグインラッパー...
;(function($, window, document, undefined){
//"use strict"; // jshint ;_;
var pluginName = 'myPlugin';
function Plugin(element, options){
this.elm = $(element);
this.options = $.extend({}, $.fn[pluginName].defaults, options);
this.init();
};
Plugin.prototype = {
init: function(){
// we run this at start...
},
update: function(){
// code that we need when we need to update...
},
};
$.fn[pluginName] = function(option) {
var options = typeof option == "object" && option;
return this.each(function() {
var $this = $(this);
var data = new Plugin($this, options);
if(!$.data($this, pluginName)){
$.data($this, pluginName, data);
}
if(typeof option == 'string'){
data[option]();
}
});
};
$.fn[pluginName].defaults = {
name: 'Hank',
...
...
};
})(jQuery, window, document);
// インライン js
$('#container').myPlugin({name: 'NOT Hank...'});
$('#updatelink').click(function(e){
$('#container').myPlugin('update');
}):