forked from elclanrs/advanced-jquery-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.html
59 lines (46 loc) · 1.53 KB
/
test.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="advanced-jquery-boilerplate.min.js"></script>
<script>
(function($, win, doc, undefined) {
var pluginName, defaults, methods, global;
// The name of your plugin
pluginName = 'myplugin';
// Default options
defaults = {
};
// Public methods
methods = {
// Gets called when creating a new instance
// this.el is the element on which the plugin was called
// this.opts contains the options passed to the plugin
_init: function() {
this.$el = $(this.el);
console.log('Plugin initialized!');
},
foo: function(name) {
return 'Hello '+ name +'!';
},
_callOnce: function () {
console.log('Call Once method was called only once, no matter how many times you init the plugin.');
}
};
// Global properties and methods get attached to `$`
// as opposed to `$.fn` so they can be extended from the outside
global = {
};
// Add the plugin to the jQuery namespace and set-up the boilerplate base
$.newPlugin(pluginName, defaults, methods, global);
}(jQuery, window, document));
$('body').myplugin(); //=> init plugin
$('html').myplugin(); //=> init again for test
console.log($('body').myplugin('get:foo', 'John')); //=> return value
</script>
</body>
</html>