Skip to content

Commit c1f3ea6

Browse files
committed
Added live browser tests, to show whether current viewing browser supports particular technology
1 parent 38fe49a commit c1f3ea6

File tree

4 files changed

+83
-31
lines changed

4 files changed

+83
-31
lines changed

css/html5demos.css

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ body.view-source #view-source {
177177
}
178178

179179
#demos .support {
180-
width: 105px;
180+
width: 126px;
181181
}
182182

183183
.support span {
@@ -261,6 +261,25 @@ body.view-source #view-source {
261261
#html5badge {
262262
/* display: none;*/
263263
margin-left: -30px;
264+
border: 0;
265+
}
266+
267+
#html5badge img {
268+
border: 0;
269+
}
270+
271+
.support span.yourbrowser {
272+
width: 16px;
273+
height: 16px;
274+
background: none;
275+
}
276+
277+
.support span.yourbrowser.supported {
278+
background: url(http://github.com/..%3Cspan%20class=pl-c1%3E/%3C/span%3Eimages/yourbrowser.gif) no-repeat top left;
279+
}
280+
281+
.support span.yourbrowser.not-supported {
282+
background: url(http://github.com/..%3Cspan%20class=pl-c1%3E/%3C/span%3Eimages/yourbrowser.gif) no-repeat top right;
264283
}
265284

266285
/** Pretty printing styles. Used with prettify.js. */

demos.json

Lines changed: 43 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"support": {
77
"live": "chrome",
88
"nightly": "safari"
9-
}
9+
},
10+
"test": "'dataset' in document.createElement('i')"
1011
},
1112
{
1213
"desc": "History API using pushState",
@@ -16,17 +17,18 @@
1617
"support": {
1718
"live": "chrome safari",
1819
"nightly": "firefox"
19-
}
20+
},
21+
"test": "Modernizr.history"
2022
},
2123
{
2224
"desc": "Drag files directly into your browser",
2325
"url": "file-api",
2426
"note": "Not directly part of HTML5",
2527
"tags": "file-api dnd",
2628
"support": {
27-
"live": "firefox",
28-
"nightly": "chrome"
29-
}
29+
"live": "firefox chrome"
30+
},
31+
"test": "typeof FileReader != 'undefined'"
3032
},
3133
{
3234
"desc": "Simple chat client",
@@ -35,7 +37,8 @@
3537
"support": {
3638
"live": "safari chrome",
3739
"nightly": "firefox opera"
38-
}
40+
},
41+
"test": "Modernizr.websockets"
3942
},
4043
{
4144
"desc": "Two videos playing in sync",
@@ -44,7 +47,8 @@
4447
"support": {
4548
"live": "firefox opera safari chrome",
4649
"nightly": "ie"
47-
}
50+
},
51+
"test": "Modernizr.video"
4852
},
4953
{
5054
"desc": "Interactive canvas gradients",
@@ -53,7 +57,8 @@
5357
"support": {
5458
"live": "firefox opera safari chrome",
5559
"nightly": "ie"
56-
}
60+
},
61+
"test": "Modernizr.canvas"
5762
},
5863
{
5964
"desc": "Canvas & Video",
@@ -62,7 +67,8 @@
6267
"support": {
6368
"live": "firefox opera safari chrome",
6469
"nightly": "ie"
65-
}
70+
},
71+
"test": "Modernizr.video && Modernizr.canvas"
6672
},
6773
{
6874
"desc": "Video",
@@ -71,7 +77,8 @@
7177
"support": {
7278
"live": "firefox opera safari chrome",
7379
"nightly": "ie"
74-
}
80+
},
81+
"test": "Modernizr.video"
7582
},
7683
{
7784
"desc": "Canvas",
@@ -80,24 +87,28 @@
8087
"support": {
8188
"live": "firefox opera safari chrome",
8289
"nightly": "ie"
83-
}
90+
},
91+
"test": "Modernizr.canvas"
8492
},
8593
{
8694
"desc": "Content Editable",
8795
"url": "contenteditable",
8896
"tags": "contenteditable storage",
8997
"support": {
9098
"live": "ie firefox opera safari chrome"
91-
}
99+
},
100+
"test": "'isContentEditable' in document.createElement('span');"
92101
},
93102
{
94103
"desc": "Geolocation",
95104
"url": "geo",
96105
"tags": "geolocation",
97106
"note": "Works on Safari Mobile too",
98107
"support": {
99-
"live": "firefox chrome safari opera"
100-
}
108+
"live": "firefox chrome safari opera",
109+
"nightly": "ie"
110+
},
111+
"test": "Modernizr.geolocation"
101112
},
102113
{
103114
"desc": "postMessage",
@@ -106,7 +117,8 @@
106117
"tags": "postMessage",
107118
"support": {
108119
"live": "ie firefox opera safari chrome"
109-
}
120+
},
121+
"test": "Modernizr.postmessage"
110122
},
111123
{
112124
"desc": "postMessage",
@@ -115,23 +127,26 @@
115127
"note": "cross domain",
116128
"support": {
117129
"live": "ie firefox opera safari chrome"
118-
}
130+
},
131+
"test": "Modernizr.postmessage"
119132
},
120133
{
121134
"desc": "drag and drop",
122135
"url": "drag",
123136
"tags": "dnd",
124137
"support": {
125138
"live": "ie firefox safari chrome"
126-
}
139+
},
140+
"test": "Modernizr.draganddrop"
127141
},
128142
{
129143
"desc": "drag anything",
130144
"url": "drag-anything",
131145
"tags": "dnd",
132146
"support": {
133147
"live": "ie firefox safari chrome"
134-
}
148+
},
149+
"test": "Modernizr.draganddrop"
135150
},
136151
{
137152
"desc": "offline detection",
@@ -167,31 +182,35 @@
167182
"tags": "offline manifest",
168183
"support": {
169184
"live": "firefox safari chrome opera"
170-
}
185+
},
186+
"test": "Modernizr.applicationcache"
171187
},
172188
{
173189
"desc": "Storage",
174190
"url": "storage",
175191
"tags": "storage",
176192
"support": {
177193
"live": "ie firefox opera safari chrome"
178-
}
194+
},
195+
"test": "Modernizr.sessionstorage && Modernizr.localstorage"
179196
},
180197
{
181198
"desc": "Web SQL Database Storage",
182199
"url": "database",
183200
"tags": "sql-database",
184201
"support": {
185202
"live": "safari chrome opera"
186-
}
203+
},
204+
"test": "Modernizr.websqldatabase"
187205
},
188206
{
189207
"desc": "Web SQL Database - rollback test",
190208
"url": "database-rollback",
191209
"tags": "sql-database",
192210
"support": {
193211
"live": "safari chrome opera"
194-
}
212+
},
213+
"test": "Modernizr.websqldatabase"
195214
},
196215
{
197216
"desc": "Web Workers",
@@ -200,6 +219,7 @@
200219
"note": "watch out - uses a lot of CPU! <a href=\"non-worker\">example without - will hang your browser</a>",
201220
"support": {
202221
"live": "safari chrome firefox opera"
203-
}
222+
},
223+
"test": "Modernizr.webworkers"
204224
}
205225
]

