Skip to content

Commit abcf3dc

Browse files
committed
Localstorage
1 parent 8ed9e99 commit abcf3dc

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

examples/calibration-editor/calibration-editor.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,22 @@ const exampleCalibrationJSON = `
2121

2222
function CalibrationInput(
2323
onCompleted,
24-
initialCalibrationJSON = exampleCalibrationJSON,
24+
initialCalibrationJSON = null
2525
) {
26+
let initialJSON;
27+
28+
if (initialCalibrationJSON == null) {
29+
let persistedJSON = localStorage.getItem("calibration-v1");
30+
31+
if (persistedJSON == null) {
32+
initialJSON = exampleCalibrationJSON;
33+
} else {
34+
initialJSON = persistedJSON;
35+
}
36+
} else {
37+
initialJSON = initialCalibrationJSON;
38+
}
39+
2640
let popupDiv = document.createElement("div");
2741

2842
popupDiv.style = `
@@ -62,7 +76,7 @@ function CalibrationInput(
6276
editor.rows = 20;
6377
editor.cols = 80;
6478
editor.spellcheck = false;
65-
editor.value = initialCalibrationJSON;
79+
editor.value = initialJSON;
6680

6781
function validateCalibration() {
6882
const maybeJson = editor.value;
@@ -78,7 +92,9 @@ function CalibrationInput(
7892
link.innerText = "Click here to continue...";
7993
link.href = "#";
8094
link.style.color = "#EFEFEF";
95+
8196
link.onclick = function() {
97+
localStorage.setItem("calibration-v1", maybeJson);
8298
onCompleted(popupDiv, calibration);
8399
return false;
84100
}

0 commit comments

Comments
 (0)