From f1c9874ed077e9880a5362d93bd2c6c054c1ddc1 Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Sun, 18 Sep 2016 16:33:33 +0800 Subject: Update to support save mode to url and parse mode from url --- public/js/index.js | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'public') diff --git a/public/js/index.js b/public/js/index.js index c800cd9d..e192db59 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -195,10 +195,16 @@ var supportExtraTags = [ } ]; var modeType = { - edit: {}, - view: {}, - both: {} -} + edit: { + name: "edit" + }, + view: { + name: "view" + }, + both: { + name: "both" + } +}; var statusType = { connected: { msg: "CONNECTED", @@ -215,7 +221,7 @@ var statusType = { label: "label-danger", fa: "fa-plug" } -} +}; var defaultMode = modeType.view; //global vars @@ -1133,6 +1139,8 @@ function changeMode(type) { ui.area.view.show(); break; } + // save mode to url + if (history.replaceState && loaded) history.replaceState(null, "", serverurl + '/' + noteid + '?' + currentMode.name); if (currentMode == modeType.view) { editor.getInputField().blur(); } @@ -2416,6 +2424,11 @@ socket.on('refresh', function (data) { else currentMode = modeType.both; } + // parse mode from url + if (window.location.search.length > 0) { + var urlMode = modeType[window.location.search.substr(1)]; + if (urlMode) currentMode = urlMode; + } changeMode(currentMode); if (nocontent && !visibleXS) { editor.focus(); -- cgit v1.2.3