Browse Source

Clear old attributes in updateAttributes

pull/1705/head
Artur Arseniev 7 years ago
parent
commit
d32ca0cec6
  1. 17
      src/dom_components/view/ComponentView.js

17
src/dom_components/view/ComponentView.js

@ -1,5 +1,5 @@
import Backbone from 'backbone';
import { isArray, isEmpty } from 'underscore';
import { isArray, isEmpty, each, keys } from 'underscore';
const Components = require('../model/Components');
const ComponentsView = require('./ComponentsView');
@ -232,17 +232,26 @@ module.exports = Backbone.View.extend({
* @private
* */
updateAttributes() {
const model = this.model;
const attrs = [];
const { model, $el, el } = this;
const defaultAttr = { 'data-gjs-type': model.get('type') || 'default' };
if (model.get('highlightable')) {
defaultAttr['data-highlightable'] = 1;
}
this.$el.attr({
// Remove all current attributes
each(el.attributes, attr => attrs.push(attr.nodeName));
attrs.forEach(attr => $el.removeAttr(attr));
const attr = {
...defaultAttr,
...model.getAttributes()
});
};
// Remove all `false` attributes
keys(attr).forEach(key => attr[key] === false && delete attr[key]);
$el.attr(attr);
this.updateStyle();
},

Loading…
Cancel
Save