├── index.html
└── js
├── project.js
└── myPlugin.js
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | myPlugin
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/js/project.js:
--------------------------------------------------------------------------------
1 | /*** Document is ready */
2 |
3 | var elements;
4 |
5 | document.addEventListener('DOMContentLoaded',function()
6 | {
7 | elements = new myPlugin();
8 |
9 | window.addEventListener('scroll',function()
10 | {
11 | });
12 |
13 | window.addEventListener('resize',function()
14 | {
15 | elements.update();
16 | });
17 | });
18 |
19 |
20 | /*** Document is loaded */
21 |
22 | window.addEventListener('load',function(event)
23 | {
24 | });
--------------------------------------------------------------------------------
/js/myPlugin.js:
--------------------------------------------------------------------------------
1 | (function()
2 | {
3 | /*** Register plugin in window object */
4 |
5 | this.myPlugin = function()
6 | {
7 | let defaults = {};
8 |
9 | this.elements = [];
10 | this.settings = (arguments[0] && typeof arguments[0] === 'object') ? extendDefaults(defaults,arguments[0]) : defaults;
11 |
12 | this.init();
13 | }
14 |
15 |
16 | /*** Public Methods */
17 |
18 | myPlugin.prototype.init = function()
19 | {
20 | console.log('Init plugin.');
21 |
22 | build.call(this);
23 | }
24 |
25 |
26 | myPlugin.prototype.update = function(element)
27 | {
28 | console.log('Update plugin.');
29 | }
30 |
31 |
32 | /*** Private Methods */
33 |
34 | function build(element)
35 | {
36 | console.log('Build plugin.');
37 | }
38 |
39 |
40 | function extendDefaults(defaults,properties)
41 | {
42 | Object.keys(properties).forEach(property => {
43 | if(properties.hasOwnProperty(property))
44 | {
45 | defaults[property] = properties[property];
46 | }
47 | });
48 | return defaults;
49 | }
50 | }());
--------------------------------------------------------------------------------