-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcore.js
More file actions
55 lines (39 loc) · 1.31 KB
/
core.js
File metadata and controls
55 lines (39 loc) · 1.31 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
// From Ben Cherry: http://www.adequatelygood.com/JavaScript-Module-Pattern-In-Depth.html
// Core Module
var MyModule = (function (module, $) {
// Private state across files
var _private = module._private = module._private || {},
_seal = module._seal || function () {
delete module._private;
delete module._seal;
delete module._unseal;
},
_unseal = module._unseal || function () {
module._private = _private;
module._seal = _seal;
module._unseal = _unseal;
};
module.init = function () {
// For block context, 'this' is 'module'
console.log(_private);
_private.els = {};
console.log('initializing');
_private.els.linkEl = $('#link');
_private.els.boxEl = $('#box');
_private.els.linkEl.on('click', {context: this}, this.linkClicked);
this.subModule.init();
};
module.linkClicked = function (event) {
// In an event callback, 'this' is the DOM element
// We get the proper context by passing it to this method in the event.data attribute
var self = event.data.context,
xPos = parseInt(Math.random() * 100) + 10;
// Animate the box
self.doAnimation(self, xPos);
};
// Loose augmentation
module.someMethod = function (arg1) {
console.log(art1);
};
return module;
}(MyModule || {}, jQuery));