summaryrefslogtreecommitdiff
path: root/Base/res/html/misc/supports.html
blob: 0593f4b35f2dc9360e7c46d26f553a888676ecd1 (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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>CSS.supports()</title>
    <style>
        @supports (color: green) {
            .p1 {
                background-color: lime;
            }
        }
        @supports (color: green) and (width: 50px) {
            .p2 {
                background-color: lime;
            }
        }
        @supports (color: green) or (flogwizzle: purple) {
            .p3 {
                background-color: lime;
            }
        }
        @supports (not (flogwizzle: purple)) {
            .p4 {
                background-color: lime;
            }
        }

        /* Selectors */
        @supports selector(.simple) {
            .p5 {
                background-color: lime;
            }
        }
        @supports selector(a#more > .complicated.case:nth-child(42)) {
            .p6 {
                background-color: lime;
            }
        }
        @supports selector(.easy) or selector(.....nope) {
            .p7 {
                background-color: lime;
            }
        }

        .negative {
            background-color: red;
        }
        @supports (not (color: green)) {
            .n1 {
                background-color: lime;
            }
        }
        @supports (color: green) and (width: 50px) or (color: green) {
            .n2 {
                background-color: lime;
            }
        }
        @supports (width: yellow) or (height: green) {
            .n3 {
                background-color: lime;
            }
        }
        @supports (flogwizzle: purple) {
            .n4 {
                background-color: lime;
            }
        }
        @supports selector(.....nope) {
            .n5 {
                background-color: lime;
            }
        }
        @supports selector(::-webkit-input-placeholder) {
            .n6 {
                background-color: lime;
            }
        }
        @supports selector(32) or selector(thing[foo??????bar]) {
            .n7 {
                background-color: lime;
            }
        }

        .success {
            background-color: lime;
        }
        .failure {
            background-color: red;
        }
    </style>
</head>
<body>
    <h1>These should all be green</h1>
    <p class="p1">@supports (color: green)</p>
    <p class="p2">@supports (color: green) and (width: 50px)</p>
    <p class="p3">@supports (color: green) or (flogwizzle: purple)</p>
    <p class="p4">@supports (not (flogwizzle: purple))</p>
    <p class="p5">@supports selector(.simple)</p>
    <p class="p6">@supports selector(a#more > .complicated.case:nth-child(42))</p>
    <p class="p7">@supports selector(.easy) or selector(.....nope)</p>

    <h1>These should all be red</h1>
    <p class="negative n1">@supports (not (color: green))</p>
    <p class="negative n2">@supports (color: green) and (width: 50px) or (color: green)</p>
    <p class="negative n3">@supports (width: yellow) or (height: green)</p>
    <p class="negative n4">@supports (flogwizzle: purple)</p>
    <p class="negative n5">@supports selector(.....nope)</p>
    <p class="negative n6">@supports selector(::-webkit-input-placeholder)</p>
    <p class="negative n7">@supports selector(32) or selector(thing[foo??????bar])</p>

    <h1>Testing CSS.supports(property, value)</h1>
    <p>These should all be green, meaning they returned true</p>
    <ul id="property-success">
    </ul>
    <p>These should all be red, meaning they returned false</p>
    <ul id="property-failure">
    </ul>

    <h1>Testing CSS.supports(string)</h1>
    <p>These should all be green, meaning they returned true</p>
    <ul id="output-success">
    </ul>
    <p>These should all be red, meaning they returned false</p>
    <ul id="output-failure">
    </ul>

<script>
    let property_success = document.getElementById("property-success");
    let property_should_succeed = [
        ["color", "green"],
        ["width", "100%"],
        ["border", "3px solid black"]
    ];
    for (let it of property_should_succeed) {
        let success = CSS.supports(it[0], it[1]);
        let li = document.createElement("li");
        li.innerText = it[0] + ": " + it[1];
        li.className = success ? "success" : "failure";
        property_success.appendChild(li);
    }

    let property_failure = document.getElementById("property-failure");
    let property_should_fail = [
        ["color", "20px"],
        ["width", "orange"],
        ["border", "9"]
    ];
    for (let it of property_should_fail) {
        let success = CSS.supports(it[0], it[1]);
        let li = document.createElement("li");
        li.innerText = it[0] + ": " + it[1];
        li.className = success ? "success" : "failure";
        property_failure.appendChild(li);
    }

    let output_success = document.getElementById("output-success");
    let should_succeed = [
        "color: green",
        "(color: green) and (width: 50px)",
        "(color: green) or (flogwizzle: purple)",
        "not (flogwizzle: purple)",
        "selector(.simple)",
        "selector(a#more > .complicated.case:nth-child(42))",
        "selector(.easy) or selector(.....nope)"
    ];
    for (let text of should_succeed) {
        let success = CSS.supports(text);
        let li = document.createElement("li");
        li.innerText = text;
        li.className = success ? "success" : "failure";
        output_success.appendChild(li);
    }

    let output_failure = document.getElementById("output-failure");
    let should_fail = [
        "not (color: green)",
        "(color: green) and (width: 50px) or (color: green)",
        "(width: yellow) or (height: green)",
        "flogwizzle: purple",
        "selector(.....nope)",
        "selector(::-webkit-input-placeholder)",
        "selector(32) or selector(thing[foo??????bar])"
    ];
    for (let text of should_fail) {
        let success = CSS.supports(text);
        let li = document.createElement("li");
        li.innerText = text;
        li.className = success ? "success" : "failure";
        output_failure.appendChild(li);
    }
</script>
</body>
</html>