Browse Source

Add `styleToString` to Styleable

pull/540/head
Artur Arseniev 9 years ago
parent
commit
b2d328da1d
  1. 22
      src/dom_components/view/ComponentView.js
  2. 22
      src/domain_abstract/model/Styleable.js
  3. 6
      src/selector_manager/model/Selectors.js

22
src/dom_components/view/ComponentView.js

@ -10,13 +10,14 @@ module.exports = Backbone.View.extend({
return this.model.get('tagName');
},
initialize(opt) {
initialize(opt = {}) {
const model = this.model;
this.opts = opt || {};
this.config = this.opts.config || {};
this.em = this.config.em || '';
this.pfx = this.config.stylePrefix || '';
this.ppfx = this.config.pStylePrefix || '';
const config = opt.config || {};
this.opts = opt;
this.config = config;
this.em = config.em || '';
this.pfx = config.stylePrefix || '';
this.ppfx = config.pStylePrefix || '';
this.attr = model.get('attributes');
this.classe = this.attr.class || [];
const $el = this.$el;
@ -150,7 +151,13 @@ module.exports = Backbone.View.extend({
* @private
* */
updateStyle() {
this.setAttribute('style', this.getStyleString());
if (this.config.avoidInlineStyle) {
const model = this.model;
this.el.id = model.getId();
model.setStyle(model.getStyle());
} else {
this.setAttribute('style', this.getStyleString());
}
},
@ -224,7 +231,6 @@ module.exports = Backbone.View.extend({
}
src && (attrs.src = src);
//attrs.id = model.getId();
this.$el.attr(attrs);
this.updateHighlight();
this.updateStyle();

22
src/domain_abstract/model/Styleable.js

@ -14,6 +14,7 @@ export default {
return { ...this.getStyle(), ...prop};
},
/**
* Get style object
* @return {Object}
@ -22,6 +23,7 @@ export default {
return { ...this.get('style') };
},
/**
* Set new style object
* @param {Object|string} prop
@ -42,6 +44,7 @@ export default {
return prop;
},
/**
* Add style property
* @param {Object|string} prop
@ -63,6 +66,7 @@ export default {
this.setStyle(prop, opts);
},
/**
* Remove style property
* @param {string} prop
@ -71,5 +75,21 @@ export default {
let style = this.getStyle();
delete style[prop];
this.setStyle(style);
}
},
/**
* Returns string of style properties
* @return {String}
*/
styleToString() {
const result = [];
const style = this.getStyle();
for (let prop in style) {
result.push(`${prop}:${style[prop]}`);
}
return result.join(';');
},
}

6
src/selector_manager/model/Selectors.js

@ -11,5 +11,11 @@ module.exports = Backbone.Collection.extend({
getValid() {
return _.filter(this.models, item => !item.get('private'));
},
getFullString() {
const result = [];
this.each(selector => result.push(selector.getFullName()));
return result.join('').trim();
}
});

Loading…
Cancel
Save