From d32ca0cec6cb14ac9178aeee9026310e2fa900e1 Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Mon, 24 Dec 2018 17:43:33 +0100 Subject: [PATCH] Clear old attributes in updateAttributes --- src/dom_components/view/ComponentView.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/dom_components/view/ComponentView.js b/src/dom_components/view/ComponentView.js index 1dd8e5540..efd76bcbf 100644 --- a/src/dom_components/view/ComponentView.js +++ b/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(); },