-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathevents.js
55 lines (48 loc) · 1.31 KB
/
events.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
var extend = require('xtend')
var BaseEvent = require('value-event/base-event')
var getFormData = require('form-data-set/element')
var _ = require('lodash')
exports.click = require('value-event/click')
exports.submit = require('value-event/submit')
exports.key = require('value-event/key')
// exports.change = require('value-event/change')
// exports.input = require('value-event/change')
var events = {
dblclick: 'doubleClick',
mousdown: 'mouseDown',
mouseup: 'mouseUp',
mouseover: 'mouseOver',
dragstart: 'dragStart',
change: 'change',
reset: 'reset',
focus: 'focus',
blur: 'blur',
input: {
name: 'input',
defaults: {
getFormData: true
}
},
change: {
name: 'change',
defaults: {
getFormData: true
}
}
}
_.each(events, function (eventData, domEventName) {
var defaults = eventData.defaults
var eventName = eventData.name
exports[eventName] = BaseEvent(function eventHandler (event, broadcast) {
if (event.type !== domEventName) return
var options = defaults
? extend(defaults, this.options)
: (this.options || {})
if (options.ignore) return
if (options.preventDefault) event.preventDefault()
var data = options.getFormData
? extend(getFormData(event.currentTarget), this.data)
: this.data
broadcast(data)
})
})