html5demo.manifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CACHE MANIFEST
22

3-
# version 15
3+
# Build 2011-02-22
44

55
CACHE:
66
images/shade.jpg

index.php

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<?php
22
$demos = json_decode(file_get_contents('demos.json'));
33

4-
function support($support) {
4+
function support($support, $url) {
55
$browsers = split(' ', 'ie firefox opera safari chrome'); // big 5 - should I add iPhone (for geo, etc)?
66
77
$live = isset($support->live) ? split(' ', $support->live) : array();
88
$nightly = isset($support->nightly) ? split(' ', $support->nightly) : array();
99

10-
$html = '';
10+
$html = '<span title="unknown browser support" class="yourbrowser tag" id="test-' . $url . '"></span> ';
1111

1212
foreach ($browsers as $browser) {
1313
$class = '';
@@ -43,6 +43,7 @@ function spans($list) {
4343
<title>HTML5 Demos and Examples</title>
4444
<link rel="stylesheet" href="/css/html5demos.css" type="text/css" />
4545
<script src="js/h5utils.js"></script>
46+
<script src="js/modernizr.custom.js"></script>
4647
</head>
4748
<body>
4849
<section id="wrapper">
@@ -64,14 +65,14 @@ function spans($list) {
6465
<tr>
6566
<th>Demo</th>
6667
<th>Support</th>
67-
<th>Technology</th>
68+
<th>Technology</th>
6869
</tr>
6970
</thead>
7071
<tbody>
7172
<?php foreach ($demos as $demo) :?>
7273
<tr>
7374
<td class="demo"><a href="<?=$demo->url?>"><?=$demo->desc?></a><?php if (isset($demo->note)) { echo ' <small>' . $demo->note . '</small>'; }?></td>
74-
<td class="support"><?=support($demo->support)?></td>
75+
<td class="support"><?=support($demo->support, $demo->url)?></td>
7576
<td class="tags"><?=spans($demo->tags)?></td>
7677
</tr>
7778
<?php endforeach ?>
@@ -86,8 +87,9 @@ function spans($list) {
8687
<footer><a id="built" href="http://twitter.com/rem">@rem built this</a></footer>
8788
</section>
8889

89-
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.%3Cspan%20class="x x-first x-last">4.2/jquery.min.js"></script>
90+
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.%3Cspan%20class="x x-first x-last">5/jquery.min.js"></script>
9091
<script>
92+
var tags = [];
9193
$(document).delegate('span.tag', 'click', function () {
9294
var $tag = $(this), tag = $tag.text(), type = $tag.closest('td').attr('class') || 'tags';
9395

@@ -104,7 +106,7 @@ function spans($list) {
104106
$trs.show();
105107
} else {
106108
$('tbody tr').show();
107-
}
109+
}
108110
});
109111

110112
var html = [];
@@ -119,6 +121,17 @@ function spans($list) {
119121

120122
$('#tags').append('<strong>Filter demos:</strong> ' + html.sort().join(''));
121123

124+
$.getJSON('demos.json', function (data) {
125+
var i = data.length, $test;
126+
while (i--) {
127+
if (data[i].test && (new Function('return ' + data[i].test))()) {
128+
$('#test-' + data[i].url).addClass('supported').attr('title', 'your browser is supported');
129+
} else if (data[i].test) {
130+
$('#test-' + data[i].url).addClass('not-supported').attr('title', 'your browser is NOT supported');
131+
}
132+
}
133+
});
134+
122135
// $('tr td.demo').click(function () {
123136
// window.location = $(this).find('a').attr('href');
124137
// });

0 commit comments

Comments
 (0)