Skip to content

Commit

Permalink
Now loads file content
Browse files Browse the repository at this point in the history
fixes #17
  • Loading branch information
vhoyer committed Apr 11, 2018
1 parent 12e64ae commit fd07b42
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
18 changes: 9 additions & 9 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -157,16 +157,16 @@ <h5 class="modal-title">Your custom configuragions</h5>
<textarea id="config-entry" class="form-control" v-model="configEntry"></textarea>
</div>
<div class="modal-footer">
<div class="input-group mr-auto w-25">
<div class="custom-file">
<input type="file" class="custom-file-input" id="inputGroupFile04">
<label class="custom-file-label" for="inputGroupFile04">Load a file</label>
<div class="input-group mr-auto w-25">
<div class="custom-file">
<input type="file" class="custom-file-input" id="inputGroupFile04" onchange="loadFileToConfig(this.files)">
<label class="custom-file-label" for="inputGroupFile04">Load a file</label>
</div>
</div>
</div>

<button type="button" class="btn btn-primary" @click="runConfig()" data-dismiss="modal">Run code</button>
<button type="button" class="btn btn-secondary" @click="saveConfigFile()">Download file</button>
<button type="button" class="btn" data-dismiss="modal">Close</button>

<button type="button" class="btn btn-primary" @click="runConfig()" data-dismiss="modal">Run code</button>
<button type="button" class="btn btn-secondary" @click="saveConfigFile()">Download file</button>
<button type="button" class="btn" data-dismiss="modal">Close</button>
</div>
</div>
</div>
Expand Down
26 changes: 21 additions & 5 deletions js.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,10 +457,10 @@ function copy(text) {
function storageAvailable(type) {
try {
var storage = window[type],
x = '__storage_test__';
storage.setItem(x, x);
storage.removeItem(x);
return true;
x = '__storage_test__'
storage.setItem(x, x)
storage.removeItem(x)
return true
}
catch(e) {
return e instanceof DOMException && (
Expand All @@ -474,6 +474,22 @@ function storageAvailable(type) {
// Firefox
e.name === 'NS_ERROR_DOM_QUOTA_REACHED') &&
// acknowledge QuotaExceededError only if there's something already stored
storage.length !== 0;
storage.length !== 0
}
}

function loadFileToConfig(files){
let file = files[0]
if (file == null) {
return
}

var reader = new FileReader()
reader.readAsText(file, "UTF-8")
reader.onload = function (evt) {
vm.configEntry = evt.target.result
}
reader.onerror = function (evt) {
alert("Couldn't load file's content")
}
}

0 comments on commit fd07b42

Please sign in to comment.