summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/mathml/support/attribute-values.js
blob: 8408124f49a3f7c3dcb2bec53fa4ccec8a049e1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
AttributeValueTransforms = {
    lowercase: function(value) { return value.toLowerCase(); },
    uppercase: function(value) { return value.toUpperCase(); },
    alternate_case: function(value) {
        var transformedValue = "";
        for (var i = 0; i < value.length; i++) {
            transformedValue += i % 2 ?
                value.charAt(i).toLowerCase() :
                value.charAt(i).toUpperCase();
        }
        return transformedValue;
    },
    // TODO: Should we perform this transform too?
    // https://github.com/mathml-refresh/mathml/issues/122
    // add_leading_and_trimming_whitespace: function(value) {
    //    var space = "\0020\0009\000A\000D";
    //    return `${space}${space}${value}${space}${space}`;
    // },
};

function TransformAttributeValues(transform, attributeNames) {
    if (typeof attributeNames === "string")
        attributeNames = [attributeNames];
    attributeNames.forEach(name => {
        Array.from(document.querySelectorAll(`[${name}]`)).forEach(element => {
            var value = element.getAttribute(name);
            var transformedValue = AttributeValueTransforms[transform](value);
            element.setAttribute(name, transformedValue);
        });
    });
}