Skip to content

Commit

Permalink
Add context-dependant visibility option for toolbar
Browse files Browse the repository at this point in the history
Change-Id: I38abfb5bd55d1766577c12ec274e926701c46200
  • Loading branch information
eszkadev committed Nov 23, 2020
1 parent 476038d commit 95440e3
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions loleaflet/src/control/Control.TopToolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -59,7 +60,7 @@ L.Control.TopToolbar = L.Control.extend({
this.map.focus();
},

_updateVisibilityForToolbar: function(toolbar) {
_updateVisibilityForToolbar: function(toolbar, context) {
if (!toolbar)
return;

Expand All @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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']}
];
},

Expand Down

0 comments on commit 95440e3

Please sign in to comment.