Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

Commit

Permalink
Greatly simplify CSS property testing
Browse files Browse the repository at this point in the history
(cherry picked from commit 644bd98)
  • Loading branch information
queengooborg authored and foolip committed Mar 16, 2023
1 parent a3103d4 commit 233959e
Showing 1 changed file with 3 additions and 49 deletions.
52 changes: 3 additions & 49 deletions static/resources/harness.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,38 +422,6 @@
return accessed;
}

/**
* Converts a CSS property name to an equivalent IDL attribute name
*
* property (string): The CSS property name
* lowercaseFirst (boolean?): (XXX Document me!)
*
* returns (string): The property name, camel-cased and without hyphens
*/
function cssPropertyToIDLAttribute(property, lowercaseFirst) {
var output = '';
var uppercaseNext = false;

if (lowercaseFirst) {
property = property.substr(1);
}

for (var i = 0; i < property.length; i++) {
var c = property[i];

if (c === '-') {
uppercaseNext = true;
} else if (uppercaseNext) {
uppercaseNext = false;
output += c.toUpperCase();
} else {
output += c;
}
}

return output;
}

/**
* Test a CSS property for support
*
Expand All @@ -468,23 +436,9 @@
return window.CSS.supports(name, value || 'inherit');
}

if (value) {
var div = document.createElement('div');
div.style[name] = '';
div.style[name] = value;
return div.style.getPropertyValue(name) !== '';
}

var attrs = [name];
attrs.push(cssPropertyToIDLAttribute(name, name.startsWith('-')));
for (var i = 0; i < attrs.length; i++) {
var attr = attrs[i];
if (attr in document.body.style) {
return true;
}
}

return false;
var div = document.createElement('div');
div.style[name] = value || 'inherit';
return div.style.getPropertyValue(name) !== '';
}

/**
Expand Down

0 comments on commit 233959e

Please sign in to comment.