feature(edit) add ability to drop file content

This commit is contained in:
coderaiser 2014-04-14 09:32:05 -04:00
parent b73cdf19fa
commit 49944f3a43

View file

@ -18,6 +18,7 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch, Zip;
Session,
Modelist,
Msg,
Events = DOM.Events,
Dialog = DOM.Dialog,
Key = CloudCmd.Key,
Images = DOM.Images,
@ -58,6 +59,13 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch, Zip;
});
initAce();
Events.add({
drop : onDrop,
dragover : function(event) {
event.preventDefault();
}
}, Element);
}
modesByName = Modelist.modesByName;
@ -340,6 +348,31 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch, Zip;
}
}
function onDrop(event) {
var reader, i, n, file, files,
onLoad = function(event) {
var data = event.target.result;
Ace.setValue(data);
};
event.preventDefault();
files = event.dataTransfer.files;
if (files.length) {
n = files.length;
for (i = 0; i < n; i++) {
reader = new FileReader();
file = files[i];
DOM.Events.add('load', onLoad, reader);
reader.readAsBinaryString(file);
}
}
}
this.showMessage = function(text) {
var parent,
HIDE_TIME = 2000;