loleaflet/js/toolbar.js | 105 ++++++++++-------------------------------------- 1 file changed, 24 insertions(+), 81 deletions(-)
New commits: commit b9e7f06e023a6f3ea60e5985dc25ec188ddf08de Author: Samuel Mehrbrodt <samuel.mehrbr...@cib.de> AuthorDate: Fri Jul 19 16:10:28 2019 +0200 Commit: Aron Budea <aron.bu...@collabora.com> CommitDate: Wed Oct 9 14:40:33 2019 +0200 Font list empty in some cases The list of font sizes was taken from the font info. This causes problems when the document uses a font which is not available on the system. As there is no obvious reason, why the list of font sizes should depend on the font (and update with every font change), remove this dependency and just populate the list of fonts once. If the document uses a font size which is not in the list, it still will be added to the font size list. Change-Id: I4d434244b341c8e782138e5a6df85a50ddad3df5 Reviewed-on: https://gerrit.libreoffice.org/75959 Reviewed-by: Michael Meeks <michael.me...@collabora.com> Reviewed-by: Samuel Mehrbrodt <samuel.mehrbr...@cib.de> Tested-by: Samuel Mehrbrodt <samuel.mehrbr...@cib.de> (cherry picked from commit 3dd8364056fc0cf5625c44b688e9cbf58e95e90b) diff --git a/loleaflet/js/toolbar.js b/loleaflet/js/toolbar.js index b5dc4cfb1..e89092784 100644 --- a/loleaflet/js/toolbar.js +++ b/loleaflet/js/toolbar.js @@ -660,7 +660,6 @@ function hideTooltip(toolbar, id) { var stylesSelectValue; var fontsSelectValue; -var fontsizesSelectValue; // mobile:false means hide it both for normal Online used from a mobile browser, and in a mobile app // mobilebrowser:false means hide it for normal Online used from a mobile browser, but don't hide it in a mobile app @@ -717,7 +716,7 @@ function createToolbar() { } }, mobile: false}, {type: 'html', id: 'fontsizes', - html: '<select class="fontsizes-select"><option>14</option></select>', + html: '<select class="fontsizes-select">', onRefresh: function (edata) { if (!edata.item.html) { edata.isCancelled = true; @@ -1372,23 +1371,6 @@ function onDocumentNameFocus() { map._onLostFocus(); } -function sortFontSizes() { - var oldVal = $('.fontsizes-select').val(); - var selectList = $('.fontsizes-select option'); - selectList.sort(function (a, b) { - a = parseFloat($(a).text() * 1); - b = parseFloat($(b).text() * 1); - if (a > b) { - return 1; - } else if (a < b) { - return -1; - } - return 0; - }); - $('.fontsizes-select').html(selectList); - $('.fontsizes-select').val(oldVal).trigger('change'); -} - function onStyleSelect(e) { var style = e.target.value; if (style.startsWith('.uno:')) { @@ -1406,56 +1388,14 @@ function onStyleSelect(e) { map.focus(); } -function updateFontSizeList(font) { - var oldSize = $('.fontsizes-select').val(); - var found = false; - $('.fontsizes-select').find('option').remove(); - var data = ['']; - data = data.concat(map.getToolbarCommandValues('.uno:CharFontName')[font]); - $('.fontsizes-select').select2({ - data: data, - placeholder: ' ', - //Allow manually entered font size. - createTag: function(query) { - return { - id: query.term, - text: query.term, - tag: true - }; - }, - tags: true - }); - $('.fontsizes-select option').each(function (i, e) { - if ($(e).text() === oldSize) { - $('.fontsizes-select').val(oldSize).trigger('change'); - found = true; - return; - } - }); - if (!found) { - // we need to add the size - $('.fontsizes-select') - .append($('<option></option>') - .text(oldSize)); - } - $('.fontsizes-select').val(oldSize).trigger('change'); - sortFontSizes(); -} - function onFontSelect(e) { var font = e.target.value; - updateFontSizeList(font); map.applyFont(font); map.focus(); } function onFontSizeSelect(e) { - var size = e.target.value; - var command = {}; - $(e.target).find('option[data-select2-tag]').removeAttr('data-select2-tag'); - map.applyFontSize(size); - var fontcolor = map.getDocType() === 'text' ? 'FontColor' : 'Color'; - command[fontcolor] = {}; + map.applyFontSize(e.target.value); map.focus(); } @@ -1760,6 +1700,26 @@ function onDocLayerInit() { if (el) el.resize(); } + + var data = [6, 7, 8, 9, 10, 10.5, 11, 12, 13, 14, 15, 16, 18, 20, + 22, 24, 26, 28, 32, 36, 40, 44, 48, 54, 60, 66, 72, 80, 88, 96]; + $('.fontsizes-select').select2({ + data: data, + placeholder: ' ', + //Allow manually entered font size. + createTag: function(query) { + return { + id: query.term, + text: query.term, + tag: true + }; + }, + tags: true, + sorter: function(data) { return data.sort(function(a, b) { + return parseFloat(a.text) - parseFloat(b.text); + })} + }); + $('.fontsizes-select').on('select2:select', onFontSizeSelect); } function onCommandStateChanged(e) { @@ -1808,7 +1768,6 @@ function onCommandStateChanged(e) { value = this.value; if (value.toLowerCase() === state.toLowerCase()) { found = true; - updateFontSizeList(value); return; } }); @@ -1825,21 +1784,19 @@ function onCommandStateChanged(e) { if (state === '0') { state = ''; } + $('.fontsizes-select option').each(function (i, e) { if ($(e).text() === state) { found = true; - return; } }); if (!found) { // we need to add the size $('.fontsizes-select') - .append($('<option></option>') + .append($('<option>') .text(state).val(state)); } - fontsizesSelectValue = state; $('.fontsizes-select').val(state).trigger('change'); - sortFontSizes(); } else if (commandName === '.uno:FontColor' || commandName === '.uno:Color') { // confusingly, the .uno: command is named differently in Writer, Calc and Impress @@ -2069,20 +2026,6 @@ function updateCommandValues(targetName) { $('.fonts-select').val(fontsSelectValue).trigger('change'); w2ui['editbar'].resize(); } - - if (targetName === 'fontsizes' && $('.fontsizes-select option').length === 1) { - $('.fontsizes-select').select2({ - placeholder: ' ', - data: [] - }); - - $('.fontsizes-select').on('select2:select', onFontSizeSelect); - if (fontsSelectValue) { - updateFontSizeList(fontsSelectValue); - } - $('.fontsizes-select').val(fontsizesSelectValue).trigger('change'); - w2ui['editbar'].resize(); - } } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits