-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathevent.js
More file actions
71 lines (60 loc) · 1.59 KB
/
event.js
File metadata and controls
71 lines (60 loc) · 1.59 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// 事件的
(function ($){
var event = {
ready : function (callback){
// if (this.dom[0] == document]) {
document.addEventListener('DOMContentLoaded', callback, false)
//
return $.init(this.dom)
},
on : function (events, fn){
this.map(function (dom){
return dom.addEventListener(events, fn, false)
})
return $.init(this.dom)
},
one : function (events, fn){
this.map(function (dom){
var handle = function (e){
fn(e)
return dom.removeEventListener(events, handle, false)
}
return dom.addEventListener(events, handle, false)
})
return $.init(this.dom)
},
off : function (events, fn){
this.map(function (dom){
return dom.removeEventListener(events, fn, false)
})
return $.init(this.dom)
},
bub : function (events, select, fn){
this.map(function (dom){
var handle = function (e){
if($(e.currentTarget).find(select).index(e.target) > -1) return fn(e)
return
}
return dom.addEventListener(events, handle, false)
})
return $.init(this.dom)
},
trigger : function (event){
this.map(function (dom){
var e = new Event(event);
dom.dispatchEvent(e)
})
return $.init(this.dom)
}
}
$.fn.extend(event)
;('focusin focusout focus blur load resize scroll unload click dblclick '+
'mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave '+
'change select keydown keypress keyup error').split(' ').forEach(function(event) {
$.fn[event] = function(callback) {
return (0 in arguments) ?
this.on(event, callback) :
this.trigger(event)
}
})
})($)