[Libreoffice-commits] online.git: 3 commits - loleaflet/src

Szymon Kłos (via logerrit) logerrit at kemper.freedesktop.org
Fri Oct 11 18:32:42 UTC 2019


 loleaflet/src/control/Control.Toolbar.js     |    2 
 loleaflet/src/layer/AnnotationManager.js     |    4 +
 loleaflet/src/layer/tile/CalcTileLayer.js    |   34 +++++++++-------
 loleaflet/src/layer/tile/ImpressTileLayer.js |   24 +++++++----
 loleaflet/src/layer/tile/TileLayer.js        |   55 +++++++++++++++++++++++++++
 loleaflet/src/layer/tile/WriterTileLayer.js  |    4 +
 6 files changed, 98 insertions(+), 25 deletions(-)

New commits:
commit 2d5874a19ef3d42f7a9f24edc1742e8327b53d8c
Author:     Szymon Kłos <szymon.klos at collabora.com>
AuthorDate: Tue Jul 2 14:09:10 2019 +0200
Commit:     Michael Meeks <michael.meeks at collabora.com>
CommitDate: Fri Oct 11 19:32:20 2019 +0100

    Use vex for annotations in all mobile apps
    
    Change-Id: I29194c0322c5258f9e074af4f3b3985470496300

diff --git a/loleaflet/src/layer/AnnotationManager.js b/loleaflet/src/layer/AnnotationManager.js
index 54336b041..c4b5a955d 100644
--- a/loleaflet/src/layer/AnnotationManager.js
+++ b/loleaflet/src/layer/AnnotationManager.js
@@ -846,7 +846,9 @@ L.AnnotationManager = L.Class.extend({
 				}
 			};
 			this._map.sendUnoCommand('.uno:InsertAnnotation', comment);
