[Libreoffice-commits] online.git: loleaflet/src
Samuel Mehrbrodt (via logerrit)
logerrit at kemper.freedesktop.org
Wed Jul 24 05:43:36 UTC 2019
loleaflet/src/control/Control.Toolbar.js | 105 +++++++------------------------
1 file changed, 24 insertions(+), 81 deletions(-)
New commits:
commit 3dd8364056fc0cf5625c44b688e9cbf58e95e90b
Author: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
AuthorDate: Fri Jul 19 16:10:28 2019 +0200
Commit: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
CommitDate: Wed Jul 24 07:43:17 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.meeks at collabora.com>
Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
Tested-by: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
diff --git a/loleaflet/src/control/Control.Toolbar.js b/loleaflet/src/control/Control.Toolbar.js
index 6931c48e2..1e302892b 100644
--- a/loleaflet/src/control/Control.Toolbar.js
+++ b/loleaflet/src/control/Control.Toolbar.js
@@ -673,7 +673,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
@@ -724,7 +723,7 @@ function initNormalToolbar() {
}
}, 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;
@@ -1193,23 +1192,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:')) {
@@ -1227,56 +1209,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();
}
@@ -1573,6 +1513,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) {
@@ -1621,7 +1581,6 @@ function onCommandStateChanged(e) {
value = this.value;
if (value.toLowerCase() === state.toLowerCase()) {
found = true;
- updateFontSizeList(value);
return;
}
});
@@ -1638,21 +1597,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
@@ -1908,20 +1865,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();
- }
}
More information about the Libreoffice-commits
mailing list