Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/CSSStyleDeclaration.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ CSSOM.CSSStyleDeclaration.prototype = {
this._importants[name] = priority;
},

/**
*
* @param {string} name
* @param {string} value
* @param {string} [priority=null] "important" or null
* For perserving multiple declarations of the same property value.
*/
mergeProperty: function(name, value, priority) {
var newVal = this[name] + "; " + name + ": " + value;
this[name] = newVal;
this._importants[name] = priority;
},

/**
*
* @param {string} name
Expand Down
14 changes: 12 additions & 2 deletions lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,12 @@ CSSOM.parse = function parse(token) {
case ";":
switch (state) {
case "value":
styleRule.style.setProperty(name, buffer.trim(), priority);
// Don't write over a redefined style
if (styleRule.style.getPropertyValue(name)) {
styleRule.style.mergeProperty(name, buffer.trim(), priority);
} else {
styleRule.style.setProperty(name, buffer.trim(), priority);
}
priority = "";
buffer = "";
state = "before-name";
Expand All @@ -300,7 +305,12 @@ CSSOM.parse = function parse(token) {
case "}":
switch (state) {
case "value":
styleRule.style.setProperty(name, buffer.trim(), priority);
// Don't write over a redefined style
if (styleRule.style.getPropertyValue(name)) {
styleRule.style.mergeProperty(name, buffer.trim(), priority);
} else {
styleRule.style.setProperty(name, buffer.trim(), priority);
}
priority = "";
case "before-name":
case "name":
Expand Down
48 changes: 48 additions & 0 deletions spec/parse.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,54 @@ var TESTS = [
return result;
})()
},
{
input: ".shadow{-webkit-box-shadow: 7px 7px 5px rgba(50, 50, 50, 0.75); -moz-box-shadow: 7px 7px 5px rgba(50, 50, 50, 0.75); box-shadow: 7px 7px 5px rgba(50, 50, 50, 0.75)}",
result: (function() {
var result = {
cssRules: [
{
selectorText: '.shadow',
parentRule: null,
style: {
0: '-webkit-box-shadow',
1: '-moz-box-shadow',
2: 'box-shadow',
'-webkit-box-shadow': '7px 7px 5px rgba(50, 50, 50, 0.75)',
'-moz-box-shadow': '7px 7px 5px rgba(50, 50, 50, 0.75)',
'box-shadow': '7px 7px 5px rgba(50, 50, 50, 0.75)',
length: 3
}
}
],
parentStyleSheet: null
};
result.cssRules[0].parentStyleSheet = result;
result.cssRules[0].style.parentRule = result.cssRules[0];
return result;
})()
},
{
input: ".background-gradient{background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#1a82f7), to(#2F2727)); background: -webkit-linear-gradient(top, #2F2727, #1a82f7); background: -moz-linear-gradient(top, #2F2727, #1a82f7); background: -ms-linear-gradient(top, #2F2727, #1a82f7); background: -o-linear-gradient(top, #2F2727, #1a82f7)}",
result: (function() {
var result = {
cssRules: [
{
selectorText: '.background-gradient',
parentRule: null,
style: {
0: 'background',
background: '-webkit-gradient(linear, 0% 0%, 0% 100%, from(#1a82f7), to(#2F2727)); background: -webkit-linear-gradient(top, #2F2727, #1a82f7); background: -moz-linear-gradient(top, #2F2727, #1a82f7); background: -ms-linear-gradient(top, #2F2727, #1a82f7); background: -o-linear-gradient(top, #2F2727, #1a82f7)',
length: 1
}
}
],
parentStyleSheet: null
};
result.cssRules[0].parentStyleSheet = result;
result.cssRules[0].style.parentRule = result.cssRules[0];
return result;
})()
},
{
input: "@media handheld, only screen and (max-device-width: 480px) {body{max-width:480px}}",
result: (function() {
Expand Down