forked from allouis/minivents
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminivents.js
More file actions
26 lines (26 loc) · 766 Bytes
/
Copy pathminivents.js
File metadata and controls
26 lines (26 loc) · 766 Bytes
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
function Events(target){
var events = {}, empty = [];
target = target || this
/**
* On: listen to events
*/
target.on = function(type, func, ctx){
(events[type] = events[type] || []).push([func, ctx])
}
/**
* Off: stop listening to event / specific callback
*/
target.off = function(type, func){
type || (events = {})
var list = events[type] || empty,
i = list.length = func ? list.length : 0;
while(i--) func == list[i][0] && list.splice(i,1)
}
/**
* Emit: send event, callbacks will be triggered
*/
target.emit = function(type){
var e = events[type] || empty, list = e.length > 0 ? e.slice(0, e.length) : e, i=0, j;
while(j=list[i++]) j[0].apply(j[1], empty.slice.call(arguments, 1))
};
};