mirror of
https://github.com/jsbin/jsbin.git
synced 2026-02-01 16:46:05 +00:00
Added support to drop files directly in to the editor - saves typing a few strokes :)
This commit is contained in:
parent
ba147b2488
commit
547ae48340
@ -3,6 +3,7 @@
|
||||
//= require "navigation"
|
||||
//= require "save"
|
||||
//= require "stream"
|
||||
//= require "file-drop"
|
||||
|
||||
var debug = false,
|
||||
$bin = $('#bin'),
|
||||
|
||||
30
js/chrome/file-drop.js
Normal file
30
js/chrome/file-drop.js
Normal file
@ -0,0 +1,30 @@
|
||||
function allowDrop(panel) {
|
||||
var holder = editors[panel].win;
|
||||
|
||||
if (typeof window.FileReader !== 'undefined') {
|
||||
holder.ondragover = function () {
|
||||
return false;
|
||||
};
|
||||
|
||||
holder.ondragend = function () {
|
||||
return false;
|
||||
};
|
||||
|
||||
holder.ondrop = function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
var file = e.dataTransfer.files[0],
|
||||
reader = new FileReader();
|
||||
reader.onload = function (event) {
|
||||
// put JS in the JavaScript panel
|
||||
editors[file.type.indexOf('javascript') > 0 ? 'javascript' : 'html'].setCode(event.target.result);
|
||||
};
|
||||
reader.readAsText(file);
|
||||
|
||||
return false;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
allowDrop('html');
|
||||
allowDrop('javascript');
|
||||
Loading…
x
Reference in New Issue
Block a user