-
Notifications
You must be signed in to change notification settings - Fork 1
/
jquery.plugin.boilerplate.js
47 lines (36 loc) · 1.05 KB
/
jquery.plugin.boilerplate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
(function($){
var pluginName = "NamespacePlugin";
var defaults = {
name: "Anonymous"
};
var Plugin = function(elem, options) {
this.elem = elem;
this.$elem = $(elem);
this.settings = $.extend({}, defaults, options);
this.init();
};
/*
* Methods
*/
Plugin.prototype._getSalutation = function() {
return "Hello " + this.settings.name;
};
Plugin.prototype.init = function() {
this.sayHello();
};
Plugin.prototype.sayHello = function() {
alert(this._getSalutation());
};
Plugin.prototype.highlight = function(colorName) {
colorName = colorName || "red";
this.$elem.css("border", "1px solid " + colorName);
};
$.fn[pluginName] = function(options) {
return this.each(function() {
var $elem = $(this);
if (!$elem.data(pluginName)) {
$elem.data(pluginName, new Plugin(this, options));
}
});
};
})(jQuery);