[Libreoffice-commits] online.git: Branch 'distro/collabora/collabora-online-4' - loleaflet/js

Samuel Mehrbrodt (via logerrit) logerrit at kemper.freedesktop.org
Wed Oct 9 13:35:33 UTC 2019


 loleaflet/js/toolbar.js |  105 ++++++++++--------------------------------------
 1 file changed, 24 insertions(+), 81 deletions(-)

New commits:
commit 1b91eef0b2f017c0447e25498e99c1335dcebe3f
Author:     Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
AuthorDate: Fri Jul 19 16:10:28 2019 +0200
Commit:     Aron Budea <aron.budea at collabora.com>
CommitDate: Wed Oct 9 15:34:07 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>
    (cherry picked from commit 3dd8364056fc0cf5625c44b688e9cbf58e95e90b)

diff --git a/loleaflet/js/toolbar.js b/loleaflet/js/toolbar.js
index f243d4368..091120da7 100644
--- a/loleaflet/js/toolbar.js
+++ b/loleaflet/js/toolbar.js
@@ -664,7 +664,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
@@ -721,7 +720,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;
@@ -1379,23 +1378,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:')) {
@@ -1413,56 +1395,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();
 }
 
@@ -1768,6 +1708,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').off('select2:select', onFontSizeSelect).on('select2:select', onFontSizeSelect);
 }
 
 function onCommandStateChanged(e) {
@@ -1816,7 +1776,6 @@ function onCommandStateChanged(e) {
 			value = this.value;
 			if (value.toLowerCase() === state.toLowerCase()) {
 				found = true;
-				updateFontSizeList(value);
 				return;
 			}
 		});
@@ -1833,21 +1792,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
@@ -2077,20 +2034,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').off('select2:select', onFontSizeSelect).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