Browse Source

Avoid useless attributes on nodes inside text components. Closes #2508

pull/2524/head
Artur Arseniev 7 years ago
parent
commit
4b77caf04b
  1. 1
      src/dom_components/view/ComponentTextView.js
  2. 19
      src/dom_components/view/ComponentView.js

1
src/dom_components/view/ComponentTextView.js

@ -114,6 +114,7 @@ export default ComponentView.extend({
!['text', 'default', ''].some(type => model.is(type)) || textable; !['text', 'default', ''].some(type => model.is(type)) || textable;
model.set( model.set(
{ {
_innertext: !selectable,
editable: selectable && model.get('editable'), editable: selectable && model.get('editable'),
selectable: selectable, selectable: selectable,
hoverable: selectable, hoverable: selectable,

19
src/dom_components/view/ComponentView.js

@ -30,7 +30,11 @@ export default Backbone.View.extend({
this.attr = model.get('attributes'); this.attr = model.get('attributes');
this.classe = this.attr.class || []; this.classe = this.attr.class || [];
this.listenTo(model, 'change:style', this.updateStyle); this.listenTo(model, 'change:style', this.updateStyle);
this.listenTo(model, 'change:attributes', this.renderAttributes); this.listenTo(
model,
'change:attributes change:_innertext',
this.renderAttributes
);
this.listenTo(model, 'change:highlightable', this.updateHighlight); this.listenTo(model, 'change:highlightable', this.updateHighlight);
this.listenTo(model, 'change:status', this.updateStatus); this.listenTo(model, 'change:status', this.updateStatus);
this.listenTo(model, 'change:script', this.reset); this.listenTo(model, 'change:script', this.reset);
@ -205,11 +209,14 @@ export default Backbone.View.extend({
* @private * @private
* */ * */
updateStyle() { updateStyle() {
const em = this.em; const { model, em, el } = this;
const model = this.model;
if (em && em.getConfig('avoidInlineStyle')) { if (em && em.getConfig('avoidInlineStyle')) {
this.el.id = model.getId(); if (model.get('_innertext')) {
el.removeAttribute('id');
} else {
el.id = model.getId();
}
const style = model.getStyle(); const style = model.getStyle();
!isEmpty(style) && model.setStyle(style); !isEmpty(style) && model.setStyle(style);
} else { } else {
@ -260,12 +267,12 @@ export default Backbone.View.extend({
updateAttributes() { updateAttributes() {
const attrs = []; const attrs = [];
const { model, $el, el, config } = this; const { model, $el, el, config } = this;
const { highlightable, textable, type } = model.attributes; const { highlightable, textable, type, _innertext } = model.attributes;
const { draggableComponents } = config; const { draggableComponents } = config;
const defaultAttr = { const defaultAttr = {
'data-gjs-type': type || 'default', 'data-gjs-type': type || 'default',
...(draggableComponents ? { draggable: true } : {}), ...(draggableComponents && !_innertext ? { draggable: true } : {}),
...(highlightable ? { 'data-highlightable': 1 } : {}), ...(highlightable ? { 'data-highlightable': 1 } : {}),
...(textable ...(textable
? { ? {

Loading…
Cancel
Save