From f9db7e588eda3410a171b2771b416e6a6573312a Mon Sep 17 00:00:00 2001 From: yflory Date: Tue, 20 Dec 2016 14:37:29 +0100 Subject: [PATCH 1/3] Fix unused backup in localStorage --- www/file/fileObject.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/www/file/fileObject.js b/www/file/fileObject.js index a254ef635..2a339b9cc 100644 --- a/www/file/fileObject.js +++ b/www/file/fileObject.js @@ -688,9 +688,6 @@ define([ fixFilesData(files[FILES_DATA]); if (JSON.stringify(files) !== before) { - var backup = JSON.parse(localStorage.oldFileSystem); - backup.push(files); - localStorage.oldFileSystem = JSON.stringify(backup); debug("Your file system was corrupted. It has been cleaned so that the pads you visit can be stored safely"); return; } From 4aed58557413a17e5f1dcfe4416728182a1c3afa Mon Sep 17 00:00:00 2001 From: yflory Date: Tue, 20 Dec 2016 14:40:00 +0100 Subject: [PATCH 2/3] Fix style issues in the toolbar --- customize.dist/src/toolbar.less | 41 ++++++++++++++++++++++----------- customize.dist/toolbar.css | 36 ++++++++++++++++++----------- www/common/toolbar.js | 2 +- www/pad/inner.html | 1 + 4 files changed, 52 insertions(+), 28 deletions(-) diff --git a/customize.dist/src/toolbar.less b/customize.dist/src/toolbar.less index 02310285b..7bdd1caae 100644 --- a/customize.dist/src/toolbar.less +++ b/customize.dist/src/toolbar.less @@ -10,15 +10,16 @@ } .toolbar-container { - .cryptpad-lag { - position: relative; - top: -2px; - } font: 12px Arial,Helvetica,Tahoma,Verdana,sans-serif; background: -webkit-linear-gradient(#EEEEEE, #DADADA); /* For Safari 5.1 to 6.0 */ background: -o-linear-gradient(#f5f5f5, #DDDDDD); /* For Opera 11.1 to 12.0 */ background: -moz-linear-gradient(#f5f5f5, #DDDDDD); /* For Firefox 3.6 to 15 */ background: linear-gradient(#f5f5f5, #DDDDDD); /* Standard syntax */ + .cryptpad-toolbar { + select { + box-sizing: border-box; + } + } } .cryptpad-toolbar { @@ -37,6 +38,17 @@ float: right; } + .cryptpad-lag { + vertical-align: top; + height: 16px; + width: 16px; + display: inline-block; + margin: 2px 0px; + padding: 5px; + div { + margin: auto; + } + } div { white-space: normal; &.cryptpad-back { @@ -45,11 +57,6 @@ cursor: pointer; color: #000; } - &.cryptpad-lag { - float: left; - line-height: 26px; - margin: 2px 0px; - } } button, select, .rightside-element { @@ -116,6 +123,11 @@ padding-left: 5px; border: 1px solid #A6A6A6; border-bottom-color: #979797; + vertical-align: top; + box-sizing: content-box; + option { + height: 24px; + } } } @@ -229,6 +241,9 @@ .cryptpad-user { position: absolute; right: 0; + span:not(.cryptpad-lag) { + vertical-align: top; + } @media screen and (max-width: 400px) { top: 3em; } @@ -276,9 +291,11 @@ padding: 5px 0px; margin: 5px 0px; font-size: 16px; + white-space: normal; } } button { + white-space: normal; margin: 2px 0px; } } @@ -295,7 +312,7 @@ //float: right; } .cryptpad-spinner { - float: left; + //float: left; display: inline-block; height: 26px; margin: 2px; @@ -310,10 +327,6 @@ .cryptpad-toolbar-username { } .lag { - display: inline-block; - vertical-align: middle; - padding: 0 !important; - margin: 0 5px !important; height: 15px !important; width: 15px !important; border-radius: 50%; diff --git a/customize.dist/toolbar.css b/customize.dist/toolbar.css index d5f8bbf57..1814fa993 100644 --- a/customize.dist/toolbar.css +++ b/customize.dist/toolbar.css @@ -17,9 +17,8 @@ background: linear-gradient(#f5f5f5, #DDDDDD); /* Standard syntax */ } -.toolbar-container .cryptpad-lag { - position: relative; - top: -2px; +.toolbar-container .cryptpad-toolbar select { + box-sizing: border-box; } .cryptpad-toolbar { box-sizing: border-box; @@ -39,6 +38,17 @@ .cryptpad-toolbar a { float: right; } +.cryptpad-toolbar .cryptpad-lag { + vertical-align: top; + height: 16px; + width: 16px; + display: inline-block; + margin: 2px 0px; + padding: 5px; +} +.cryptpad-toolbar .cryptpad-lag div { + margin: auto; +} .cryptpad-toolbar div { white-space: normal; } @@ -48,11 +58,6 @@ cursor: pointer; color: #000; } -.cryptpad-toolbar div.cryptpad-lag { - float: left; - line-height: 26px; - margin: 2px 0px; -} .cryptpad-toolbar button, .cryptpad-toolbar select, .cryptpad-toolbar .rightside-element { @@ -118,6 +123,11 @@ padding-left: 5px; border: 1px solid #A6A6A6; border-bottom-color: #979797; + vertical-align: top; + box-sizing: content-box; +} +.cryptpad-toolbar select option { + height: 24px; } .cryptpad-toolbar-top { display: block; @@ -234,6 +244,9 @@ position: absolute; right: 0; } +.cryptpad-toolbar-top .cryptpad-user span:not(.cryptpad-lag) { + vertical-align: top; +} @media screen and (max-width: 400px) { .cryptpad-toolbar-top .cryptpad-user { top: 3em; @@ -289,8 +302,10 @@ padding: 5px 0px; margin: 5px 0px; font-size: 16px; + white-space: normal; } .cryptpad-toolbar-leftside .cryptpad-dropdown-container .cryptpad-dropdown button { + white-space: normal; margin: 2px 0px; } .cryptpad-toolbar-leftside button { @@ -303,7 +318,6 @@ text-align: right; } .cryptpad-spinner { - float: left; display: inline-block; height: 26px; margin: 2px; @@ -316,10 +330,6 @@ text-transform: uppercase; } .lag { - display: inline-block; - vertical-align: middle; - padding: 0 !important; - margin: 0 5px !important; height: 15px !important; width: 15px !important; border-radius: 50%; diff --git a/www/common/toolbar.js b/www/common/toolbar.js index c421a31d0..511ee3138 100644 --- a/www/common/toolbar.js +++ b/www/common/toolbar.js @@ -84,7 +84,7 @@ define([ id: uid(), 'class': SPINNER_CLS, }); - $container.append($spinner); + $container.prepend($spinner); return $spinner[0]; }; diff --git a/www/pad/inner.html b/www/pad/inner.html index e8e3d0300..1fc7b0cfe 100644 --- a/www/pad/inner.html +++ b/www/pad/inner.html @@ -15,6 +15,7 @@ } #cke_1_top .cryptpad-toolbar { margin-bottom: 1px; + padding: 0px; } From c359c27997185d33bd2004f5bae42f346a850d7d Mon Sep 17 00:00:00 2001 From: yflory Date: Tue, 20 Dec 2016 17:27:45 +0100 Subject: [PATCH 3/3] Use user object as default store in file manager --- customize.dist/fsStore.js | 11 +++- customize.dist/index.html | 2 +- customize.dist/src/fragments/index.html | 2 +- customize.dist/src/toolbar.less | 1 + customize.dist/toolbar.css | 1 + www/common/cryptpad-common.js | 7 ++- www/file/main.js | 76 ++++++++++++++++--------- 7 files changed, 68 insertions(+), 32 deletions(-) diff --git a/customize.dist/fsStore.js b/customize.dist/fsStore.js index c031cba21..7910a5cf3 100644 --- a/customize.dist/fsStore.js +++ b/customize.dist/fsStore.js @@ -19,6 +19,7 @@ define([ var storeObj; var ready = false; var filesOp; + var exp = {}; var safeSet = function (key, val) { storeObj[key] = val; @@ -85,6 +86,10 @@ define([ cb(); }; + Store.getProxy = function () { + return exp; + }; + var changeHandlers = Store.changeHandlers = []; Store.change = function (f) { @@ -134,7 +139,9 @@ define([ }; var rt = window.rt = Listmap.create(listmapConfig); + exp.proxy = rt.proxy; rt.proxy.on('create', function (info) { + exp.info = info; var realtime = info.realtime; if (!Cryptpad.getUserHash()) { localStorage.FS_hash = Cryptpad.getEditHashFromKeys(info.channel, secret.keys); @@ -170,12 +177,12 @@ define([ }; Store.ready = function (f, Cryptpad) { - if (Cryptpad.parsePadUrl(window.location.href).type === "file") { + /*if (Cryptpad.parsePadUrl(window.location.href).type === "file") { if (typeof(f) === 'function') { f(void 0, Cryptpad.getStore(true)); } return; - } + }*/ if (ready) { if (typeof(f) === 'function') { f(void 0, Store); diff --git a/customize.dist/index.html b/customize.dist/index.html index 025f6c1ea..c9e09fd8a 100644 --- a/customize.dist/index.html +++ b/customize.dist/index.html @@ -80,7 +80,7 @@ --> - +
diff --git a/customize.dist/src/fragments/index.html b/customize.dist/src/fragments/index.html index 8815c91b5..91f33178d 100644 --- a/customize.dist/src/fragments/index.html +++ b/customize.dist/src/fragments/index.html @@ -40,7 +40,7 @@ --> - +
diff --git a/customize.dist/src/toolbar.less b/customize.dist/src/toolbar.less index 7bdd1caae..af45fe057 100644 --- a/customize.dist/src/toolbar.less +++ b/customize.dist/src/toolbar.less @@ -39,6 +39,7 @@ } .cryptpad-lag { + box-sizing: content-box; vertical-align: top; height: 16px; width: 16px; diff --git a/customize.dist/toolbar.css b/customize.dist/toolbar.css index 1814fa993..4d31b6d78 100644 --- a/customize.dist/toolbar.css +++ b/customize.dist/toolbar.css @@ -39,6 +39,7 @@ float: right; } .cryptpad-toolbar .cryptpad-lag { + box-sizing: content-box; vertical-align: top; height: 16px; width: 16px; diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 8ce10d64a..09f44d3d9 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -432,7 +432,9 @@ define([ cb(err, data); }); }; - + var setLSAttribute = common.setLSAttribute = function (attr, value) { + localStorage[attr] = value; + }; // STORAGE var getPadAttribute = common.getPadAttribute = function (attr, cb, legacy) { @@ -445,6 +447,9 @@ define([ cb(err, data); }); }; + var getLSAttribute = common.getLSAttribute = function (attr) { + return localStorage[attr]; + }; // STORAGE diff --git a/www/file/main.js b/www/file/main.js index 79f2aa8fb..73066590a 100644 --- a/www/file/main.js +++ b/www/file/main.js @@ -747,13 +747,13 @@ define([ var $span = $(this); var value; if ($span.hasClass('foldername')) { - value = files[SORT_FOLDER_DESC]; - files[SORT_FOLDER_DESC] = value ? false : true; + value = Cryptpad.getLSAttribute(SORT_FOLDER_DESC); + Cryptpad.setLSAttribute(SORT_FOLDER_DESC, value ? false : true); refresh(); return; } - value = files[SORT_FILE_BY]; - var descValue = files[SORT_FILE_DESC]; + value = Cryptpad.getLSAttribute(SORT_FILE_BY); + var descValue = Cryptpad.getLSAttribute(SORT_FILE_DESC); if ($span.hasClass('filename')) { if (value === '') { descValue = descValue ? false : true; @@ -775,17 +775,17 @@ define([ } }); } - files[SORT_FILE_BY] = value; - files[SORT_FILE_DESC] = descValue; + Cryptpad.setLSAttribute(SORT_FILE_BY, value); + Cryptpad.setLSAttribute(SORT_FILE_DESC, descValue); refresh(); }; var addFolderSortIcon = function ($list) { var $icon = $sortAscIcon.clone(); - if (files[SORT_FOLDER_DESC]) { + if (Cryptpad.getLSAttribute(SORT_FOLDER_DESC)) { $icon = $sortDescIcon.clone(); } - if (typeof(files[SORT_FOLDER_DESC]) !== "undefined") { + if (typeof(Cryptpad.getLSAttribute(SORT_FOLDER_DESC)) !== "undefined") { $list.find('.foldername').prepend($icon); } }; @@ -801,12 +801,12 @@ define([ }; var addFileSortIcon = function ($list) { var $icon = $sortAscIcon.clone(); - if (files[SORT_FILE_DESC]) { + if (Cryptpad.getLSAttribute(SORT_FILE_DESC)) { $icon = $sortDescIcon.clone(); } var classSorted; - if (files[SORT_FILE_BY] === '') { classSorted = 'filename'; } - else if (files[SORT_FILE_BY]) { classSorted = files[SORT_FILE_BY]; } + if (Cryptpad.getLSAttribute(SORT_FILE_BY) === '') { classSorted = 'filename'; } + else if (Cryptpad.getLSAttribute(SORT_FILE_BY)) { classSorted = Cryptpad.getLSAttribute(SORT_FILE_BY); } if (classSorted) { $list.find('.' + classSorted).prepend($icon); } @@ -895,7 +895,7 @@ define([ var $fileHeader = getFileListHeader(false); $container.append($fileHeader); var keys = unsorted; - var sortedFiles = sortElements(false, [UNSORTED], keys, files[SORT_FILE_BY], !files[SORT_FILE_DESC], true); + var sortedFiles = sortElements(false, [UNSORTED], keys, Cryptpad.getLSAttribute(SORT_FILE_BY), !Cryptpad.getLSAttribute(SORT_FILE_DESC), true); sortedFiles.forEach(function (href) { var file = filesOp.getFileData(href); if (!file) { @@ -928,7 +928,7 @@ define([ var $fileHeader = getFileListHeader(false); $container.append($fileHeader); var keys = allfiles; - var sortedFiles = sortElements(false, [FILES_DATA], keys, files[SORT_FILE_BY], !files[SORT_FILE_DESC], false, true); + var sortedFiles = sortElements(false, [FILES_DATA], keys, Cryptpad.getLSAttribute(SORT_FILE_BY), !Cryptpad.getLSAttribute(SORT_FILE_DESC), false, true); sortedFiles.forEach(function (file) { var $icon = $fileIcon.clone(); var $name = $('', { 'class': 'file-element element' }); @@ -969,8 +969,8 @@ define([ }); }); }); - var sortedFolders = sortTrashElements(true, filesList, null, !files[SORT_FOLDER_DESC]); - var sortedFiles = sortTrashElements(false, filesList, files[SORT_FILE_BY], !files[SORT_FILE_DESC]); + var sortedFolders = sortTrashElements(true, filesList, null, !Cryptpad.getLSAttribute(SORT_FOLDER_DESC)); + var sortedFiles = sortTrashElements(false, filesList, Cryptpad.getLSAttribute(SORT_FILE_BY), !Cryptpad.getLSAttribute(SORT_FILE_DESC)); if (filesOp.hasSubfolder(root, true)) { $list.append($folderHeader); } sortedFolders.forEach(function (f) { var $element = createElement([TRASH], f.spath, root, true); @@ -1044,8 +1044,8 @@ define([ if (filesOp.hasSubfolder(root)) { $list.append($folderHeader); } // display sub directories var keys = Object.keys(root); - var sortedFolders = sortElements(true, path, keys, null, !files[SORT_FOLDER_DESC]); - var sortedFiles = sortElements(false, path, keys, files[SORT_FILE_BY], !files[SORT_FILE_DESC]); + var sortedFolders = sortElements(true, path, keys, null, !Cryptpad.getLSAttribute(SORT_FOLDER_DESC)); + var sortedFiles = sortElements(false, path, keys, Cryptpad.getLSAttribute(SORT_FILE_BY), !Cryptpad.getLSAttribute(SORT_FILE_DESC)); sortedFolders.forEach(function (key) { if (filesOp.isFile(root[key])) { return; } var $element = createElement(path, key, root, true); @@ -1436,6 +1436,8 @@ define([ // don't initialize until the store is ready. Cryptpad.ready(function () { + var storeObj = Cryptpad.getStore().getProxy && Cryptpad.getStore().getProxy().proxy ? Cryptpad.getStore().getProxy() : undefined; + Cryptpad.styleAlerts(); if (window.location.hash && window.location.hash === "#iframe") { @@ -1458,8 +1460,13 @@ define([ logging: false }; - var rt = window.rt = module.rt = Listmap.create(listmapConfig); - rt.proxy.on('create', function (info) { + var proxy; + if (storeObj) { proxy = storeObj.proxy; } + else { + var rt = window.rt = module.rt = Listmap.create(listmapConfig); + proxy = rt.proxy; + } + var onCreate = function (info) { var realtime = module.realtime = info.realtime; var editHash = APP.editHash = !readOnly ? Cryptpad.getEditHashFromKeys(info.channel, secret.keys) : undefined; @@ -1505,25 +1512,40 @@ define([ $userBlock.append($backupButton); } - }).on('ready', function () { - module.files = rt.proxy; - if (JSON.stringify(rt.proxy) === '{}') { + }; + var onReady = function () { + module.files = proxy; + if (JSON.stringify(proxy) === '{}') { var store = Cryptpad.getStore(true); store.get(Cryptpad.storageKey, function (err, s) { - rt.proxy[FILES_DATA] = s; + proxy[FILES_DATA] = s; initLocalStorage(); - init(rt.proxy); + init(proxy); }); return; } initLocalStorage(); - init(rt.proxy); + init(proxy); APP.userList.onChange(); - }) - .on('disconnect', function (info) { + }; + var onDisconnect = function (info) { setEditable(false); console.error('err'); Cryptpad.alert(Messages.common_connectionLost); + }; + + if (storeObj) { + onCreate(storeObj.info); + onReady(); + } else { + proxy.on('create', function (info) { + onCreate(info); + }).on('ready', function () { + onReady(); + }); + } + proxy.on('disconnect', function () { + onDisconnect(); }); });