From 2b45543d7ff887fd6dd68e740cab6cfc81e96d1d Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Sun, 3 Mar 2019 13:43:38 +0100 Subject: [PATCH] Ensure default CSS block container. Fixes #1829 --- src/css_composer/view/CssRulesView.js | 25 ++++++++++++------------- src/device_manager/model/Device.js | 8 +++----- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/css_composer/view/CssRulesView.js b/src/css_composer/view/CssRulesView.js index 587da5c88..8568ca03c 100644 --- a/src/css_composer/view/CssRulesView.js +++ b/src/css_composer/view/CssRulesView.js @@ -41,11 +41,10 @@ module.exports = Backbone.View.extend({ return; } - var fragment = fragmentEl || null; - var viewObject = CssRuleView; - var config = this.config; - let rendered, view; + const fragment = fragmentEl || null; + const { config } = this; const opts = { model, config }; + let rendered, view; // I have to render keyframes of the same name together // Unfortunately at the moment I didn't find the way of appending them @@ -114,21 +113,21 @@ module.exports = Backbone.View.extend({ render() { this.renderStarted = 1; this.atRules = {}; - const $el = this.$el; + const { em, $el, className, collection } = this; const frag = document.createDocumentFragment(); - const className = this.className; $el.empty(); - // Create devices related DOM structure - this.em + // Create devices related DOM structure, ensure also to have a default container + const prs = em .get('DeviceManager') .getAll() - .pluck('priority') - .forEach(priority => { - $(`
`).appendTo(frag); - }); + .pluck('priority'); + prs.every(pr => pr) && prs.unshift(0); + prs.forEach(pr => + $(`
`).appendTo(frag) + ); - this.collection.each(model => this.addToCollection(model, frag)); + collection.each(model => this.addToCollection(model, frag)); $el.append(frag); $el.attr('class', className); return this; diff --git a/src/device_manager/model/Device.js b/src/device_manager/model/Device.js index 19ae096b7..f7fbf029d 100644 --- a/src/device_manager/model/Device.js +++ b/src/device_manager/model/Device.js @@ -1,3 +1,4 @@ +import { isUndefined } from 'underscore'; import Backbone from 'backbone'; module.exports = Backbone.Model.extend({ @@ -21,12 +22,9 @@ module.exports = Backbone.Model.extend({ }, initialize() { - if (this.get('widthMedia') == null) { + this.get('widthMedia') === null && this.set('widthMedia', this.get('width')); - } - - if (!this.get('priority')) { + !this.get('priority') && this.set('priority', parseFloat(this.get('widthMedia')) || 0); - } } });