Skip to content

Commit

Permalink
Add editor.select(el) method
Browse files Browse the repository at this point in the history
  • Loading branch information
artf committed Aug 17, 2017
1 parent 26d63a2 commit 6436e4e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
4 changes: 4 additions & 0 deletions index.html
Expand Up @@ -1328,6 +1328,10 @@ <h1 class="heading">Insert title here</h1>
//console.log('Style of ', model.get('property'), 'Target: ', targetValue, 'Computed:', computedValue, 'Default:', defaultValue);
})

editor.on('block:drag:stop', function(model) {
editor.select(model);
});

editor.render();
</script>
</body>
Expand Down
19 changes: 18 additions & 1 deletion src/editor/index.js
Expand Up @@ -329,15 +329,32 @@ module.exports = config => {
}
},

/**
* Select a component
* @param {Component|HTMLElement} el Component to select
* @return {this}
* @example
* // Select dropped block
* editor.on('block:drag:stop', function(model) {
* editor.select(model);
* });
*/
select(el) {
em.setSelected(el);
return this;
},

/**
* Set device to the editor. If the device exists it will
* change the canvas to the proper width
* @param {string} name Name of the device
* @return {this}
* @example
* editor.setDevice('Tablet');
*/
setDevice(name) {
return em.set('device', name);
em.set('device', name);
return this;
},

/**
Expand Down
15 changes: 15 additions & 0 deletions src/editor/model/Editor.js
Expand Up @@ -333,6 +333,21 @@ module.exports = Backbone.Model.extend({
return this.get('selectedComponent');
},

/**
* Select a component
* @param {Component|HTMLElement} el Component to select
* @private
*/
setSelected(el) {
let model = el;

if (el instanceof HTMLElement) {
model = $(el).data('model');
}

this.set('selectedComponent', model);
},

/**
* Set components inside editor's canvas. This method overrides actual components
* @param {Object|string} components HTML string or components model
Expand Down

0 comments on commit 6436e4e

Please sign in to comment.