-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjquery.plugin.js
More file actions
77 lines (66 loc) · 1.75 KB
/
Copy pathjquery.plugin.js
File metadata and controls
77 lines (66 loc) · 1.75 KB
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
/**
* jQuery Plugin Starting Point - A base jquery plugin template
*
* Use this template as a base to create any jQuery plugin.
* has UMD/AMD support
* also contains a super cool way to register plugins that could be forked out
*
* Licensed under the MIT:
* http://www.opensource.org/licenses/mit-license.php
*
* @author Will Ayers ( @cointilt )
* @version 2.0
* @link https://github.com/cointilt/jQuery-Plugin-Starting-Point
*/
;(function (factory) {
if (typeof define == 'function' && define.amd) {
// AMD define
define(['jquery'], factory);
} else {
// default no AMD/UMD way
factory(jQuery);
}
}(function ($) {
// Plugin name and Default app variable
var pluginName = 'myPlugin',
App = {};
// Plugin initialize function
App.init = function (options, el) {
// default options
var defaults = {};
// combine default options with passed in options
this.options = $.extend({}, defaults, options);
// setup elements
this.el = el;
this.$el = $(el);
// return this for chaining
return this;
};
// get option
App.option = function (name) {
return this.options[name];
};
// create missing function on crappy browsers
if (typeof Object.create !== 'function') {
Object.create = function (o) {
function F() {}
F.prototype = o;
return new F();
};
}
// custom way of registering plugins
// this could be taken out and added in it's own file
$.registerPlugin = function (name, object) {
$.fn[name] = function (options) {
return this.each(function () {
if (!$.data(this, name)) {
$.data(this, name, Object.create(object).init(options, this));
}
});
};
};
// register App as a jQuery Plugin
$.registerPlugin(pluginName, App);
// return the app the be able to call specific if needed
return App;
}));