diff --git a/index.html b/index.html index 36aa32a1b..da95cc944 100755 --- a/index.html +++ b/index.html @@ -1326,11 +1326,6 @@ let computedValue = view.getComputedValue(); let defaultValue = view.getDefaultValue(); //console.log('Style of ', model.get('property'), 'Target: ', targetValue, 'Computed:', computedValue, 'Default:', defaultValue); - }) - - editor.on('block:drag:stop', function(model) { - console.log(model); - model && editor.select(model); }); editor.render(); diff --git a/src/dom_components/model/Component.js b/src/dom_components/model/Component.js index eca8bf3de..600dfd7e6 100644 --- a/src/dom_components/model/Component.js +++ b/src/dom_components/model/Component.js @@ -114,6 +114,7 @@ module.exports = Backbone.Model.extend(Styleable).extend({ this.components = new Components(this.defaultC, opt); this.components.parent = this; this.listenTo(this, 'change:script', this.scriptUpdated); + this.listenTo(this, 'change:traits', this.traitsUpdated); this.set('attributes', this.get('attributes') || {}); this.set('components', this.components); this.set('classes', new Selectors(this.defaultCl)); @@ -150,6 +151,23 @@ module.exports = Backbone.Model.extend(Styleable).extend({ this.set('scriptUpdated', 1); }, + /** + * Once traits are updated I have to populates model's attributes + */ + traitsUpdated() { + let found = 0; + const attrs = Object.assign({}, this.get('attributes')); + + this.get('traits').each((trait) => { + found = 1; + if (!trait.get('changeProp')) { + attrs[trait.get('name')] = trait.getInitValue(); + } + }); + + found && this.set('attributes', attrs); + }, + /** * Init toolbar */ diff --git a/src/trait_manager/model/Trait.js b/src/trait_manager/model/Trait.js index 2107f9382..4a28d2ad1 100644 --- a/src/trait_manager/model/Trait.js +++ b/src/trait_manager/model/Trait.js @@ -23,4 +23,8 @@ module.exports = Backbone.Model.extend({ } }, + getInitValue() { + return this.get('value') || this.get('default'); + } + });