mirror of
https://github.com/demostf/demo.js
synced 2026-06-03 16:44:12 +02:00
Browser version
This commit is contained in:
parent
27ebb577df
commit
127b82aa96
3 changed files with 2623 additions and 0 deletions
2561
browser.js
Normal file
2561
browser.js
Normal file
File diff suppressed because it is too large
Load diff
34
browsertest.js
Normal file
34
browsertest.js
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
var Demo = require('./demo');
|
||||
|
||||
document.addEventListener("DOMContentLoaded", function (event) {
|
||||
console.log('as');
|
||||
var input = document.getElementById('fileinput');
|
||||
input.onchange = handleFileSelect;
|
||||
});
|
||||
|
||||
function handleFileSelect(evt) {
|
||||
var files = evt.target.files; // FileList object
|
||||
|
||||
// Loop through the FileList and render image files as thumbnails.
|
||||
for (var i = 0, f; f = files[i]; i++) {
|
||||
|
||||
var reader = new FileReader();
|
||||
|
||||
// Closure to capture the file information.
|
||||
reader.onload = (function (theFile) {
|
||||
return function (buffer) {
|
||||
console.log(buffer.target.result);
|
||||
var demo = new Demo(buffer.target.result);
|
||||
var parser = demo.getParser();
|
||||
var head = parser.readHeader();
|
||||
var state = parser.parseBody();
|
||||
document.getElementById('head').value = JSON.stringify(head, null, 2);
|
||||
document.getElementById('out').value = JSON.stringify(state, null, 2);
|
||||
};
|
||||
})(f);
|
||||
|
||||
// Read in the image file as a data URL.
|
||||
console.log(f);
|
||||
reader.readAsArrayBuffer(f);
|
||||
}
|
||||
}
|
||||
28
index.html
Normal file
28
index.html
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
<html>
|
||||
<head>
|
||||
<script src="browser.js"></script>
|
||||
<style>
|
||||
textarea {
|
||||
width: 100%;
|
||||
height: 200px;
|
||||
}
|
||||
|
||||
#out {
|
||||
height: 500px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<input type="file" id="fileinput" />
|
||||
|
||||
<p>Demo header</p>
|
||||
<textarea id="head">
|
||||
|
||||
</textarea>
|
||||
|
||||
<p>Demo summary</p>
|
||||
<textarea id="out">
|
||||
|
||||
</textarea>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Add a link
Reference in a new issue