Browse Source

Bind onSelect to component change in selectComponent command

pull/437/head
Artur Arseniev 9 years ago
parent
commit
b4752b4855
  1. 23
      src/commands/view/SelectComponent.js

23
src/commands/view/SelectComponent.js

@ -90,6 +90,7 @@ module.exports = {
* @private * @private
* */ * */
toggleSelectComponent(enable) { toggleSelectComponent(enable) {
const em = this.em;
const method = enable ? 'on' : 'off'; const method = enable ? 'on' : 'off';
const methods = {on, off}; const methods = {on, off};
const body = this.getCanvasBody(); const body = this.getCanvasBody();
@ -99,6 +100,7 @@ module.exports = {
methods[method](body, 'click', this.onClick); methods[method](body, 'click', this.onClick);
methods[method](win, 'scroll', this.onFrameScroll); methods[method](win, 'scroll', this.onFrameScroll);
methods[method](win, 'keydown', this.onKeyPress); methods[method](win, 'keydown', this.onKeyPress);
em[method]('change:selectedComponent', this.onSelect, this);
}, },
/** /**
@ -221,18 +223,14 @@ module.exports = {
}, },
/** /**
* Hover command * On element click
* @param {Object} e * @param {Event} e
* @private * @private
*/ */
onClick(e) { onClick(e) {
var m = $(e.target).data('model'); e.stopPropagation();
if(!m) const model = $(e.target).data('model');
return; model && this.editor.select(model);
var s = m.get('stylable');
if(!(s instanceof Array) && !s)
return;
this.onSelect(e, e.target);
}, },
/** /**
@ -296,12 +294,11 @@ module.exports = {
* @param {Object} el * @param {Object} el
* @private * @private
* */ * */
onSelect(e, el) { onSelect() {
e.stopPropagation(); const model = this.em.getSelected();
var model = $(el).data('model');
if (model) { if (model) {
this.editor.select(model); const el = model.view.el;
this.showFixedElementOffset(el); this.showFixedElementOffset(el);
this.hideElementOffset(); this.hideElementOffset();
this.hideHighlighter(); this.hideHighlighter();

Loading…
Cancel
Save