Browse Source

Update Select component event binding

no-jquery
Artur Arseniev 9 years ago
parent
commit
b25eb1e73d
  1. 10
      src/commands/view/MoveComponent.js
  2. 35
      src/commands/view/SelectComponent.js

10
src/commands/view/MoveComponent.js

@ -1,3 +1,5 @@
import {on, off} from 'utils/mixins'
const SelectComponent = require('./SelectComponent');
const SelectPosition = require('./SelectPosition');
const $ = Backbone.$;
@ -49,7 +51,7 @@ module.exports = _.extend({}, SelectPosition, SelectComponent, {
this.sorter.onEndMove = this.onEndMove.bind(this);
this.stopSelectComponent();
this.$wrapper.off('mousedown', this.initSorter);
this.getContentWindow().on('keydown', this.rollback);
on(this.getContentWindow(), 'keydown', this.rollback);
},
/**
@ -77,11 +79,11 @@ module.exports = _.extend({}, SelectPosition, SelectComponent, {
*/
this.stopSelectComponent();
this.getContentWindow().on('keydown', this.rollback);
on(this.getContentWindow(), 'keydown', this.rollback);
},
onEndMoveFromModel() {
this.getContentWindow().off('keydown', this.rollback);
off(this.getContentWindow(), 'keydown', this.rollback);
},
/**
@ -90,7 +92,7 @@ module.exports = _.extend({}, SelectPosition, SelectComponent, {
*/
onEndMove() {
this.enable();
this.getContentWindow().off('keydown', this.rollback);
off(this.getContentWindow(), 'keydown', this.rollback);
},
/**

35
src/commands/view/SelectComponent.js

@ -1,3 +1,5 @@
import {on, off} from 'utils/mixins'
const ToolbarView = require('dom_components/view/ToolbarView');
const Toolbar = require('dom_components/model/Toolbar');
const key = require('keymaster');
@ -67,16 +69,6 @@ module.exports = {
}
},
/**
* Returns canavs body el
*/
getCanvasBodyEl() {
if(!this.$bodyEl) {
this.$bodyEl = $(this.getCanvasBody());
}
return this.$bodyEl;
},
/**
* Start select component event
* @private
@ -98,16 +90,15 @@ module.exports = {
* @private
* */
toggleSelectComponent(enable) {
var el = '*';
var method = enable ? 'on' : 'off';
this.getCanvasBodyEl()
[method]('mouseover', el, this.onHover)
[method]('mouseout', el, this.onOut)
[method]('click', el, this.onClick);
var cw = this.getContentWindow();
cw[method]('scroll', this.onFrameScroll);
cw[method]('keydown', this.onKeyPress);
const method = enable ? 'on' : 'off';
const methods = {on, off};
const body = this.getCanvasBody();
const win = this.getContentWindow();
methods[method](body, 'mouseover', this.onHover);
methods[method](body, 'mouseout', this.onOut);
methods[method](body, 'click', this.onClick);
methods[method](win, 'scroll', this.onFrameScroll);
methods[method](win, 'keydown', this.onKeyPress);
},
/**
@ -556,9 +547,7 @@ module.exports = {
* @private
*/
getContentWindow() {
if(!this.contWindow)
this.contWindow = $(this.frameEl.contentWindow);
return this.contWindow;
return this.frameEl.contentWindow;
},
run(editor) {

Loading…
Cancel
Save