-			this._map.removeLayer(this.removeItem(e.annotation._data.id));
+			var item = this.removeItem(e.annotation._data.id);
+			if (item)
+				this._map.removeLayer(item);
 		} else if (e.annotation._data.trackchange) {
 			comment = {
 				ChangeTrackingId: {
diff --git a/loleaflet/src/layer/tile/CalcTileLayer.js b/loleaflet/src/layer/tile/CalcTileLayer.js
index 25ca2f478..837dd79eb 100644
--- a/loleaflet/src/layer/tile/CalcTileLayer.js
+++ b/loleaflet/src/layer/tile/CalcTileLayer.js
@@ -14,22 +14,27 @@ L.CalcTileLayer = L.TileLayer.extend({
 	},
 
 	newAnnotation: function (comment) {
-		var annotations = this._annotations[this._selectedPart];
-		var annotation;
-		for (var key in annotations) {
-			if (this._cellCursor.contains(annotations[key]._annotation._data.cellPos)) {
-				annotation = annotations[key];
-				break;
+		if (window.mode.isMobile()) {
+			var that = this;
+			this.newAnnotationVex(comment, function(annotation) { that._onAnnotationSave(annotation); });
+		} else {
+			var annotations = this._annotations[this._selectedPart];
+			var annotation;
+			for (var key in annotations) {
+				if (this._cellCursor.contains(annotations[key]._annotation._data.cellPos)) {
+					annotation = annotations[key];
+					break;
+				}
 			}
-		}
 
-		if (!annotation) {
-			comment.cellPos = this._cellCursor;
-			annotation = this.createAnnotation(comment);
-			annotation._annotation._tag = annotation;
-			this.showAnnotation(annotation);
+			if (!annotation) {
+				comment.cellPos = this._cellCursor;
+				annotation = this.createAnnotation(comment);
+				annotation._annotation._tag = annotation;
+				this.showAnnotation(annotation);
+			}
+			annotation.editAnnotation();
 		}
-		annotation.editAnnotation();
 	},
 
 	createAnnotation: function (comment) {
@@ -277,7 +282,8 @@ L.CalcTileLayer = L.TileLayer.extend({
 	},
 
 	hideAnnotation: function (annotation) {
-		this._map.removeLayer(annotation);
+		if (annotation)
+			this._map.removeLayer(annotation);
 	},
 
 	showAnnotations: function () {
diff --git a/loleaflet/src/layer/tile/ImpressTileLayer.js b/loleaflet/src/layer/tile/ImpressTileLayer.js
index baa6c13f3..88b8b8fe6 100644
--- a/loleaflet/src/layer/tile/ImpressTileLayer.js
+++ b/loleaflet/src/layer/tile/ImpressTileLayer.js
@@ -23,56 +23,7 @@ L.ImpressTileLayer = L.TileLayer.extend({
 		this.onAnnotationCancel();
 
 		if (window.mode.isMobile()) {
-			var that = this;
-
-			var dialog = vex.dialog.open({
-				message: '',
-				input: [
-					'<textarea name="comment" content="' + comment.text + '" class="loleaflet-annotation-textarea" style="max-width: 400px" required />'
-				].join(''),
-				buttons: [
-					$.extend({}, vex.dialog.buttons.YES, { text: _('Save') }),
-					$.extend({}, vex.dialog.buttons.NO, { text: _('Cancel') })
-				],
-				callback: function (data) {
-					if (data) {
-						that._draft = L.annotation(L.latLng(0, 0), comment, {noMenu: true}).addTo(that._map);
-						that._draft._data.text = data.comment;
-						that.onAnnotationSave();
-					}
-				}
-			});
-
-			var tagTd = 'td',
-			empty = '',
-			tagDiv = 'div';
-			this._author = L.DomUtil.create('table', 'loleaflet-annotation-table');
-			var tbody = L.DomUtil.create('tbody', empty, this._author);
-			var tr = L.DomUtil.create('tr', empty, tbody);
-			var tdImg = L.DomUtil.create(tagTd, 'loleaflet-annotation-img', tr);
-			var tdAuthor = L.DomUtil.create(tagTd, 'loleaflet-annotation-author', tr);
-			var imgAuthor = L.DomUtil.create('img', 'avatar-img', tdImg);
-			imgAuthor.setAttribute('src', L.Icon.Default.imagePath + '/user.png');
-			imgAuthor.setAttribute('width', 32);
-			imgAuthor.setAttribute('height', 32);
-			this._authorAvatarImg = imgAuthor;
-			this._contentAuthor = L.DomUtil.create(tagDiv, 'loleaflet-annotation-content-author', tdAuthor);
-			this._contentDate = L.DomUtil.create(tagDiv, 'loleaflet-annotation-date', tdAuthor);
-
-			$(this._nodeModifyText).text(comment.text);
-			$(this._contentAuthor).text(comment.author);
-			$(this._authorAvatarImg).attr('src', comment.avatar);
-			var user = this._map.getViewId(comment.author);
-			if (user >= 0) {
-				var color = L.LOUtil.rgbToHex(this._map.getViewColor(user));
-				$(this._authorAvatarImg).css('border-color', color);
-			}
-
-			var d = new Date(comment.dateTime.replace(/,.*/, 'Z'));
-			var dateOptions = { weekday: 'short', year: 'numeric', month: 'short', day: 'numeric' };
-			$(this._contentDate).text((isNaN(d.getTime()) || this._map.getDocType() === 'spreadsheet')? comment.dateTime: d.toLocaleDateString(String.locale, dateOptions));
-
-			dialog.get(0).insertBefore(this._author, dialog.get(0).childNodes[0]);
+			this.newAnnotationVex(comment, this.onAnnotationSave);
 		} else {
 			this._draft = L.annotation(L.latLng(0, 0), comment, {noMenu: true}).addTo(this._map);
 			this._draft.edit();
diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index ec5a74c98..97ad079bf 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -6,6 +6,7 @@
 // Implement String::startsWith which is non-portable (Firefox only, it seems)
 // See http://stackoverflow.com/questions/646628/how-to-check-if-a-string-startswith-another-string#4579228
 
+/* global vex $ L _ */
 /*eslint no-extend-native:0*/
 if (typeof String.prototype.startsWith !== 'function') {
 	String.prototype.startsWith = function (str) {
@@ -352,6 +353,60 @@ L.TileLayer = L.GridLayer.extend({
 		return newEvent;
 	},
 
+	newAnnotationVex: function(comment, addCommentFn) {
+		var that = this;
+
+		var dialog = vex.dialog.open({
+			message: '',
+			input: [
+				'<textarea name="comment" content="' + comment.text + '" class="loleaflet-annotation-textarea" style="max-width: 400px" required />'
+			].join(''),
+			buttons: [
+				$.extend({}, vex.dialog.buttons.YES, { text: _('Save') }),
+				$.extend({}, vex.dialog.buttons.NO, { text: _('Cancel') })
+			],
+			callback: function (data) {
+				if (data) {
+					that._draft = L.annotation(L.latLng(0, 0), comment, {noMenu: true}).addTo(that._map);
+					that._draft._data.text = data.comment;
+					comment.text = data.comment;
+					addCommentFn.call(that, {annotation: that._draft}, comment);
+				}
+			}
+		});
+
+		var tagTd = 'td',
+		empty = '',
+		tagDiv = 'div';
+		this._author = L.DomUtil.create('table', 'loleaflet-annotation-table');
+		var tbody = L.DomUtil.create('tbody', empty, this._author);
+		var tr = L.DomUtil.create('tr', empty, tbody);
+		var tdImg = L.DomUtil.create(tagTd, 'loleaflet-annotation-img', tr);
+		var tdAuthor = L.DomUtil.create(tagTd, 'loleaflet-annotation-author', tr);
+		var imgAuthor = L.DomUtil.create('img', 'avatar-img', tdImg);
+		imgAuthor.setAttribute('src', L.Icon.Default.imagePath + '/user.png');
+		imgAuthor.setAttribute('width', 32);
+		imgAuthor.setAttribute('height', 32);
+		this._authorAvatarImg = imgAuthor;
+		this._contentAuthor = L.DomUtil.create(tagDiv, 'loleaflet-annotation-content-author', tdAuthor);
+		this._contentDate = L.DomUtil.create(tagDiv, 'loleaflet-annotation-date', tdAuthor);
+
+		$(this._nodeModifyText).text(comment.text);
+		$(this._contentAuthor).text(comment.author);
+		$(this._authorAvatarImg).attr('src', comment.avatar);
+		var user = this._map.getViewId(comment.author);
+		if (user >= 0) {
+			var color = L.LOUtil.rgbToHex(this._map.getViewColor(user));
+			$(this._authorAvatarImg).css('border-color', color);
+		}
+
+		var d = new Date(comment.dateTime.replace(/,.*/, 'Z'));
+		var dateOptions = { weekday: 'short', year: 'numeric', month: 'short', day: 'numeric' };
+		$(this._contentDate).text((isNaN(d.getTime()) || this._map.getDocType() === 'spreadsheet')? comment.dateTime: d.toLocaleDateString(String.locale, dateOptions));
+
+		dialog.get(0).insertBefore(this._author, dialog.get(0).childNodes[0]);
+	},
+
 	clearAnnotations: function() {
 		console.debug('Implemented in child  classes');
 	},
diff --git a/loleaflet/src/layer/tile/WriterTileLayer.js b/loleaflet/src/layer/tile/WriterTileLayer.js
index ffc1cee12..2b50e443c 100644
--- a/loleaflet/src/layer/tile/WriterTileLayer.js
+++ b/loleaflet/src/layer/tile/WriterTileLayer.js
@@ -21,6 +21,10 @@ L.WriterTileLayer = L.TileLayer.extend({
 		if (comment.anchorPos) {
 			this._annotations.modify(this._annotations.add(comment));
 		}
+		if (window.mode.isMobile()) {
+			var that = this;
+			this.newAnnotationVex(comment, function(annotation) { that._annotations._onAnnotationSave(annotation); });
+		}
 	},
 
 	clearAnnotations: function() {
commit dbdfd19d1926087ba130f0e3382b58b60b99a1b6
Author:     Szymon Kłos <szymon.klos at collabora.com>
AuthorDate: Tue Jul 2 13:18:24 2019 +0200
Commit:     Michael Meeks <michael.meeks at collabora.com>
CommitDate: Fri Oct 11 19:32:20 2019 +0100

    Fix mobile detection in Impress
    
    Before we used css based screen width detection.
    Delete condition which is not working in Impress,
    use explicit JS check added before.
    
    Change-Id: I06819391bd470fd2185bc64318afbe5d9614f0a8

diff --git a/loleaflet/src/control/Control.Toolbar.js b/loleaflet/src/control/Control.Toolbar.js
index 7521180db..19bdacc8a 100644
--- a/loleaflet/src/control/Control.Toolbar.js
+++ b/loleaflet/src/control/Control.Toolbar.js
@@ -11,7 +11,7 @@ var map;
 
 // has to match small screen size requirement
 function _inMobileMode() {
-	return L.Browser.mobile && $('#main-menu').css('display') === 'none';
+	return L.Browser.mobile && screen.width < 768;
 }
 
 // mobile device with big screen size
commit c8962910a537b3005198909d6934cac093811043
Author:     Szymon Kłos <szymon.klos at collabora.com>
AuthorDate: Tue Jul 2 11:23:31 2019 +0200
Commit:     Michael Meeks <michael.meeks at collabora.com>
CommitDate: Fri Oct 11 19:32:20 2019 +0100

    Use vex dialog on mobile when inserting a comment
    
    Change-Id: Ibe089c810edba7696fd6e707e4a757ee83fdf99d

diff --git a/loleaflet/src/layer/tile/ImpressTileLayer.js b/loleaflet/src/layer/tile/ImpressTileLayer.js
index 9e77dc1ee..baa6c13f3 100644
--- a/loleaflet/src/layer/tile/ImpressTileLayer.js
+++ b/loleaflet/src/layer/tile/ImpressTileLayer.js
@@ -3,7 +3,8 @@
  * Impress tile layer is used to display a presentation document
  */
 
-/* global $ _ w2ui w2utils _UNO */
+/* global $ _ w2ui w2utils _UNO L */
+
 L.ImpressTileLayer = L.TileLayer.extend({
 	extraSize: L.point(290, 0),
 
@@ -20,14 +21,68 @@ L.ImpressTileLayer = L.TileLayer.extend({
 			return;
 		}
 		this.onAnnotationCancel();
-		this._draft = L.annotation(L.latLng(0, 0), comment, {noMenu: true}).addTo(this._map);
-		this._draft.edit();
-		var mapCenter = this._map.latLngToLayerPoint(this._map.getCenter());
-		var bounds = this._draft.getBounds();
-		var topLeft = mapCenter.subtract(L.point(bounds.max.x - bounds.min.x, (bounds.max.y - bounds.min.y)/2));
-		this._draft.setLatLng(this._map.layerPointToLatLng(topLeft));
-		this.layoutAnnotations();
-		this._draft.focus();
+
+		if (window.mode.isMobile()) {
+			var that = this;
+
+			var dialog = vex.dialog.open({
+				message: '',
+				input: [
+					'<textarea name="comment" content="' + comment.text + '" class="loleaflet-annotation-textarea" style="max-width: 400px" required />'
+				].join(''),
+				buttons: [
+					$.extend({}, vex.dialog.buttons.YES, { text: _('Save') }),
+					$.extend({}, vex.dialog.buttons.NO, { text: _('Cancel') })
+				],
+				callback: function (data) {
+					if (data) {
+						that._draft = L.annotation(L.latLng(0, 0), comment, {noMenu: true}).addTo(that._map);
+						that._draft._data.text = data.comment;
+						that.onAnnotationSave();
+					}
+				}
+			});
+
+			var tagTd = 'td',
+			empty = '',
+			tagDiv = 'div';
+			this._author = L.DomUtil.create('table', 'loleaflet-annotation-table');
+			var tbody = L.DomUtil.create('tbody', empty, this._author);
+			var tr = L.DomUtil.create('tr', empty, tbody);
+			var tdImg = L.DomUtil.create(tagTd, 'loleaflet-annotation-img', tr);
+			var tdAuthor = L.DomUtil.create(tagTd, 'loleaflet-annotation-author', tr);
+			var imgAuthor = L.DomUtil.create('img', 'avatar-img', tdImg);
+			imgAuthor.setAttribute('src', L.Icon.Default.imagePath + '/user.png');
+			imgAuthor.setAttribute('width', 32);
+			imgAuthor.setAttribute('height', 32);
+			this._authorAvatarImg = imgAuthor;
+			this._contentAuthor = L.DomUtil.create(tagDiv, 'loleaflet-annotation-content-author', tdAuthor);
+			this._contentDate = L.DomUtil.create(tagDiv, 'loleaflet-annotation-date', tdAuthor);
+
+			$(this._nodeModifyText).text(comment.text);
+			$(this._contentAuthor).text(comment.author);
+			$(this._authorAvatarImg).attr('src', comment.avatar);
+			var user = this._map.getViewId(comment.author);
+			if (user >= 0) {
+				var color = L.LOUtil.rgbToHex(this._map.getViewColor(user));
+				$(this._authorAvatarImg).css('border-color', color);
+			}
+
+			var d = new Date(comment.dateTime.replace(/,.*/, 'Z'));
+			var dateOptions = { weekday: 'short', year: 'numeric', month: 'short', day: 'numeric' };
+			$(this._contentDate).text((isNaN(d.getTime()) || this._map.getDocType() === 'spreadsheet')? comment.dateTime: d.toLocaleDateString(String.locale, dateOptions));
+
+			dialog.get(0).insertBefore(this._author, dialog.get(0).childNodes[0]);
+		} else {
+			this._draft = L.annotation(L.latLng(0, 0), comment, {noMenu: true}).addTo(this._map);
+			this._draft.edit();
+			var mapCenter = this._map.latLngToLayerPoint(this._map.getCenter());
+			var bounds = this._draft.getBounds();
+			var topLeft = mapCenter.subtract(L.point(bounds.max.x - bounds.min.x, (bounds.max.y - bounds.min.y)/2));
+			this._draft.setLatLng(this._map.layerPointToLatLng(topLeft));
+			this.layoutAnnotations();
+			this._draft.focus();
+		}
 	},
 
 	beforeAdd: function (map) {


More information about the Libreoffice-commits mailing list