Skip to content

Commit fcab3bc

Browse files
committed
Add Demo Helpers
Includes: - HTML5 File API check - Sine graph point generator
1 parent 38573b5 commit fcab3bc

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

examples/_helpers.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
function isFileAPIAvailable() {
2+
// Check for the various File API support.
3+
if (window.File && window.FileReader && window.FileList && window.Blob) {
4+
// Great success! All the File APIs are supported.
5+
return true;
6+
} else {
7+
// source: File API availability - http://caniuse.com/#feat=fileapi
8+
// source: <output> availability - http://html5doctor.com/the-output-element/
9+
document.writeln('The HTML5 APIs used in this form are only available in the following browsers:<br />');
10+
// 6.0 File API & 13.0 <output>
11+
document.writeln(' - Google Chrome: 13.0 or later<br />');
12+
// 3.6 File API & 6.0 <output>
13+
document.writeln(' - Mozilla Firefox: 6.0 or later<br />');
14+
// 10.0 File API & 10.0 <output>
15+
document.writeln(' - Internet Explorer: Not supported (partial support expected in 10.0)<br />');
16+
// ? File API & 5.1 <output>
17+
document.writeln(' - Safari: Not supported<br />');
18+
// ? File API & 9.2 <output>
19+
document.writeln(' - Opera: Not supported');
20+
return false;
21+
}
22+
}
23+
24+
// Used to generate the data for the sine wave demo
25+
// source: http://coding.smashingmagazine.com/2011/10/04/quick-look-math-animations-javascript/
26+
function drawSine() {
27+
var counter = 0;
28+
// 100 iterations
29+
var increase = Math.PI * 2 / 100;
30+
for ( i = 0; i <= 1; i += 0.01 ) {
31+
x = i;
32+
y = Math.sin( counter ) / 2 + 0.5;
33+
counter += increase;
34+
console.log(x + ',' + y);
35+
}
36+
}

0 commit comments

Comments
 (0)