From f662036817ba6620fb3a0ca8376905e6fcbfe0a1 Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 17 Sep 2018 15:10:10 +0200 Subject: [PATCH] Change the hash in the address bar when browsing a shared folder --- www/common/sframe-protocol.js | 2 ++ www/drive/inner.js | 9 +++++++-- www/drive/main.js | 8 ++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/www/common/sframe-protocol.js b/www/common/sframe-protocol.js index 7e566b9bb..391cbf96a 100644 --- a/www/common/sframe-protocol.js +++ b/www/common/sframe-protocol.js @@ -223,6 +223,8 @@ define({ // Refresh the drive when the drive has changed ('change' or 'remove' events) 'EV_DRIVE_CHANGE': true, 'EV_DRIVE_REMOVE': true, + // Set shared folder hash in the address bar + 'EV_DRIVE_SET_HASH': true, // Remove an owned pad from the server 'Q_REMOVE_OWNED_CHANNEL': true, diff --git a/www/drive/inner.js b/www/drive/inner.js index 4d718e303..a250ca83a 100644 --- a/www/drive/inner.js +++ b/www/drive/inner.js @@ -1895,8 +1895,8 @@ define([ 'class': 'cp-toolbar-share-button', title: Messages.shareButton }); - var $icon = $sharedIcon.clone().appendTo($shareBlock); - var $text = $('').text(Messages.shareButton).appendTo($shareBlock); + $sharedIcon.clone().appendTo($shareBlock); + $('').text(Messages.shareButton).appendTo($shareBlock); var data = manager.getSharedFolderData(id); var parsed = Hash.parsePadUrl(data.href); if (!parsed || !parsed.hash) { return void console.error("Invalid href: "+data.href); } @@ -2579,7 +2579,12 @@ define([ createNewButton(isInRoot, $toolbar.find('.cp-app-drive-toolbar-leftside')); var sfId = manager.isInSharedFolder(currentPath); if (sfId) { + var sfData = manager.getSharedFolderData(sfId); + var parsed = Hash.parsePadUrl(sfData.href); + sframeChan.event('EV_DRIVE_SET_HASH', parsed.hash || ''); createShareButton(sfId, $toolbar.find('.cp-app-drive-toolbar-leftside')); + } else { + sframeChan.event('EV_DRIVE_SET_HASH', ''); } createTitle($toolbar.find('.cp-app-drive-path'), path); diff --git a/www/drive/main.js b/www/drive/main.js index 7395b163a..2ace94441 100644 --- a/www/drive/main.js +++ b/www/drive/main.js @@ -87,6 +87,14 @@ define([ cb(obj); }); }); + sframeChan.on('EV_DRIVE_SET_HASH', function (hash) { + // Update the hash in the address bar + var ohc = window.onhashchange; + window.onhashchange = function () {}; + window.location.hash = hash || ''; + window.onhashchange = ohc; + ohc({reset:true}); + }); Cryptpad.onNetworkDisconnect.reg(function () { sframeChan.event('EV_NETWORK_DISCONNECT'); });