aboutsummaryrefslogtreecommitdiff
path: root/main.js
diff options
context:
space:
mode:
Diffstat (limited to 'main.js')
-rw-r--r--main.js11
1 files changed, 10 insertions, 1 deletions
diff --git a/main.js b/main.js
index cd64ecb..6eccc24 100644
--- a/main.js
+++ b/main.js
@@ -63,6 +63,7 @@ document.getElementById("open-file").addEventListener("change", e => {
function loadFile(path) {
fetch("./stories/"+path).then(r => r.json()).then(d => {
+ d.readOnly = true;
db.files.put({name:"main",data:(data=d)});
//location.hash = "#/"+data.current;
location.hash = "#/";
@@ -158,6 +159,8 @@ function renderPath() {
const main = document.getElementById("main");
const o = main.cloneNode(false);
+ document.documentElement.classList[data.readOnly?"add":"remove"]("read-only");
+
state.addcount = 0;
if (!path.startsWith("/")) {
if (/^[0-9]+$/.test(path) && data.pages[+path] &&
@@ -167,7 +170,8 @@ function renderPath() {
} else path = "";
} else path = path.slice(1);
state.editing = path.endsWith("edit");
- if (state.editing) path = path.slice(0,-5);
+ if (state.editing) { path = path.slice(0,-5);
+ if (data.readOnly) { state.editing = false; location.hash = "#/"+path; }}
if (!/^[0-9]+(-[0-9]+)*$/.test(path)) path = "";
const pieces = path.split("-");
@@ -292,4 +296,9 @@ document.getElementById("theme").addEventListener("click", () =>
"=1; expires=Fri, 31 Dec 9999 23:59:59 GMT" :
"=; expires=Thu, 01 Jan 1970 00:00:00 GMT"));
+document.getElementById("enable-edit").addEventListener("click", () => {
+ delete data.readOnly; state.path = renderPath(); });
+document.getElementById("disable-edit").addEventListener("click", () => {
+ data.readOnly = true; state.path = renderPath(); });
+
});