|
|
|
@ -1,74 +1,22 @@ |
|
|
|
var Backbone = require('backbone'); |
|
|
|
|
|
|
|
module.exports = Backbone.View.extend({ |
|
|
|
module.exports = require('backbone').View.extend({ |
|
|
|
|
|
|
|
tagName: 'style', |
|
|
|
|
|
|
|
initialize(o) { |
|
|
|
this.config = o.config || {}; |
|
|
|
this.listenTo(this.model, 'change:style', this.render); |
|
|
|
this.listenTo(this.model, 'change:state', this.render); |
|
|
|
this.listenTo(this.model, 'destroy remove', this.remove); |
|
|
|
this.listenTo(this.model, 'change:mediaText', this.render); |
|
|
|
this.listenTo(this.model.get('selectors'), 'change', this.selChanged); |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* Triggered when some selector is changed |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
selChanged() { |
|
|
|
this.selStr = this.renderSelectors(); |
|
|
|
this.render(); |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* Returns string of selectors |
|
|
|
* @return {String} |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
renderSelectors() { |
|
|
|
const sel = []; |
|
|
|
initialize(o = {}) { |
|
|
|
this.config = o.config || {}; |
|
|
|
const model = this.model; |
|
|
|
model.get('selectors').each(model => sel.push(model.getFullName())); |
|
|
|
const sels = sel.join(''); |
|
|
|
const add = model.get('selectorsAdd'); |
|
|
|
return sels + (sels && add ? ', ' : '') + add; |
|
|
|
const toTrack = 'change:style change:state change:mediaText'; |
|
|
|
this.listenTo(model, toTrack, this.render); |
|
|
|
this.listenTo(model, 'destroy remove', this.remove); |
|
|
|
this.listenTo(model.get('selectors'), 'change', this.render); |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* Returns string of properties |
|
|
|
* @return {String} |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
renderProperties() { |
|
|
|
var sel = [], |
|
|
|
props = this.model.get('style'); |
|
|
|
for (var prop in props){ |
|
|
|
sel.push(prop + ':' + props[prop] + ';'); |
|
|
|
} |
|
|
|
return sel.join(''); |
|
|
|
}, |
|
|
|
|
|
|
|
render() { |
|
|
|
var block = '', |
|
|
|
selStr = '', |
|
|
|
o = ''; |
|
|
|
if(!this.selStr) |
|
|
|
this.selStr = this.renderSelectors(); |
|
|
|
var prpStr = this.renderProperties(); |
|
|
|
var stateStr = this.model.get('state'); |
|
|
|
var mediaText = this.model.get('mediaText'); |
|
|
|
if(this.selStr){ |
|
|
|
stateStr = stateStr ? ':' + stateStr : ''; |
|
|
|
block = prpStr !== '' ? '{' + prpStr + '}' : ''; |
|
|
|
} |
|
|
|
o = this.selStr && block ? this.selStr + stateStr + block : ''; |
|
|
|
|
|
|
|
if(mediaText && o) |
|
|
|
o = '@media ' + mediaText + '{' + o + '}'; |
|
|
|
|
|
|
|
this.$el.html(o); |
|
|
|
const model = this.model; |
|
|
|
const important = model.get('important'); |
|
|
|
this.el.innerHTML = this.model.toCSS({important}); |
|
|
|
return this; |
|
|
|
}, |
|
|
|
|
|
|
|
|