Skip to content
This repository has been archived by the owner on Feb 12, 2018. It is now read-only.

Commit

Permalink
Bug fix (old file import instructions were being displayed when click…
Browse files Browse the repository at this point in the history
…ing the import button in write mode)
  • Loading branch information
dmfrancisco committed Jul 13, 2011
1 parent a079bf6 commit 522a009
Showing 1 changed file with 27 additions and 23 deletions.
50 changes: 27 additions & 23 deletions public/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ jQuery.fn.iphoneSwitch = function (start_state, switched_on_callback, switched_o
if (state === 'off') {
switchPanel(function () {
// This shouldn't be done here of course, but this is not a serious project so I'm not worried
$('#paper').html("<p style='font-size:20px'><strong>Drag <em>&amp;</em> drop a file</strong>, from " +
"your system, into this paper sheet.</p>");
escrito.addImportInstructions();
});
}
});
Expand Down Expand Up @@ -365,6 +364,30 @@ var escrito = function () {
reader.readAsText(file);
}

/* Print some instructions on how to upload files in the paper sheet */
function addImportInstructions() {
var importMessage = "";

if (typeof window.File !== 'undefined' &&
typeof window.FileReader !== 'undefined' &&
Modernizr.draganddrop) { /* Chrome & Firefox 4+ */
importMessage = "<p style='font-size:20px'><strong>Drag <em>&amp;</em> drop a file</strong>, " +
"from your system, into this paper sheet.</p><p>Alternatively, you can also " +
"upload it here: <input type=file></p>";

} else if (typeof window.FileReader !== 'undefined') { /* Opera? */
importMessage = "<p style='font-size:20px'><strong>Upload a file</strong>, " +
"from your system: <input type=file></p>";
} else { /* IE */
importMessage = "<p style='font-size:20px'>Currently, <strong>we don't support file uploads</strong> " +
"to our servers.</p><p>Please, copy <em>&amp;</em> paste your file's content or try a "+
"different browser, such as Chrome or Firefox.</p>";
}

$('#paper').html(importMessage);
$("input:file").uniform({fileDefaultText: 'No file chosen'});
}

/* Save written content */
function saveText() {
var uriContent = "data:application/octet-stream," + encodeURIComponent(editor.getSession().getValue());
Expand Down Expand Up @@ -475,26 +498,7 @@ var escrito = function () {

// When clicking the import button
$('#import-button').click(function (e) {
var importMessage = "";

if (typeof window.File !== 'undefined' &&
typeof window.FileReader !== 'undefined' &&
Modernizr.draganddrop) { /* Chrome & Firefox 4+ */
importMessage = "<p style='font-size:20px'><strong>Drag <em>&amp;</em> drop a file</strong>, " +
"from your system, into this paper sheet.</p><p>Alternatively, you can also " +
"upload it here: <input type=file></p>";

} else if (typeof window.FileReader !== 'undefined') { /* Opera? */
importMessage = "<p style='font-size:20px'><strong>Upload a file</strong>, " +
"from your system: <input type=file></p>";
} else { /* IE */
importMessage = "<p style='font-size:20px'>Currently, <strong>we don't support file uploads</strong> " +
"to our servers.</p><p>Please, copy <em>&amp;</em> paste your file's content or try a "+
"different browser, such as Chrome or Firefox.</p>";
}

$('#paper').html(importMessage);
$("input:file").uniform({fileDefaultText: 'No file chosen'});
addImportInstructions();
uploadFileClientSide();
});

Expand Down Expand Up @@ -542,7 +546,7 @@ var escrito = function () {
});
}

return { init : init };
return { init : init, addImportInstructions: addImportInstructions };
}();

$(document).ready(function () {
Expand Down

0 comments on commit 522a009

Please sign in to comment.