Skip to content

Commit

Permalink
Improve resizable component model property
Browse files Browse the repository at this point in the history
Passing an object, will use it as additional options
  • Loading branch information
artf committed Aug 16, 2017
1 parent 43114bf commit 9202520
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/dom_components/model/Component.js
Expand Up @@ -43,6 +43,7 @@ module.exports = Backbone.Model.extend(Styleable).extend({
copyable: true,

// Indicates if it's possible to resize the component (at the moment implemented only on Image Components)
// It's also possible to pass an object as options for the Resizer
resizable: false,

// Allow to edit the content of the component (used on Text components)
Expand Down
8 changes: 7 additions & 1 deletion src/dom_components/view/ComponentView.js
Expand Up @@ -248,6 +248,7 @@ module.exports = Backbone.View.extend({
var attrName = 'data-' + pfx + 'handler';
var resizeClass = pfx + 'resizing';
var model = this.model;
var resizable = model.get('resizable');
var modelToStyle;

var toggleBodyClass = (method, e, opts) => {
Expand All @@ -259,7 +260,7 @@ module.exports = Backbone.View.extend({
}
};

if(editor && model.get('resizable')) {
if(editor && resizable) {
let resizeOptions = {
onStart(e, opts) {
toggleBodyClass('addClass', e, opts);
Expand Down Expand Up @@ -290,6 +291,11 @@ module.exports = Backbone.View.extend({
}
}
};

if (typeof resizable == 'object') {
resizeOptions = Object.assign(resizeOptions, resizable);
}

editor.runCommand('resize', {
el: this.el,
options: resizeOptions
Expand Down

0 comments on commit 9202520

Please sign in to comment.