diff options
author | Henry Castro <hcastro@collabora.com> | 2020-03-12 23:43:15 -0400 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2020-03-18 23:20:27 +0100 |
commit | 1c4a66e736d73ab372745972a3bfcbb611e2de8a (patch) | |
tree | e7476db768871abf776081abcc79741006592640 | |
parent | 569b342c2029876b1c9ef8b54f235138bff9c792 (diff) |
lolealet: fill the font list when data is received
The changes only populate the font list when the data
is received by the client, the other approach iterates
all toolbar items to refresh each one.
Change-Id: I837b52275b49e025fa353dcf088f97c19779bc79
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/90450
Tested-by: Andras Timar <andras.timar@collabora.com>
Reviewed-by: Andras Timar <andras.timar@collabora.com>
-rw-r--r-- | loleaflet/src/control/Control.Toolbar.js | 59 |
1 files changed, 35 insertions, 24 deletions
diff --git a/loleaflet/src/control/Control.Toolbar.js b/loleaflet/src/control/Control.Toolbar.js index ea80836a4..d6e8ce67d 100644 --- a/loleaflet/src/control/Control.Toolbar.js +++ b/loleaflet/src/control/Control.Toolbar.js @@ -2090,6 +2090,39 @@ function onCommandValues(e) { } } +function updateToolbarCommandValues(e) { + if (e.commandName === '.uno:CharFontName') { + // 2) For .uno:CharFontName + var commandValues = map.getToolbarCommandValues(e.commandName); + if (typeof commandValues === 'undefined') { + return; + } + + var data = []; // reset data in order to avoid that the font select box is populated with styles, too. + // Old browsers like IE11 et al don't like Object.keys with + // empty arguments + if (typeof commandValues === 'object') { + data = data.concat(Object.keys(commandValues)); + } + + /* debug messages it will be removed later */ + if (data.length < 3) { + console.log('ALERT!, the server is sending a small font list'); + } + /* debug end*/ + + $('.fonts-select').select2({ + data: data.sort(function (a, b) { // also sort(localely) + return a.localeCompare(b); + }), + placeholder: _('Font') + }); + $('.fonts-select').on('select2:select', onFontSelect); + $('.fonts-select').val(fontsSelectValue).trigger('change'); + w2ui['editbar'].resize(); + } +} + function updateCommandValues(targetName) { var data = []; // 1) For .uno:StyleApply @@ -2162,29 +2195,6 @@ function updateCommandValues(targetName) { $('.styles-select').on('select2:select', onStyleSelect); w2ui['editbar'].resize(); } - - if (targetName === 'fonts' && $('.fonts-select option').length === 1) { - // 2) For .uno:CharFontName - commandValues = map.getToolbarCommandValues('.uno:CharFontName'); - if (typeof commandValues === 'undefined') { - return; - } - data = []; // reset data in order to avoid that the font select box is populated with styles, too. - // Old browsers like IE11 et al don't like Object.keys with - // empty arguments - if (typeof commandValues === 'object') { - data = data.concat(Object.keys(commandValues)); - } - $('.fonts-select').select2({ - data: data.sort(function (a, b) { // also sort(localely) - return a.localeCompare(b); - }), - placeholder: _('Font') - }); - $('.fonts-select').on('select2:select', onFontSelect); - $('.fonts-select').val(fontsSelectValue).trigger('change'); - w2ui['editbar'].resize(); - } } @@ -2683,7 +2693,8 @@ function setupToolbar(e) { if (!window.mode.isMobile()) { - map.on('updatetoolbarcommandvalues', function() { + map.on('updatetoolbarcommandvalues', function(e) { + updateToolbarCommandValues(e); w2ui['editbar'].refresh(); }); |