Skip to content

Commit 0793324

Browse files
authored
Merge pull request #5 from moxon6/add-import-export
Add import/export buttons
2 parents 0f25aa6 + aac74aa commit 0793324

File tree

2 files changed

+46
-5
lines changed

2 files changed

+46
-5
lines changed

index.html

+42-5
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,40 @@
88
<script type="text/python3" src="app.py"></script>
99
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/brython/3.7.5/brython.js"></script>
1010
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/brython/3.7.5/brython_stdlib.js"></script>
11-
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.6/ace.js"
12-
charset="utf-8"></script>
13-
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.6/ext-language_tools.js"
14-
charset="utf-8"></script>
11+
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.6/ace.js" charset="utf-8"></script>
12+
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.6/ext-language_tools.js" charset="utf-8"></script>
1513
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.6/theme-monokai.js"></script>
14+
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2.0.0/FileSaver.js"></script>
1615
<script>
1716
// Workaround to allow brython to handle AttributeErrors correctly
1817
window.$raise = () => null;
1918
</script>
19+
<script>
20+
function configure() {
21+
brython({debug:1})
22+
23+
document.querySelector("#export_button")
24+
.addEventListener("click", () => {
25+
saveAs(
26+
new Blob([ window.ace.edit("editor").getValue() ]),
27+
"bot.py"
28+
)
29+
})
30+
31+
document.querySelector("#import")
32+
.addEventListener("change", function(e) {
33+
const file = e.target.files[0];
34+
if (!file) return;
35+
36+
const reader = new FileReader();
37+
reader.onload = e => window.ace.edit("editor").setValue(e.target.result);
38+
reader.readAsText(file);
39+
})
40+
}
41+
</script>
2042
</head>
2143

22-
<body onload="brython({debug:1})">
44+
<body onload="configure()">
2345
<div class="app">
2446
<div class="editor-panel">
2547
<div id="editor">
@@ -29,6 +51,21 @@
2951
</div>
3052
</div>
3153
<div class="button-container">
54+
<div>
55+
<button id="import_button" class="option-button">
56+
<label for="import">
57+
<span>Import</span>
58+
<i class="fa fa-upload"></i>
59+
</label>
60+
<input id="import" type="file" onchange="onImportSelected(this)"/>
61+
</button>
62+
</div>
63+
<div>
64+
<button id="export_button" class="option-button" onclick="onExportClick()">
65+
<span>Export</span>
66+
<i class="fa fa-download"></i>
67+
</button>
68+
</div>
3269
<div>
3370
<button id="reset_button" class="option-button">
3471
<span>Reset</span>

styles/main.scss

+4
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,7 @@ body {
4343
grid-area: 1 / 2 / 3 / 3;
4444
}
4545
}
46+
47+
#import {
48+
display: none;
49+
}

0 commit comments

Comments
 (0)