|
1 | 1 | /* @flow */ |
2 | 2 |
|
| 3 | +import { emptyObject } from 'shared/util' |
3 | 4 | import { parseFilters } from './parser/filter-parser' |
4 | 5 |
|
5 | 6 | export function baseWarn (msg: string) { |
@@ -42,39 +43,59 @@ export function addHandler ( |
42 | 43 | important?: boolean, |
43 | 44 | warn?: Function |
44 | 45 | ) { |
| 46 | + modifiers = modifiers || emptyObject |
45 | 47 | // warn prevent and passive modifier |
46 | 48 | /* istanbul ignore if */ |
47 | 49 | if ( |
48 | 50 | process.env.NODE_ENV !== 'production' && warn && |
49 | | - modifiers && modifiers.prevent && modifiers.passive |
| 51 | + modifiers.prevent && modifiers.passive |
50 | 52 | ) { |
51 | 53 | warn( |
52 | 54 | 'passive and prevent can\'t be used together. ' + |
53 | 55 | 'Passive handler can\'t prevent default event.' |
54 | 56 | ) |
55 | 57 | } |
| 58 | + |
56 | 59 | // check capture modifier |
57 | | - if (modifiers && modifiers.capture) { |
| 60 | + if (modifiers.capture) { |
58 | 61 | delete modifiers.capture |
59 | 62 | name = '!' + name // mark the event as captured |
60 | 63 | } |
61 | | - if (modifiers && modifiers.once) { |
| 64 | + if (modifiers.once) { |
62 | 65 | delete modifiers.once |
63 | 66 | name = '~' + name // mark the event as once |
64 | 67 | } |
65 | 68 | /* istanbul ignore if */ |
66 | | - if (modifiers && modifiers.passive) { |
| 69 | + if (modifiers.passive) { |
67 | 70 | delete modifiers.passive |
68 | 71 | name = '&' + name // mark the event as passive |
69 | 72 | } |
| 73 | + |
| 74 | + // normalize click.right and click.middle since they don't actually fire |
| 75 | + // this is technically browser-specific, but at least for now browsers are |
| 76 | + // the only target envs that have right/middle clicks. |
| 77 | + if (name === 'click') { |
| 78 | + if (modifiers.right) { |
| 79 | + name = 'contextmenu' |
| 80 | + delete modifiers.right |
| 81 | + } else if (modifiers.middle) { |
| 82 | + name = 'mouseup' |
| 83 | + } |
| 84 | + } |
| 85 | + |
70 | 86 | let events |
71 | | - if (modifiers && modifiers.native) { |
| 87 | + if (modifiers.native) { |
72 | 88 | delete modifiers.native |
73 | 89 | events = el.nativeEvents || (el.nativeEvents = {}) |
74 | 90 | } else { |
75 | 91 | events = el.events || (el.events = {}) |
76 | 92 | } |
77 | | - const newHandler = { value, modifiers } |
| 93 | + |
| 94 | + const newHandler: any = { value } |
| 95 | + if (modifiers !== emptyObject) { |
| 96 | + newHandler.modifiers = modifiers |
| 97 | + } |
| 98 | + |
78 | 99 | const handlers = events[name] |
79 | 100 | /* istanbul ignore if */ |
80 | 101 | if (Array.isArray(handlers)) { |
|
0 commit comments