Skip to content

Commit a91098f

Browse files
committed
feat: implement read/write of custom properties
1 parent 55a81be commit a91098f

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

lib/CSSStyleDeclaration.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ CSSStyleDeclaration.prototype = {
3535
* Returns the empty string if the property has not been set.
3636
*/
3737
getPropertyValue: function(name) {
38+
if (name.indexOf('--') === 0 && this.hasOwnProperty(name)) {
39+
return this[name];
40+
}
3841
if (!this._values.hasOwnProperty(name)) {
3942
return '';
4043
}
@@ -56,13 +59,19 @@ CSSStyleDeclaration.prototype = {
5659
this.removeProperty(name);
5760
return;
5861
}
59-
var lowercaseName = name.toLowerCase();
60-
if (!allProperties.has(lowercaseName) && !allExtraProperties.has(lowercaseName)) {
62+
var isCustomProperty = name.indexOf('--') === 0;
63+
// custom properties are case-sensitive
64+
var propertyName = isCustomProperty ? name : name.toLowerCase();
65+
if (
66+
!isCustomProperty &&
67+
!allProperties.has(propertyName) &&
68+
!allExtraProperties.has(propertyName)
69+
) {
6170
return;
6271
}
6372

64-
this[lowercaseName] = value;
65-
this._importants[lowercaseName] = priority;
73+
this[propertyName] = value;
74+
this._importants[propertyName] = priority;
6675
},
6776
_setProperty: function(name, value, priority) {
6877
if (value === undefined) {

0 commit comments

Comments
 (0)