mirror of
https://github.com/compiler-explorer/compiler-explorer.git
synced 2026-12-02 12:47:32 -06:00
File load dialog fix
Don't try and load on "change" if there's nothing selected. Fixes #373
This commit is contained in:
+14
-13
@@ -135,12 +135,14 @@ LoadSave.prototype.populate = function (root, list) {
|
||||
|
||||
LoadSave.prototype.onLocalFile = function (event) {
|
||||
var files = event.target.files;
|
||||
var file = files[0];
|
||||
var reader = new FileReader();
|
||||
reader.onload = _.bind(function () {
|
||||
this.onLoad(reader.result);
|
||||
}, this);
|
||||
reader.readAsText(file);
|
||||
if (files.length !== 0) {
|
||||
var file = files[0];
|
||||
var reader = new FileReader();
|
||||
reader.onload = _.bind(function () {
|
||||
this.onLoad(reader.result);
|
||||
}, this);
|
||||
reader.readAsText(file);
|
||||
}
|
||||
this.modal.modal('hide');
|
||||
};
|
||||
|
||||
@@ -178,7 +180,7 @@ LoadSave.prototype.onSaveToBrowserStorage = function () {
|
||||
this.alertSystem.ask(
|
||||
"Replace current?",
|
||||
"Do you want to replace the existing saved file '" + name + "'?",
|
||||
{yes: done});
|
||||
{ yes: done });
|
||||
} else {
|
||||
done();
|
||||
this.modal.modal('hide');
|
||||
@@ -195,11 +197,10 @@ LoadSave.prototype.onSaveToFile = function (fileEditor) {
|
||||
try {
|
||||
var fileLang = this.currentLanguage.name;
|
||||
var name = fileLang !== undefined && fileEditor !== undefined ?
|
||||
(fileLang +" Editor #" + fileEditor + ' ') : '';
|
||||
saveAs(new Blob(
|
||||
[this.editorText],
|
||||
{type: "text/plain;charset=utf-8"}),
|
||||
"Compiler Explorer " + name + "Code" + this.extension);
|
||||
(fileLang + " Editor #" + fileEditor + ' ') : '';
|
||||
saveAs(
|
||||
new Blob([this.editorText], { type: "text/plain;charset=utf-8" }),
|
||||
"Compiler Explorer " + name + "Code" + this.extension);
|
||||
return true;
|
||||
} catch (e) {
|
||||
this.alertSystem.notify('Error while saving your code. Use the clipboard instead.', {
|
||||
@@ -221,4 +222,4 @@ LoadSave.prototype.doLoad = function (element) {
|
||||
};
|
||||
|
||||
|
||||
module.exports = {LoadSave: LoadSave};
|
||||
module.exports = { LoadSave: LoadSave };
|
||||
|
||||
Reference in New Issue
Block a user