Skip to content

Commit

Permalink
feat: implement read/write of custom properties
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Jan 23, 2020
1 parent 55a81be commit a91098f
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions lib/CSSStyleDeclaration.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ CSSStyleDeclaration.prototype = {
* Returns the empty string if the property has not been set.
*/
getPropertyValue: function(name) {
if (name.indexOf('--') === 0 && this.hasOwnProperty(name)) {
return this[name];
}
if (!this._values.hasOwnProperty(name)) {
return '';
}
Expand All @@ -56,13 +59,19 @@ CSSStyleDeclaration.prototype = {
this.removeProperty(name);
return;
}
var lowercaseName = name.toLowerCase();
if (!allProperties.has(lowercaseName) && !allExtraProperties.has(lowercaseName)) {
var isCustomProperty = name.indexOf('--') === 0;
// custom properties are case-sensitive
var propertyName = isCustomProperty ? name : name.toLowerCase();
if (
!isCustomProperty &&
!allProperties.has(propertyName) &&
!allExtraProperties.has(propertyName)
) {
return;
}

this[lowercaseName] = value;
this._importants[lowercaseName] = priority;
this[propertyName] = value;
this._importants[propertyName] = priority;
},
_setProperty: function(name, value, priority) {
if (value === undefined) {
Expand Down

0 comments on commit a91098f

Please sign in to comment.