所以我已经阅读了一些教程,但我仍然对如何将我的特定标记系统变成一个可用的插件感到困惑。
我用一堆函数声明了以下对象:
var Tags = {};
Tags.Class = function() {
...
};
然后我声明原型:
Tags.TaggingForm = new Tags.Class();
// Only takes text input fields for now!
Tags.TaggingForm.prototype = {
initialize: function(tag_field){
...
},
hideInputField: function() {
...
},
然后我有使用该对象的实际函数调用:
Tags.make_tagging_input = function (id) {
var
tagger = new Tags.TaggingForm(id);
...
}
我只是想知道如何把它变成一个插件:我现在这样称呼它:
window.g_gloab_var = Tags.make_tagging_input("#id");
这个骨架不断被建议,但我不知道如何应用它:
//You need an anonymous function to wrap around your function to avoid conflict
(函数($){
//Attach this new method to jQuery
$.fn.extend({
//This is where you write your plugin's name
tags_input: function() {
//Iterate over the current set of matched elements
return this.each(function() {
//code to be inserted here
});
}
});
//pass jQuery to the function,
//So that we will able to use any valid Javascript variable name
//to replace "$" SIGN. But, we'll stick to $ (I like dollar sign: ) )
})(jQuery);