-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.plugin.template.simple.js
49 lines (36 loc) · 1.13 KB
/
jquery.plugin.template.simple.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
48
49
var MyPlugin = function (element, options) {
var myplugin = this;
this.$element = $(element);
this.options = $.extend({}, $.fn.myplugin.defaults, options);
this.$element.on('mouseover', function () {myplugin.publicMethod();});
};
MyPlugin.prototype = {
myAttribute: 'value',
_privateMethod: function () {},
publicMethod: function () {}
};
(function (factory) {
if (typeof define === 'function' && define.amd) {
define(['jquery'], factory);
} else {
factory(window.jQuery);
}
}(function ($) {
$.fn.myplugin = function (option) {
var args = [].splice.call(arguments, 1);
return this.each(function () {
var $this = $(this),
data = $this.data('myplugin'),
options = typeof option === 'object' && option;
if (!data) {
$this.data('myplugin', (data = new MyPlugin(this, options)));
} else if (typeof option === 'string') {
data[option].apply(data, args);
}
});
};
$.fn.myplugin.defaults = {
width: 500000,
text: 'Crazy man'
};
}));