added "tabs"; file upload; saving split state
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 18 Apr 2022 21:09:57 +0000 (21:09 +0000)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 18 Apr 2022 21:09:57 +0000 (21:09 +0000)
static/css/index.css
static/src/index.js
static/src/service-worker.js
static/src/storage.js
templates/index.html

index f6f4c831b63ae2d57c7cd1d4e5e8c2bcd326a5e3..f52cc725800b0003ea3f6988ef9143464f32a2b8 100644 (file)
@@ -4,6 +4,7 @@
     --divider-size: 4px;
     --left-half-width: 70%;
     --top-half-height: 30%;
+    --tab-line-height: 24px;
 }
 
 * {
@@ -111,7 +112,7 @@ select:hover {
 
 #code-result {
     height: 100vh;
-    max-height: calc(100vh - var(--menu-bar-height) - var(--input-bar-height) - var(--top-half-height) - var(--divider-size));  /* subtract the padding */
+    max-height: calc(100vh - var(--menu-bar-height) - var(--input-bar-height) - var(--top-half-height) - var(--divider-size) - var(--tab-line-height));  /* subtract the padding */
 
     background: var(--terminal-background-color); 
     color: var(--terminal-foreground-color);
@@ -166,7 +167,7 @@ select:hover {
 
 #render-target {
     width: 100%;
-    height: var(--top-half-height);
+    height: calc(var(--top-half-height) - var(--tab-line-height));
 }
 
 .jquery-modal.blocker.current {
@@ -246,3 +247,19 @@ select:hover {
 .ace_editor {
     font-family: "mononoki Nerd Font Mono", "mononoki NF", Monaco, Menlo, "Ubuntu Mono", Consolas, source-code-pro, monospace !important;
 }
+
+.tab-line {
+    background: var(--light-background-color);
+    border-bottom: 2px solid var(--dark-background-color);
+    cursor: default;
+    user-select: none;
+}
+
+.tab-line span {
+    background: var(--active-color);
+    border-radius: 8px 8px 0 0;
+    margin-left: 8px;
+    padding: 2px 6px;
+    height: 100%;
+    line-height: var(--tab-line-height);
+}
\ No newline at end of file
index 775b516886153a7469b2825de74a8444850c53f2..e44323cc3e575be9d018470dbd5890378963244d 100644 (file)
@@ -194,6 +194,7 @@ function load_settings() {
     editor_keybind_mode = localStorage["editor_keybind_mode"];
     ui_theme = localStorage["ui_theme"] || ui_theme;
 
+    load_split_sizes();
     change_editor_theme(editor_theme);
     change_keybindings(editor_keybind_mode);
     change_ui_theme(ui_theme);
@@ -281,6 +282,20 @@ async function request_permalink() {
     }
 }
 
+function load_split_sizes() {
+    let $root = $(":root");
+
+    $root.css("--top-half-height", localStorage.getItem("top-half-height"));
+    $root.css("--left-half-width", localStorage.getItem("left-half-width"));
+}
+
+function save_split_sizes() {
+    let $root = $(":root");
+
+    localStorage.setItem("top-half-height", $root.css("--top-half-height"));
+    localStorage.setItem("left-half-width", $root.css("--left-half-width"));
+}
+
 window.onload = () => {
     if ('serviceWorker' in navigator) {
         navigator.serviceWorker.register("/playground/static/src/service-worker.js", {
@@ -300,9 +315,12 @@ window.onload = () => {
 
     make_resizer("horizontal-divider", "--left-half-width", "", (e) => {
         editor.resize(true);
+        save_split_sizes();
     });
 
-    make_resizer("vertical-divider", "", "--top-half-height", null);
+    make_resizer("vertical-divider", "", "--top-half-height", (e) => {
+        save_split_sizes();
+    });
 
     document.getElementById("input-bar").addEventListener("keyup", (ev) => {
         if (ev.keyCode === 13) {
index fcdb3ace620f3b70c81e502fc0af5edc5370f500..c9564c68c38920f2fe35bd8ccd094c83aabe524f 100644 (file)
@@ -1,4 +1,4 @@
-const app_version = 1;
+const app_version = 2;
 
 const cacheName = 'cache-v1';
 const precacheResources = [
index 8edd14f9e6e02370fbe95d5382ee132c541ed4cb..29225dfc00369661378e78d70e9ca42e6fb51fda 100644 (file)
@@ -95,3 +95,18 @@ function prompt_download() {
     download_link.remove();
 }
 
+function prompt_upload() {
+    $("#fileupload").click();
+}
+
+function file_uploaded(ev) {
+    let file = ev.target.files[0];
+
+    let reader = new FileReader();
+    reader.readAsText(file, 'UTF-8');
+    reader.onload = readerEvent => {
+        let code = readerEvent.target.result;
+        let editor = ace.edit('code-editor');
+        editor.setValue(code);
+    }
+}
\ No newline at end of file
index bda2f1d338548c1d5c3a0872426738381304ebd0..f549c85c13750dc17d8debd98b1368d3a67273f2 100644 (file)
@@ -28,7 +28,9 @@
             <button title="Stop" onclick="kill_code()"><i class="fas fa-stop"></i></button>
             <button title="Save" onclick="prompt_save()"><i class="fas fa-save"></i></button>
             <button title="Load" onclick="prompt_load()"><i class="fas fa-folder"></i></button>
+            <button title="Upload" onclick="prompt_upload()"><i class="fas fa-upload"></i></button>
             <button title="Download" onclick="prompt_download()"><i class="fas fa-download"></i></button>
+            <input id="fileupload" style="display:none" type="file" onchange="file_uploaded(event)"/>
             <a title="Settings" href="#settings-modal" rel="modal:open" style="color: var(--foreground-color)"><i class="fas fa fa-gears"></i></a>
 
             <label style="margin-left: 64px" for="examples">Load example:</label>
         </div>
 
         <div class="left-half">
+            <div class="tab-line"><span>Code</span></div>
             <pre id="code-editor" ondragover="handle_dragover(event);" ondrop="handle_drop(event);">{{ code_body }}</pre>
         </div>
 
         <div id="horizontal-divider" class="divider"></div>
 
         <div class="right-half">
+            <div class="tab-line"><span>Canvas</span></div>
             <canvas id="render-target"></canvas>
 
             <div id="vertical-divider" class="divider"></div>
 
+            <div class="tab-line"><span>Output</span></div>
             <pre id="code-result"></pre>
             <input type="textbox" id="input-bar" placeholder="Input" />
             <!--<input type="button" id="input-submit" value="Enter" onclick="submit_input()" /> -->