Skip to content

Commit

Permalink
Bind onSelect to component change in selectComponent command
Browse files Browse the repository at this point in the history
  • Loading branch information
artf committed Oct 18, 2017
1 parent 0efe3b2 commit b4752b4
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions src/commands/view/SelectComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ module.exports = {
* @private
* */
toggleSelectComponent(enable) {
const em = this.em;
const method = enable ? 'on' : 'off';
const methods = {on, off};
const body = this.getCanvasBody();
Expand All @@ -99,6 +100,7 @@ module.exports = {
methods[method](body, 'click', this.onClick);
methods[method](win, 'scroll', this.onFrameScroll);
methods[method](win, 'keydown', this.onKeyPress);
em[method]('change:selectedComponent', this.onSelect, this);
},

/**
Expand Down Expand Up @@ -221,18 +223,14 @@ module.exports = {
},

/**
* Hover command
* @param {Object} e
* On element click
* @param {Event} e
* @private
*/
onClick(e) {
var m = $(e.target).data('model');
if(!m)
return;
var s = m.get('stylable');
if(!(s instanceof Array) && !s)
return;
this.onSelect(e, e.target);
e.stopPropagation();
const model = $(e.target).data('model');
model && this.editor.select(model);
},

/**
Expand Down Expand Up @@ -296,12 +294,11 @@ module.exports = {
* @param {Object} el
* @private
* */
onSelect(e, el) {
e.stopPropagation();
var model = $(el).data('model');
onSelect() {
const model = this.em.getSelected();

if (model) {
this.editor.select(model);
const el = model.view.el;
this.showFixedElementOffset(el);
this.hideElementOffset();
this.hideHighlighter();
Expand Down

0 comments on commit b4752b4

Please sign in to comment.