| Index: ports/thttpd/nacl.js
|
| diff --git a/ports/thttpd/nacl.js b/ports/thttpd/nacl.js
|
| index 34da3b267ec73a2d30cff4358b4cadf790df8a21..104e1668274b75b16957724d8bc7c9bea7c2fb77 100644
|
| --- a/ports/thttpd/nacl.js
|
| +++ b/ports/thttpd/nacl.js
|
| @@ -4,10 +4,15 @@
|
| * found in the LICENSE file.
|
| */
|
|
|
| -var uploadURL = 'http://localhost:8006/tmp/'
|
| +/* jshint evil: true */
|
| +/* globals $, FileError */
|
| +
|
| +'use strict';
|
| +
|
| +var uploadURL = 'http://localhost:8006/tmp/';
|
|
|
| function moduleDidLoad() {
|
| - $("#status_field").text("SUCCESS")
|
| + $("#status_field").text("SUCCESS");
|
| }
|
|
|
| function is_array(input) {
|
| @@ -17,48 +22,49 @@ function is_array(input) {
|
| function escapeHTML(szHTML) {
|
| return szHTML.split("&").join("&").split( "<").join("<").split(">")
|
| .join(">").split("\n").join("<br />").replace(" ", " ")
|
| - .replace("\t", " ")
|
| + .replace("\t", " ");
|
| }
|
|
|
|
|
| function handleMessage(message_event) {
|
| - if (message_event.data == null || message_event.data == "null") {
|
| - console.log("warning: null message")
|
| - return
|
| + if (message_event.data === null || message_event.data == "null") {
|
| + console.log("warning: null message");
|
| + return;
|
| }
|
| console.log(message_event.data);
|
| var data = eval('('+message_event.data+')');
|
| - if (data == null) {
|
| - console.log("warning: null data")
|
| - return
|
| + if (data === null) {
|
| + console.log("warning: null data");
|
| + return;
|
| }
|
|
|
| if (data.result && data.type == "network error") {
|
| - $("#status_field").html("Failure")
|
| - $("#log").html("Network initialization error. Please supply the following "
|
| - + "flags to chrome: --enable-nacl --allow-nacl-socket-api=localhost")
|
| + $("#status_field").html("Failure");
|
| + $("#log").html("Network initialization error. Please supply the following" +
|
| + " flags to chrome: --enable-nacl --allow-nacl-socket-api=localhost");
|
| } else {
|
| - $("#log").html("<pre>" + message_event.data + "</pre>")
|
| + $("#log").html("<pre>" + message_event.data + "</pre>");
|
| }
|
| }
|
|
|
| function uploadFile(file) {
|
| (function(f) {
|
| - fs.root.getFile(file.name, {create: true, exclusive: true},
|
| + window.fs.root.getFile(file.name, {create: true, exclusive: true},
|
| function(fileEntry) {
|
| fileEntry.createWriter(function(fileWriter) {
|
| fileWriter.write(f); // Note: write() can take a File or Blob object.
|
| var url = uploadURL + file.name;
|
| - $("#log").html("File uploaded! Checkout at <a target=\"_blank\" href=\"" + url + "\">" + url + "</a>")
|
| + $("#log").html("File uploaded! Checkout at <a target=\"_blank\" href=\"" +
|
| + url + "\">" + url + "</a>");
|
| }, errorHandler);
|
| }, errorHandler);
|
| })(file);
|
| }
|
|
|
| function handleFileSelect(evt) {
|
| - var files = this.files;
|
| - for (var i = 0, file; file = files[i]; ++i) {
|
| - uploadFile(file)
|
| + var files = evt.srcElement.files;
|
| + for (var i = 0; i < files.length; i++) {
|
| + uploadFile(files[i]);
|
| }
|
| }
|
|
|
| @@ -72,18 +78,18 @@ function onInitFs(fs) {
|
| fs.root.getDirectory("/", {}, function (dir) { // readdir
|
| var dirReader = dir.createReader();
|
| var handleEntries = function(results) {
|
| - if (results.length == 0)
|
| + if (results.length === 0)
|
| return;
|
| results = toArray(results);
|
| results.forEach(function(entry, i) {
|
| - var url = uploadURL + entry.name
|
| + var url = uploadURL + entry.name;
|
| $("#listing").append('<a target="_blank" href="' + url + '">' + entry.name + "</a><br>\n");
|
| });
|
| - dirReader.readEntries(handleEntries)
|
| + dirReader.readEntries(handleEntries);
|
| };
|
| - dirReader.readEntries(handleEntries)
|
| + dirReader.readEntries(handleEntries);
|
| });
|
| - window.fs = fs
|
| + window.fs = fs;
|
| }
|
|
|
| function errorHandler(e) {
|
| @@ -108,18 +114,19 @@ function errorHandler(e) {
|
| default:
|
| msg = 'Unknown Error';
|
| break;
|
| - };
|
| - $("#log").html("Error uploading file.")
|
| + }
|
| + $("#log").html("Error uploading file.");
|
| console.log('Error: ' + msg);
|
| }
|
|
|
| $(document).ready(function() {
|
| window.URL = window.URL || window.webkitURL;
|
| - window.requestFileSystem = window.requestFileSystem
|
| - || window.webkitRequestFileSystem;
|
| + window.requestFileSystem = window.requestFileSystem ||
|
| + window.webkitRequestFileSystem;
|
| navigator.webkitPersistentStorage.requestQuota(1024*1024,
|
| function(grantedBytes) {
|
| - window.requestFileSystem(TEMPORARY, grantedBytes, onInitFs, errorHandler);
|
| + window.requestFileSystem(window.TEMPORARY, grantedBytes, onInitFs,
|
| + errorHandler);
|
| }, function(e) {
|
| console.log('Error', e);
|
| });
|
| @@ -130,4 +137,4 @@ $(document).ready(function() {
|
|
|
| document.getElementById('upfile').addEventListener(
|
| 'change', handleFileSelect, false);
|
| -})
|
| +});
|
|
|