From 456370b1aa33b2304a72bbdc3bcf673fbbf64d8d Mon Sep 17 00:00:00 2001 From: yflory Date: Thu, 21 Sep 2017 17:56:24 +0200 Subject: [PATCH 01/12] Base for Drive in sandboxed iframe --- customize.dist/src/less2/main.less | 3 +- www/code/inner.html | 2 +- www/common/common-interface.js | 4 +- www/common/metadata-manager.js | 1 - www/common/sframe-boot.js | 19 + www/common/sframe-common-file.js | 2 - www/common/sframe-common-interface.js | 101 +- www/common/sframe-common-outer.js | 37 +- www/common/sframe-common.js | 19 + www/common/sframe-protocol.js | 6 + www/common/userObject.js | 8 + www/file/inner.html | 2 +- www/filepicker/inner.html | 2 +- www/newdrive/app-drive.less | 879 +++++++ www/newdrive/file.less | 820 +++++++ www/newdrive/index.html | 38 + www/newdrive/inner.html | 63 + www/newdrive/inner.js | 3014 +++++++++++++++++++++++++ www/newdrive/main.js | 53 + www/pad/inner.html | 2 +- www/slide/inner.html | 2 +- www/whiteboard/inner.html | 2 +- 22 files changed, 5060 insertions(+), 19 deletions(-) create mode 100644 www/newdrive/app-drive.less create mode 100644 www/newdrive/file.less create mode 100644 www/newdrive/index.html create mode 100644 www/newdrive/inner.html create mode 100644 www/newdrive/inner.js create mode 100644 www/newdrive/main.js diff --git a/customize.dist/src/less2/main.less b/customize.dist/src/less2/main.less index 5e0479deb..ed0d0bd0d 100644 --- a/customize.dist/src/less2/main.less +++ b/customize.dist/src/less2/main.less @@ -22,11 +22,12 @@ html.cp-app-print { .app-print_main(); } +body.cp-app-drive { @import "../../../newdrive/app-drive.less"; } body.cp-app-pad { @import "../../../pad/app-pad.less"; } body.cp-app-code { @import "../../../code/app-code.less"; } body.cp-app-slide { @import "../../../slide/app-slide.less"; } body.cp-app-file { @import "../../../file/app-file.less"; } body.cp-app-filepicker { @import "../../../filepicker/app-filepicker.less"; } -body.cp-app-poll { @import "../../../poll/app-poll.less"; } +//body.cp-app-poll { @import "../../../poll/app-poll.less"; } body.cp-app-whiteboard { @import "../../../whiteboard/app-whiteboard.less"; } diff --git a/www/code/inner.html b/www/code/inner.html index 2ac5b56f8..5d914b6c8 100644 --- a/www/code/inner.html +++ b/www/code/inner.html @@ -2,7 +2,7 @@ - + + + + + diff --git a/www/olddrive/inner.html b/www/olddrive/inner.html new file mode 100644 index 000000000..0b26aa7a1 --- /dev/null +++ b/www/olddrive/inner.html @@ -0,0 +1,60 @@ + + + + + + + + +
+
+
+
+
+
+
+
+ + + + + +
+ + + diff --git a/www/olddrive/inner.js b/www/olddrive/inner.js new file mode 100644 index 000000000..e1779778b --- /dev/null +++ b/www/olddrive/inner.js @@ -0,0 +1,7 @@ +define([ + 'less!/bower_components/components-font-awesome/css/font-awesome.min.css', + 'css!/bower_components/bootstrap/dist/css/bootstrap.min.css', + 'less!/drive/file.less', + 'less!/customize/src/less/cryptpad.less', + 'less!/customize/src/less/toolbar.less', +], function () {}); diff --git a/www/newdrive/inner.js b/www/olddrive/main.js similarity index 73% rename from www/newdrive/inner.js rename to www/olddrive/main.js index 9c1072954..d7766b75f 100644 --- a/www/newdrive/inner.js +++ b/www/olddrive/main.js @@ -1,56 +1,44 @@ define([ 'jquery', + '/bower_components/chainpad-listmap/chainpad-listmap.js', '/bower_components/chainpad-crypto/crypto.js', - '/bower_components/textpatcher/TextPatcher.js', - '/common/toolbar3.js', + '/bower_components/textpatcher/TextPatcher.amd.js', 'json.sortify', '/common/cryptpad-common.js', - '/common/common-util.js', - '/common/cryptget.js', - '/bower_components/nthen/index.js', - '/common/sframe-common.js', - '/common/common-realtime.js', '/common/userObject.js', + '/common/toolbar2.js', '/customize/application_config.js', + '/common/cryptget.js', '/common/mergeDrive.js', - '/common/sframe-chainpad-listmap.js', - 'css!/bower_components/bootstrap/dist/css/bootstrap.min.css', 'less!/bower_components/components-font-awesome/css/font-awesome.min.css', - 'less!/customize/src/less2/main.less', -], function ( - $, - Crypto, - TextPatcher, - Toolbar, - JSONSortify, - Cryptpad, - Util, - Cryptget, - nThen, - SFCommon, - CommonRealtime, - FO, - AppConfig, - Merge, - Listmap) -{ + 'less!/customize/src/less/cryptpad.less', +], function ($, Listmap, Crypto, TextPatcher, JSONSortify, Cryptpad, FO, Toolbar, AppConfig, Get, Merge) { + var module = window.MODULE = {}; + var Messages = Cryptpad.Messages; + //var saveAs = window.saveAs; + + // Use `$(function () {});` to make sure the html is loaded before doing anything else + $(function () { + var ifrw = $('#pad-iframe')[0].contentWindow; + + Cryptpad.addLoadingScreen(); + var onConnectError = function () { + Cryptpad.errorLoadingScreen(Messages.websocketError); + }; var APP = window.APP = { editable: false, Cryptpad: Cryptpad, + loggedIn: Cryptpad.isLoggedIn(), mobile: function () { return $('body').width() <= 600; } // Menu and content area are not inline-block anymore for mobiles }; - var stringify = function (obj) { + var stringify = APP.stringify = function (obj) { return JSONSortify(obj); }; - var onConnectError = function () { - Cryptpad.errorLoadingScreen(Messages.websocketError); - }; - var E_OVER_LIMIT = 'E_OVER_LIMIT'; var SEARCH = "search"; @@ -66,11 +54,10 @@ define([ var RECENT = "recent"; var RECENT_NAME = Messages.fm_recentPadsName; - var LS_LAST = "app-drive-lastOpened"; - var LS_OPENED = "app-drive-openedFolders"; - var LS_VIEWMODE = "app-drive-viewMode"; - var LS_SEARCHCURSOR = "app-drive-searchCursor"; - var FOLDER_CONTENT_ID = "cp-app-drive-content-folder"; + var LOCALSTORAGE_LAST = "cryptpad-file-lastOpened"; + var LOCALSTORAGE_OPENED = "cryptpad-file-openedFolders"; + var LOCALSTORAGE_VIEWMODE = "cryptpad-file-viewMode"; + var FOLDER_CONTENT_ID = "folderContent"; var config = {}; var DEBUG = config.DEBUG = true; @@ -82,12 +69,10 @@ define([ }; var log = config.log = Cryptpad.log; - var localStore = window.cryptpadStore; - APP.store = {}; var getLastOpenedFolder = function () { var path; try { - path = APP.store[LS_LAST] ? JSON.parse(APP.store[LS_LAST]) : [ROOT]; + path = localStorage[LOCALSTORAGE_LAST] ? JSON.parse(localStorage[LOCALSTORAGE_LAST]) : [ROOT]; } catch (e) { path = [ROOT]; } @@ -95,75 +80,84 @@ define([ }; var setLastOpenedFolder = function (path) { if (path[0] === SEARCH) { return; } - APP.store[LS_LAST] = JSON.stringify(path); - localStore.put(LS_LAST, JSON.stringify(path)); + localStorage[LOCALSTORAGE_LAST] = JSON.stringify(path); + }; + + var initLocalStorage = function () { + try { + var store = JSON.parse(localStorage[LOCALSTORAGE_OPENED]); + if (!$.isArray(store)) { + localStorage[LOCALSTORAGE_OPENED] = '[]'; + } + } catch (e) { + localStorage[LOCALSTORAGE_OPENED] = '[]'; + } }; var wasFolderOpened = function (path) { - var stored = JSON.parse(APP.store[LS_OPENED] || '[]'); - return stored.indexOf(JSON.stringify(path)) !== -1; + var store = JSON.parse(localStorage[LOCALSTORAGE_OPENED]); + return store.indexOf(JSON.stringify(path)) !== -1; }; var setFolderOpened = function (path, opened) { var s = JSON.stringify(path); - var stored = JSON.parse(APP.store[LS_OPENED] || '[]'); - if (opened && stored.indexOf(s) === -1) { - stored.push(s); + var store = JSON.parse(localStorage[LOCALSTORAGE_OPENED]); + if (opened && store.indexOf(s) === -1) { + store.push(s); } if (!opened) { - var idx = stored.indexOf(s); + var idx = store.indexOf(s); if (idx !== -1) { - stored.splice(idx, 1); + store.splice(idx, 1); } } - APP.store[LS_OPENED] = JSON.stringify(stored); - localStore.put(LS_OPENED, JSON.stringify(stored)); + localStorage[LOCALSTORAGE_OPENED] = JSON.stringify(store); }; var getViewModeClass = function () { - var mode = APP.store[LS_VIEWMODE]; - if (mode === 'list') { return 'cp-app-drive-content-list'; } - return 'cp-app-drive-content-grid'; + var mode = localStorage[LOCALSTORAGE_VIEWMODE]; + if (mode === 'list') { return 'list'; } + return 'grid'; }; var getViewMode = function () { - return APP.store[LS_VIEWMODE] || 'grid'; + return localStorage[LOCALSTORAGE_VIEWMODE] || 'grid'; }; var setViewMode = function (mode) { if (typeof(mode) !== "string") { logError("Incorrect view mode: ", mode); return; } - APP.store[LS_VIEWMODE] = mode; - localStore.put(LS_VIEWMODE, mode); + localStorage[LOCALSTORAGE_VIEWMODE] = mode; }; var setSearchCursor = function () { - var $input = $('#cp-app-drive-tree-search-input'); - APP.store[LS_SEARCHCURSOR] = $input[0].selectionStart; - localStore.put(LS_SEARCHCURSOR, $input[0].selectionStart); + var $input = APP.$iframe.find('#searchInput'); + localStorage.searchCursor = $input[0].selectionStart; }; var getSearchCursor = function () { - return APP.store[LS_SEARCHCURSOR] || 0; + return localStorage.searchCursor || 0; }; +/* var now = function () { + return new Date().getTime(); + }; */ + var setEditable = function (state) { APP.editable = state; if (!state) { - APP.$content.addClass('cp-app-drive-readonly'); - $('[draggable="true"]').attr('draggable', false); + APP.$iframe.find('#content').addClass('readonly'); + APP.$iframe.find('[draggable="true"]').attr('draggable', false); } else { - APP.$content.removeClass('cp-app-drive-readonly'); - $('[draggable="false"]').attr('draggable', true); + APP.$iframe.find('#content').removeClass('readonly'); + APP.$iframe.find('[draggable="false"]').attr('draggable', true); } }; // Icons - var $folderIcon = $('', { - "class": "fa fa-folder cp-app-drive-icon-folder cp-app-drive-content-icon" - }); + var $folderIcon = $('', {"class": "fa fa-folder folder icon"}); //var $folderIcon = $('', {src: "/customize/images/icons/folder.svg", "class": "folder icon"}); var $folderEmptyIcon = $folderIcon.clone(); - var $folderOpenedIcon = $('', {"class": "fa fa-folder-open cp-app-drive-icon-folder"}); + var $folderOpenedIcon = $('', {"class": "fa fa-folder-open folder"}); //var $folderOpenedIcon = $('', {src: "/customize/images/icons/folderOpen.svg", "class": "folder icon"}); var $folderOpenedEmptyIcon = $folderOpenedIcon.clone(); //var $upIcon = $('', {"class": "fa fa-arrow-circle-up"}); @@ -172,8 +166,8 @@ define([ var $recentIcon = $('', {"class": "fa fa-clock-o"}); var $trashIcon = $('', {"class": "fa fa-trash"}); var $trashEmptyIcon = $('', {"class": "fa fa-trash-o"}); - //var $collapseIcon = $('', {"class": "fa fa-minus-square-o cp-app-drive-icon-expcol"}); - var $expandIcon = $('', {"class": "fa fa-plus-square-o cp-app-drive-icon-expcol"}); + //var $collapseIcon = $('', {"class": "fa fa-minus-square-o expcol"}); + var $expandIcon = $('', {"class": "fa fa-plus-square-o expcol"}); var $emptyTrashIcon = $('