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

Commit

Permalink
Drag-and-drop import using HTML5 File API
Browse files Browse the repository at this point in the history
  • Loading branch information
dmfrancisco committed Jun 24, 2011
1 parent b3d0c0d commit 960e04d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
29 changes: 29 additions & 0 deletions javascripts/default.js
Expand Up @@ -68,6 +68,33 @@ function writeOn() {
$('.editor').focus();
}

/* Text file drag-and-drop */
function dropFile() {
if (typeof window.FileReader === 'undefined') {
alert('fail');
}

$("#preview").bind('dragover', function() {
$("#paper").addClass('hover');
return false;
}).bind("dragend", function() {
$("#paper").removeClass('hover');
return false;
}).bind("drop", function (e) {
$("#paper").removeClass('hover');
e.stopPropagation();
e.preventDefault();

var file = e.originalEvent.dataTransfer.files[0], reader = new FileReader();
reader.onload = function (event) {
editor.setCode(event.target.result);
render(event.target.result);
};
reader.readAsText(file);
return false;
});
}

/* Save written content */
function saveText() {
var uriContent = "data:application/octet-stream," + encodeURIComponent(editor.getCode());
Expand Down Expand Up @@ -196,10 +223,12 @@ function whileLoading() {
allMenus.each(function() {
hideWindow($(this));
});
$("#paper").removeClass('hover');
});

initLanguageMenu(); // Manage click events on the language menu
initExportMenu(); // Manage click events on the export menu
dropFile(); // Allow drag-and-drop of text files
}

/* When codemirror is ready */
Expand Down
5 changes: 5 additions & 0 deletions stylesheets/preview.css
Expand Up @@ -30,3 +30,8 @@
font-family: Menlo, Monaco, Consolas, "Lucida Console", monospace;
margin: 0; padding: 0;
}
#paper.hover {
-webkit-box-shadow: 0 0 20px rgba(255, 255, 0, 0.4);
-moz-box-shadow: 0 0 20px rgba(255, 255, 0, 0.4);
box-shadow: 0 0 20px rgba(255, 255, 0, 0.4);
}

0 comments on commit 960e04d

Please sign in to comment.