forked from videojs/video.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
event-emitter.js
43 lines (35 loc) · 1.16 KB
/
event-emitter.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
vjs.EventEmitter = function() {
};
vjs.EventEmitter.prototype.allowedEvents_ = {
};
vjs.EventEmitter.prototype.on = function(type, fn) {
// Remove the addEventListener alias before calling vjs.on
// so we don't get into an infinite type loop
var ael = this.addEventListener;
this.addEventListener = Function.prototype;
vjs.on(this, type, fn);
this.addEventListener = ael;
};
vjs.EventEmitter.prototype.addEventListener = vjs.EventEmitter.prototype.on;
vjs.EventEmitter.prototype.off = function(type, fn) {
vjs.off(this, type, fn);
};
vjs.EventEmitter.prototype.removeEventListener = vjs.EventEmitter.prototype.off;
vjs.EventEmitter.prototype.one = function(type, fn) {
vjs.one(this, type, fn);
};
vjs.EventEmitter.prototype.trigger = function(event) {
var type = event.type || event;
if (typeof event === 'string') {
event = {
type: type
};
}
event = vjs.fixEvent(event);
if (this.allowedEvents_[type] && this['on' + type]) {
this['on' + type](event);
}
vjs.trigger(this, event);
};
// The standard DOM EventTarget.dispatchEvent() is aliased to trigger()
vjs.EventEmitter.prototype.dispatchEvent = vjs.EventEmitter.prototype.trigger;