Skip to content

Commit

Permalink
Preserve '!important' in CSS Traversing
Browse files Browse the repository at this point in the history
  • Loading branch information
artf committed May 11, 2017
1 parent 33365e9 commit 476a1e9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/editor/model/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ define(['backbone', 'backboneUndo', 'keymaster', 'Utils', 'StorageManager', 'Dev

defaults: {
clipboard: null,
designerMode: false,
selectedComponent: null,
previousModel: null,
changesCount: 0,
Expand All @@ -36,7 +37,7 @@ define(['backbone', 'backboneUndo', 'keymaster', 'Utils', 'StorageManager', 'Dev
M.onLoad();
});

this.initUndoManager(); // Is already called (inside components and css composer)
this.initUndoManager();

this.on('change:selectedComponent', this.componentSelected, this);
this.on('change:changesCount', this.updateBeforeUnload, this);
Expand Down
5 changes: 4 additions & 1 deletion src/parser/model/ParserCss.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ define(function(require) {
var stl = node.style;
var style = {};
for (var j = 0, len2 = stl.length; j < len2; j++) {
style[stl[j]] = stl[stl[j]];
var propName = stl[j];
var important = stl.getPropertyPriority(propName);
style[propName] = stl[propName] +
(important ? ' !' + important : '');
}

var lastRule = '';
Expand Down
13 changes: 13 additions & 0 deletions test/specs/parser/model/ParserCss.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,19 @@ define([path + 'model/ParserCss',],
obj.parse(str).should.deep.equal(result);
});

it('Parse rule with important styles', function() {
var str = ' .test1 {color:red !important; width: 100px; height: 10px !important}';
var result = {
selectors: ['test1'],
style: {
color: 'red !important',
height: '10px !important',
width: '100px',
}
};
obj.parse(str).should.deep.equal(result);
});

});

}
Expand Down

0 comments on commit 476a1e9

Please sign in to comment.