From 95440e3e9de57aae49fe3fda225b6f700dcd1794 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20K=C5=82os?= Date: Mon, 23 Nov 2020 15:16:43 +0100 Subject: [PATCH] Add context-dependant visibility option for toolbar Change-Id: I38abfb5bd55d1766577c12ec274e926701c46200 --- loleaflet/src/control/Control.TopToolbar.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/loleaflet/src/control/Control.TopToolbar.js b/loleaflet/src/control/Control.TopToolbar.js index a7972471f9ce..24b7803ec521 100644 --- a/loleaflet/src/control/Control.TopToolbar.js +++ b/loleaflet/src/control/Control.TopToolbar.js @@ -18,6 +18,7 @@ L.Control.TopToolbar = L.Control.extend({ map.on('updatepermission', this.onUpdatePermission, this); map.on('wopiprops', this.onWopiProps, this); map.on('commandstatechanged', this.onCommandStateChanged, this); + map.on('contextchange', this.onContextChange, this); if (!window.mode.isMobile()) { map.on('updatetoolbarcommandvalues', this.updateCommandValues, this); @@ -59,7 +60,7 @@ L.Control.TopToolbar = L.Control.extend({ this.map.focus(); }, - _updateVisibilityForToolbar: function(toolbar) { + _updateVisibilityForToolbar: function(toolbar, context) { if (!toolbar) return; @@ -76,6 +77,15 @@ L.Control.TopToolbar = L.Control.extend({ else if (((window.mode.isMobile() && item.mobile === true) || (window.mode.isTablet() && item.tablet === true) || (window.mode.isDesktop() && item.desktop === true) || (window.ThisIsAMobileApp && item.mobilebrowser === true)) && item.hidden) { toShow.push(item.id); } + + if (context && item.context) { + if (item.context.indexOf(context) >= 0) + toShow.push(item.id); + else + toHide.push(item.id); + } else if (!context && item.context) { + toHide.push(item.id); + } }); console.log('explicitly hiding: ' + toHide); @@ -85,6 +95,10 @@ L.Control.TopToolbar = L.Control.extend({ toShow.forEach(function(item) { toolbar.show(item); }); }, + onContextChange: function(event) { + this._updateVisibilityForToolbar(w2ui['editbar'], event.context); + }, + // mobile:false means hide it both for normal Online used from a mobile phone browser, and in a mobile app on a mobile phone // mobilebrowser:false means hide it for normal Online used from a mobile browser, but don't hide it in a mobile app // tablet:true means show it in normal Online from a tablet browser, and in a mobile app on a tablet @@ -227,7 +241,8 @@ L.Control.TopToolbar = L.Control.extend({ {type: 'break', id: 'breaksidebar', hidden: true}, {type: 'button', id: 'fold', img: 'fold', desktop: true, mobile: false, hidden: true}, {type: 'button', id: 'hamburger-tablet', img: 'hamburger', desktop: false, mobile: false, tablet: true, iosapptablet: false, hidden: true}, - {type: 'button', id: 'languagecode', desktop: false, mobile: true, tablet: false} + {type: 'button', id: 'languagecode', desktop: false, mobile: true, tablet: false}, + {type: 'button', id: 'contextbutton', img: 'basicshapes_ellipse', context: ['Table']} ]; },