提交 | 用户 | age
|
f75425
|
1 |
const validEvents = [ |
V |
2 |
'onActivate', |
|
3 |
'onAddUndo', |
|
4 |
'onBeforeAddUndo', |
|
5 |
'onBeforeExecCommand', |
|
6 |
'onBeforeGetContent', |
|
7 |
'onBeforeRenderUI', |
|
8 |
'onBeforeSetContent', |
|
9 |
'onBeforePaste', |
|
10 |
'onBlur', |
|
11 |
'onChange', |
|
12 |
'onClearUndos', |
|
13 |
'onClick', |
|
14 |
'onContextMenu', |
|
15 |
'onCopy', |
|
16 |
'onCut', |
|
17 |
'onDblclick', |
|
18 |
'onDeactivate', |
|
19 |
'onDirty', |
|
20 |
'onDrag', |
|
21 |
'onDragDrop', |
|
22 |
'onDragEnd', |
|
23 |
'onDragGesture', |
|
24 |
'onDragOver', |
|
25 |
'onDrop', |
|
26 |
'onExecCommand', |
|
27 |
'onFocus', |
|
28 |
'onFocusIn', |
|
29 |
'onFocusOut', |
|
30 |
'onGetContent', |
|
31 |
'onHide', |
|
32 |
'onInit', |
|
33 |
'onKeyDown', |
|
34 |
'onKeyPress', |
|
35 |
'onKeyUp', |
|
36 |
'onLoadContent', |
|
37 |
'onMouseDown', |
|
38 |
'onMouseEnter', |
|
39 |
'onMouseLeave', |
|
40 |
'onMouseMove', |
|
41 |
'onMouseOut', |
|
42 |
'onMouseOver', |
|
43 |
'onMouseUp', |
|
44 |
'onNodeChange', |
|
45 |
'onObjectResizeStart', |
|
46 |
'onObjectResized', |
|
47 |
'onObjectSelected', |
|
48 |
'onPaste', |
|
49 |
'onPostProcess', |
|
50 |
'onPostRender', |
|
51 |
'onPreProcess', |
|
52 |
'onProgressState', |
|
53 |
'onRedo', |
|
54 |
'onRemove', |
|
55 |
'onReset', |
|
56 |
'onSaveContent', |
|
57 |
'onSelectionChange', |
|
58 |
'onSetAttrib', |
|
59 |
'onSetContent', |
|
60 |
'onShow', |
|
61 |
'onSubmit', |
|
62 |
'onUndo', |
|
63 |
'onVisualAid', |
|
64 |
]; |
|
65 |
|
|
66 |
const isValidKey = (key: string) => validEvents.indexOf(key) !== -1; |
|
67 |
|
|
68 |
export const bindHandlers = (initEvent: Event, listeners: any, editor: any): void => { |
|
69 |
Object.keys(listeners) |
|
70 |
.filter(isValidKey) |
|
71 |
.forEach((key: string) => { |
|
72 |
const handler = listeners[key]; |
|
73 |
if (typeof handler === 'function') { |
|
74 |
if (key === 'onInit') { |
|
75 |
handler(initEvent, editor); |
|
76 |
} else { |
|
77 |
editor.on(key.substring(2), (e: any) => handler(e, editor)); |
|
78 |
} |
|
79 |
} |
|
80 |
}); |
|
81 |
}; |