| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2013 The Native Client Authors. All rights reserved. |
| 3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
| 4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
| 5 */ | 5 */ |
| 6 | 6 |
| 7 NaClTerm.nmf = 'lua.nmf' | 7 /* globals NaClTerm, lib */ |
| 8 NaClTerm.env = ['NACL_DATA_MOUNT_FLAGS=manifest=/manifest.txt'] | 8 |
| 9 'use strict'; |
| 10 |
| 11 NaClTerm.nmf = 'lua.nmf'; |
| 12 NaClTerm.env = ['NACL_DATA_MOUNT_FLAGS=manifest=/manifest.txt']; |
| 9 | 13 |
| 10 function log(message) { | 14 function log(message) { |
| 11 document.getElementById('log').textContent = message; | 15 document.getElementById('log').textContent = message; |
| 12 } | 16 } |
| 13 | 17 |
| 14 function fsErrorHandler(error) { | 18 function fsErrorHandler(error) { |
| 15 log("Filesystem error: "+ error); | 19 log("Filesystem error: "+ error); |
| 16 } | 20 } |
| 17 | 21 |
| 18 function uploadFile(file) { | 22 function uploadFile(file) { |
| 19 fs.root.getFile(file.name, {create: true, exclusive: true}, | 23 window.fs.root.getFile(file.name, {create: true, exclusive: true}, |
| 20 function(fileEntry) { | 24 function(fileEntry) { |
| 21 fileEntry.createWriter(function(fileWriter) { | 25 fileEntry.createWriter(function(fileWriter) { |
| 22 // Note: write() can take a File or Blob object. | 26 // Note: write() can take a File or Blob object. |
| 23 fileWriter.write(file); | 27 fileWriter.write(file); |
| 24 log("File uploaded!\n"); | 28 log("File uploaded!\n"); |
| 25 }, fsErrorHandler); | 29 }, fsErrorHandler); |
| 26 }, fsErrorHandler); | 30 }, fsErrorHandler); |
| 27 } | 31 } |
| 28 | 32 |
| 29 function uploadFiles(evt) { | 33 function uploadFiles(evt) { |
| 30 var files = this.files; | 34 var files = evt.srcElement.files; |
| 31 for (var i = 0, file; file = files[i]; ++i) { | 35 for (var i = 0; i < files.length; i++) { |
| 32 uploadFile(file) | 36 uploadFile(files[i]); |
| 33 } | 37 } |
| 34 } | 38 } |
| 35 | 39 |
| 36 function onInitFS(fs) { | 40 function onInitFS(fs) { |
| 37 var upload = document.getElementById('upload'); | 41 var upload = document.getElementById('upload'); |
| 38 if (upload !== null) { | 42 if (upload !== null) { |
| 39 upload.addEventListener('change', uploadFiles, false); | 43 upload.addEventListener('change', uploadFiles, false); |
| 40 window.fs = fs | 44 window.fs = fs; |
| 41 } | 45 } |
| 42 NaClTerm.init(); | 46 NaClTerm.init(); |
| 43 } | 47 } |
| 44 | 48 |
| 45 function onInit() { | 49 function onInit() { |
| 46 navigator.webkitPersistentStorage.requestQuota(1024 * 1024, | 50 navigator.webkitPersistentStorage.requestQuota(1024 * 1024, |
| 47 function(bytes) { | 51 function(bytes) { |
| 48 window.webkitRequestFileSystem(window.PERSISTENT, bytes, onInitFS) | 52 window.webkitRequestFileSystem(window.PERSISTENT, bytes, onInitFS); |
| 49 }, | 53 }, |
| 50 function() { | 54 function() { |
| 51 log("Failed to allocate space!\n"); | 55 log("Failed to allocate space!\n"); |
| 52 // Start the terminal even if FS failed to init. | 56 // Start the terminal even if FS failed to init. |
| 53 NaClTerm.init(); | 57 NaClTerm.init(); |
| 54 } | 58 } |
| 55 ); | 59 ); |
| 56 } | 60 } |
| 57 | 61 |
| 58 window.onload = function() { | 62 window.onload = function() { |
| 59 lib.init(function() { | 63 lib.init(function() { |
| 60 onInit(); | 64 onInit(); |
| 61 }); | 65 }); |
| 62 }; | 66 }; |
| OLD | NEW |