summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--public/index.php1
-rw-r--r--public/site.js10
2 files changed, 11 insertions, 0 deletions
diff --git a/public/index.php b/public/index.php
index e767a65..b6ac78e 100644
--- a/public/index.php
+++ b/public/index.php
@@ -150,6 +150,7 @@ $csrf = csrf_token();
<textarea maxlength="16383" id="editor" name="code" rows="20"><?= htmlentities($code ?? $defaultCode) ?></textarea>
<div id="toolbar">
<button type="submit">&#9654;&nbsp;Compile &amp; run</button>
+ <button type="button" id="dlCodeButton">Download code as file</button>
</div>
</form>
<div id="output" style="display: none;"></div>
diff --git a/public/site.js b/public/site.js
index 17a8115..ed7173d 100644
--- a/public/site.js
+++ b/public/site.js
@@ -11,6 +11,16 @@ $(function() {
});
editor.setSize(null, 500);
+ $("#dlCodeButton").on("click", function() {
+ var a = $("<a></a>")
+ .attr("href", "data:text/x-java;charset=UTF-8," + encodeURIComponent(editor.getValue()))
+ .attr("download", "Program.java")
+ .css("display", "none")
+ .appendTo("body");
+ a.get(0).click();
+ a.remove();
+ });
+
$("form").on("submit", function(e) {
e.preventDefault();