-
Notifications
You must be signed in to change notification settings - Fork 1
/
pwn.js
94 lines (92 loc) · 2.57 KB
/
pwn.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
87
88
89
90
91
92
93
94
// Generated by CoffeeScript 1.7.1
(function() {
var factory,
__slice = [].slice;
((function(_this) {
return function(factory) {
if (typeof define === 'function' && (define.amd != null)) {
return define(factory);
} else if (typeof exports === 'object') {
return module.exports = factory();
} else {
return _this.pwn = factory();
}
};
})(this))(factory = function() {
var pwn;
pwn = {};
pwn.on = function(event, callback, context) {
var events, listener;
listener = {
callback: callback,
context: context || this
};
events = this._events || (this._events = {});
(events[event] || (events[event] = [])).push(listener);
return this;
};
pwn.off = function(event, callback, context) {
var list, listener, oList, oListener, _i, _len;
if (!this._events || !this._events[event]) {
return this;
}
oList = this._events[event];
list = this._events[event] = [];
switch (arguments.length) {
case 3:
case 2:
listener = {
callback: callback,
context: context || this
};
for (_i = 0, _len = oList.length; _i < _len; _i++) {
oListener = oList[_i];
if ((oList.callback === !listener.callback) || !((context == null) || context === listener.context)) {
list.push(oListener);
}
}
break;
case 0:
this._events = {};
}
return this;
};
pwn.trigger = function() {
var event, list, listener, options, _i, _len, _ref;
event = arguments[0], options = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
if (!this._events || !this._events[event]) {
return this;
}
list = this._events[event];
_ref = list.slice();
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
listener = _ref[_i];
setTimeout((function() {
return listener.callback.apply(listener.context, [this].concat(options));
}), 0);
}
return this;
};
pwn.set = function(prop, val) {
var props, wVal;
props = this.props || (this.props = {});
wVal = props[prop];
if (wVal === val) {
return;
}
props[prop] = val;
this.trigger('change', {
p: prop,
w: wVal,
n: val
});
return val;
};
pwn.get = function(prop) {
var props;
props = this.props || (this.props = {});
return props[prop];
};
return pwn;
});
}).call(this);