From 8c02277a48929974d6c7bc0c8cc105401590a7e3 Mon Sep 17 00:00:00 2001 From: Himalini Gururaj Date: Wed, 8 Feb 2023 16:37:40 -0500 Subject: [PATCH 1/5] added session storage saving: --- visualizer.html | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/visualizer.html b/visualizer.html index fa8bda1..ab5dceb 100644 --- a/visualizer.html +++ b/visualizer.html @@ -267,6 +267,18 @@ //themes are available here: https://github.com/ajaxorg/ace/tree/master/lib/ace/theme editor.setTheme("ace/theme/tomorrow"); editor.session.setMode("ace/mode/javascript"); +editor.getSession().on('change', function() { + update() +}); +if (sessionStorage.getItem("autosave")) { + // Restore the contents of the text field + editor.setValue(sessionStorage.getItem("autosave")); +} + +function update() //writes in
with id=output +{ + sessionStorage.setItem("autosave", editor.getValue()); +} var show = document.getElementById('show'); From 1c01fe276f230c5e7c79b39bd8ea53ce3488b098 Mon Sep 17 00:00:00 2001 From: Himalini Gururaj Date: Wed, 8 Feb 2023 16:41:14 -0500 Subject: [PATCH 2/5] cleaned comments and naming --- visualizer.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/visualizer.html b/visualizer.html index ab5dceb..9bf8ee5 100644 --- a/visualizer.html +++ b/visualizer.html @@ -268,14 +268,14 @@ editor.setTheme("ace/theme/tomorrow"); editor.session.setMode("ace/mode/javascript"); editor.getSession().on('change', function() { - update() + saveOnEditorUpdate() }); + if (sessionStorage.getItem("autosave")) { - // Restore the contents of the text field editor.setValue(sessionStorage.getItem("autosave")); } -function update() //writes in
with id=output +function saveOnEditorUpdate() { sessionStorage.setItem("autosave", editor.getValue()); } From 87f4872c5e0bc340a00f0b485614c1221f4dac73 Mon Sep 17 00:00:00 2001 From: Himalini Gururaj Date: Fri, 10 Feb 2023 14:12:04 -0500 Subject: [PATCH 3/5] added url file loading consistency --- visualizer.html | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/visualizer.html b/visualizer.html index 9bf8ee5..d9091b5 100644 --- a/visualizer.html +++ b/visualizer.html @@ -443,13 +443,7 @@ let reload = document.getElementById("reload"); let currentSource = null; //{file:file} or {url:url} or null reload.addEventListener('click', function() { - if (currentSource) { - if (currentSource.file) { - readFile(currentSource.file); - } else if (currentSource.url) { - readURL(currentSource.url); - } - } + location.reload(); }); @@ -601,11 +595,34 @@ }); + +function addURLParam(key, value){ + let params = new URLSearchParams(window.location.search); + params.set(key, value); + const editedURL = window.location.pathname + "?" + params.toString(); + history.pushState(null, "", editedURL); + console.log("hello") + let newParams = new URLSearchParams(window.location.search); + console.log("updated: " + newParams.get("edited")) + + +} { //check for '?load=....' in the URL: - const m = document.location.search.match(/^\?load=(.+)$/); - if (m) { - readURL(m[1]); - } + let params = new URLSearchParams(window.location.search); + let name = params.get("load"); + if (name && !isFileEdited()) { + readURL(name); + addURLParam("edited", "true"); + + } +} + +function isFileEdited(){ + let params = new URLSearchParams(window.location.search); + let edited = params.get("edited"); + console.log("checking url: " + edited); + return edited !== null; + } From 1a170ed4d07b8403e297e89bd4c102582cca1163 Mon Sep 17 00:00:00 2001 From: Himalini Gururaj Date: Mon, 13 Feb 2023 12:15:36 -0500 Subject: [PATCH 4/5] clear url when file loaded --- visualizer.html | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/visualizer.html b/visualizer.html index d9091b5..56cd02a 100644 --- a/visualizer.html +++ b/visualizer.html @@ -586,6 +586,7 @@ file.addEventListener('change', function(evt){ try { readFile(file.files[0]); + deleteParam(); file.value = ""; } catch (e) { console.log(e); @@ -601,11 +602,10 @@ params.set(key, value); const editedURL = window.location.pathname + "?" + params.toString(); history.pushState(null, "", editedURL); - console.log("hello") let newParams = new URLSearchParams(window.location.search); - console.log("updated: " + newParams.get("edited")) - - +} +function deleteParam(){ + window.history.pushState({}, document.title, window.location.pathname); } { //check for '?load=....' in the URL: let params = new URLSearchParams(window.location.search); @@ -620,7 +620,6 @@ function isFileEdited(){ let params = new URLSearchParams(window.location.search); let edited = params.get("edited"); - console.log("checking url: " + edited); return edited !== null; } From ac4f43dadf2ae27bb73d3631325dfa18435459c4 Mon Sep 17 00:00:00 2001 From: Himalini Gururaj Date: Wed, 15 Feb 2023 17:31:25 -0500 Subject: [PATCH 5/5] addressed PR comments --- visualizer.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/visualizer.html b/visualizer.html index 56cd02a..15e4c25 100644 --- a/visualizer.html +++ b/visualizer.html @@ -605,7 +605,7 @@ let newParams = new URLSearchParams(window.location.search); } function deleteParam(){ - window.history.pushState({}, document.title, window.location.pathname); + window.history.pushState(null, "", window.location.pathname); } { //check for '?load=....' in the URL: let params = new URLSearchParams(window.location.search); @@ -613,7 +613,7 @@ if (name && !isFileEdited()) { readURL(name); addURLParam("edited", "true"); - + updateVisualizer(true); } }