From c72bbd4c37d894458006bbf85470fe0b933a5e4c Mon Sep 17 00:00:00 2001 From: yflory Date: Tue, 21 Feb 2017 17:42:58 +0100 Subject: [PATCH] Use the file name as initial title --- www/code/main.js | 5 +++++ www/common/cryptpad-common.js | 21 ++++++++++++--------- www/drive/main.js | 5 ++++- www/pad/main.js | 2 ++ www/poll/main.js | 6 +++++- www/slide/main.js | 5 +++++ 6 files changed, 33 insertions(+), 11 deletions(-) diff --git a/www/code/main.js b/www/code/main.js index 7e44531b4..c74656a66 100644 --- a/www/code/main.js +++ b/www/code/main.js @@ -564,6 +564,11 @@ define([ editor.setValue(newDoc || ''); + if (Cryptpad.initialName && document.title === defaultName) { + updateTitle(Cryptpad.initialName); + onLocal(); + } + if (Visible.isSupported()) { Visible.onChange(function (yes) { if (yes) { unnotify(); } diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 6ca5bb426..c03664036 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -214,15 +214,6 @@ define([ secret.keys = Crypto.createEditCryptor(); secret.key = Crypto.createEditCryptor().editKeyStr; }; - // If we have a hash in the URL specifying a path, it means the document was created from - // the drive and should be stored at the selected path. - if (/[?&]path=/.test(window.location.hash)) { - var patharr = window.location.hash.match(/[?&]path=([^&]+)/); - var namearr = window.location.hash.match(/[?&]name=([^&]+)/); - common.initialPath = patharr[1] || undefined; - common.initialName = namearr && namearr[1] ? decodeURIComponent(namearr[1]) : undefined; - window.location.hash = ''; - } if (!secretHash && !/#/.test(window.location.href)) { generate(); return secret; @@ -698,6 +689,9 @@ define([ }); }; + var newPadNameKey = common.newPadNameKey = "newPadName"; + var newPadPathKey = common.newPadPathKey = "newPadPath"; + // local name? common.ready = function (f) { var state = 0; @@ -708,6 +702,15 @@ define([ f(void 0, env); }; + if (sessionStorage[newPadNameKey]) { + common.initialName = sessionStorage[newPadNameKey]; + delete sessionStorage[newPadNameKey]; + } + if (sessionStorage[newPadPathKey]) { + common.initialPath = sessionStorage[newPadPathKey]; + delete sessionStorage[newPadPathKey]; + } + Store.ready(function (err, storeObj) { store = common.store = env.store = storeObj; diff --git a/www/drive/main.js b/www/drive/main.js index e643c0c6a..1d0b3eade 100644 --- a/www/drive/main.js +++ b/www/drive/main.js @@ -897,8 +897,11 @@ define([ } var onNamed = function (name) { if (!name) { return; } + // TODO var path = '/#?name=' + encodeURIComponent(name) + '&path=' + encodeURIComponent(currentPath); - window.open('/' + type + path); + sessionStorage[Cryptpad.newPadNameKey] = name; + sessionStorage[Cryptpad.newPadPathKey] = currentPath; + window.open('/' + type + '/'); }; Cryptpad.prompt(Messages.fm_nameFile, Cryptpad.getDefaultName({type: type}), onNamed); }; diff --git a/www/pad/main.js b/www/pad/main.js index 01603a7c0..e073ea27a 100644 --- a/www/pad/main.js +++ b/www/pad/main.js @@ -372,6 +372,8 @@ define([ }; if (!initializing) { hjson[3].metadata.title = document.title; + } else if (Cryptpad.initialName) { + hjson[3].metadata.title = Cryptpad.initialName; } return stringify(hjson); }; diff --git a/www/poll/main.js b/www/poll/main.js index e5679a171..ea22d6a76 100644 --- a/www/poll/main.js +++ b/www/poll/main.js @@ -567,7 +567,11 @@ define([ } else { APP.proxy.info.defaultTitle = defaultName; } - updateTitle(APP.proxy.info.title || defaultName); + if (Cryptpad.initialName && !APP.proxy.info.title) { + updateTitle(Cryptpad.initialName); + } else { + updateTitle(APP.proxy.info.title || defaultName); + } // Description var resize = function () { diff --git a/www/slide/main.js b/www/slide/main.js index 0615c76c0..e6931603d 100644 --- a/www/slide/main.js +++ b/www/slide/main.js @@ -638,6 +638,11 @@ define([ editor.setValue(newDoc || ''); Slide.update(newDoc); + if (Cryptpad.initialName && APP.title === defaultName) { + updateTitle(Cryptpad.initialName); + onLocal(); + } + if (Visible.isSupported()) { Visible.onChange(function (yes) { if (yes) { unnotify(); }