Browse Source

Refactor event propagation in CanvasView

pull/856/head
Artur Arseniev 8 years ago
parent
commit
3c92263a34
  1. 21
      src/canvas/view/CanvasView.js

21
src/canvas/view/CanvasView.js

@ -207,8 +207,8 @@ module.exports = Backbone.View.extend({
// the keyCode/which will be always `0`. Even if it's an old/deprecated
// property keymaster (and many others) still use it... using `defineProperty`
// hack seems the only way
const createCustomEvent = e => {
var oEvent = new KeyboardEvent(e.type, e);
const createCustomEvent = (e, cls) => {
var oEvent = new window[cls](e.type, e);
oEvent.keyCodeVal = e.keyCode;
['keyCode', 'which'].forEach(prop => {
Object.defineProperty(oEvent, prop, {
@ -219,12 +219,17 @@ module.exports = Backbone.View.extend({
});
return oEvent;
};
fdoc.addEventListener('keydown', e => {
doc.dispatchEvent(createCustomEvent(e));
});
fdoc.addEventListener('keyup', e => {
doc.dispatchEvent(createCustomEvent(e));
});
[
{ event: 'keydown keyup', class: 'KeyboardEvent' }
//{ event: 'mousedown mousemove mouseup', class: 'MouseEvent' },
].forEach(obj =>
obj.event.split(' ').forEach(event => {
fdoc.addEventListener(event, e =>
doc.dispatchEvent(createCustomEvent(e, obj.class))
);
})
);
}
},

Loading…
Cancel
Save