forked from stevenbenisek/jquery-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.plugin.js
86 lines (77 loc) · 2.01 KB
/
jquery.plugin.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/**
* @library <%= plugin name %>
* @description <%= description %>
* @author <%= author_name %> <<%= author_email %>>
* @license <%= license %>
*/
;(function(window, document, $, undefined) {
'use strict';
/**
* Plugin NAMESPACE and SELECTOR
* @type {String}
* @api private
*/
var NAMESPACE = '<%= plugin name %>',
SELECTOR = '[data-' + NAMESPACE + ']';
/**
* Plugin constructor
* @param {Node} element
* @param {Object} [options]
* @api public
*/
function Plugin (element, options) {
this.options = $.extend(true, $.fn[NAMESPACE].defaults, options);
this.$element = $(element);
}
/**
* Plugin prototype
* @type {Object}
* @api public
*/
Plugin.prototype = {
constructor: Plugin,
version: '<%= version %>',
/**
* Init method
* @api public
*/
init: function () {
// @todo add method logic
}
// @todo add methods
};
/**
* jQuery plugin definition
* @param {String} [method]
* @param {Object} [options]
* @return {Object}
* @api public
*/
$.fn[NAMESPACE] = function (method, options) {
return this.each(function () {
var $this = $(this),
data = $this.data('fn.' + NAMESPACE);
options = (typeof method === 'object') ? method : options;
if (!data) {
$this.data('fn.' + NAMESPACE, (data = new Plugin(this, options)));
}
data[(typeof method === 'string') ? method : 'init']();
});
};
/**
* jQuery plugin defaults
* @type {Object}
* @api public
*/
$.fn[NAMESPACE].defaults = {
// @todo add defaults
};
/**
* jQuery plugin data api
* @api public
*/
$(document).on('click.' + NAMESPACE, SELECTOR, function (event) {
$(this)[NAMESPACE]();
event.preventDefault();
});
}(this, this.document, this.jQuery));