[Libreoffice-commits] online.git: loleaflet/dist loleaflet/src
Pranav Kant
pranavk at collabora.co.uk
Thu Oct 20 11:58:48 UTC 2016
loleaflet/dist/toolbar/toolbar.js | 17 ++++++++-
loleaflet/src/layer/marker/Cursor.js | 10 +++++
loleaflet/src/layer/tile/TileLayer.js | 60 +++++++++++++++++++++++++++++++++-
3 files changed, 84 insertions(+), 3 deletions(-)
New commits:
commit 49f4e696e517b5f278aab465eebccaae9d8cc675
Author: Pranav Kant <pranavk at collabora.co.uk>
Date: Thu Oct 20 17:21:50 2016 +0530
loleaflet: Click user item to go to its cursor
Change-Id: Iac87da20cfe422000eb9a32ccad50e8483637616
diff --git a/loleaflet/dist/toolbar/toolbar.js b/loleaflet/dist/toolbar/toolbar.js
index dc2b8b5..366e3ec 100644
--- a/loleaflet/dist/toolbar/toolbar.js
+++ b/loleaflet/dist/toolbar/toolbar.js
@@ -1308,11 +1308,24 @@ map.on('statusindicator', function (e) {
}
});
+function onUseritemClicked(e) {
+ var viewId = parseInt(e.currentTarget.id.replace('user-', ''));
+
+ if (map._docLayer) {
+ if (map.getDocType() === 'spreadsheet') {
+ map._docLayer.goToCellViewCursor(viewId);
+ } else if (map.getDocType() === 'text') {
+ map._docLayer.goToViewCursor(viewId);
+ }
+ }
+}
+
function getUserItem(viewId, userName, color) {
- var html = '<tr class="useritem" id="user-' + viewId + '">' +
+ var html = '<tr class="useritem" id="user-' + viewId + '" onclick="onUseritemClicked(event)">' +
'<td class=usercolor style="background-color: ' + color +';"></td>' +
'<td class="username loleaflet-font">' + userName + '</td>' +
- '</tr>';
+ '</tr>';
+
return html;
}
var nUsers = _('%n users');
diff --git a/loleaflet/src/layer/marker/Cursor.js b/loleaflet/src/layer/marker/Cursor.js
index 1335e8e..0a5e622 100644
--- a/loleaflet/src/layer/marker/Cursor.js
+++ b/loleaflet/src/layer/marker/Cursor.js
@@ -64,6 +64,16 @@ L.Cursor = L.Layer.extend({
}
},
+ showCursorHeader: function() {
+ if (this._cursorHeader) {
+ L.DomUtil.setStyle(this._cursorHeader, 'visibility', 'visible');
+
+ setTimeout(L.bind(function() {
+ L.DomUtil.setStyle(this._cursorHeader, 'visibility', 'hidden');
+ }, this), this.options.headerTimeout);
+ }
+ },
+
_initLayout: function () {
this._container = L.DomUtil.create('div', 'leaflet-cursor-container');
if (this.options.header) {
diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index d8836d5..8eeb44f 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -701,6 +701,43 @@ L.TileLayer = L.GridLayer.extend({
}
},
+ goToCellViewCursor: function(viewId) {
+ if (this._cellViewCursors[viewId] && !this._isEmptyRectangle(this._cellViewCursors[viewId].bounds)) {
+ if (!this._map.getBounds().contains(this._cellViewCursors[viewId].bounds)) {
+ var mapBounds = this._map.getBounds();
+ var scrollX = 0;
+ var scrollY = 0;
+ var spacingX = Math.abs(this._cellViewCursors[viewId].bounds.getEast() - this._cellViewCursors[viewId].bounds.getWest()) / 4.0;
+ var spacingY = Math.abs(this._cellViewCursors[viewId].bounds.getSouth() - this._cellViewCursors[viewId].bounds.getNorth()) / 4.0;
+ if (this._cellViewCursors[viewId].bounds.getWest() < mapBounds.getWest()) {
+ scrollX = this._cellViewCursors[viewId].bounds.getWest() - mapBounds.getWest() - spacingX;
+ } else if (this._cellViewCursors[viewId].bounds.getEast() > mapBounds.getEast()) {
+ scrollX = this._cellViewCursors[viewId].bounds.getEast() - mapBounds.getEast() + spacingX;
+ }
+
+ if (this._cellViewCursors[viewId].bounds.getNorth() > mapBounds.getNorth()) {
+ scrollY = this._cellViewCursors[viewId].bounds.getNorth() - mapBounds.getNorth() + spacingY;
+ } else if (this._cellViewCursors[viewId].bounds.getSouth() < mapBounds.getSouth()) {
+ scrollY = this._cellViewCursors[viewId].bounds.getSouth() - mapBounds.getSouth() - spacingY;
+ }
+
+ if (scrollX !== 0 || scrollY !== 0) {
+ var newCenter = mapBounds.getCenter();
+ newCenter.lat += scrollX;
+ newCenter.lat += scrollY;
+ var center = this._map.project(newCenter);
+ center = center.subtract(this._map.getSize().divideBy(2));
+ center.x = Math.round(center.x < 0 ? 0 : center.x);
+ center.y = Math.round(center.y < 0 ? 0 : center.y);
+ this._map.fire('scrollto', {x: center.x, y: center.y});
+ }
+ }
+
+ var borderColor = L.LOUtil.rgbToHex(this._map.getViewColor(viewId));
+ this._cellViewCursors[viewId].marker.bindPopup(this._map.getViewName(viewId), {autoClose: false, autoPan: false, borderColor: borderColor});
+ }
+ },
+
_onViewCursorVisibleMsg: function(textMsg) {
textMsg = textMsg.substring('viewcursorvisible:'.length + 1);
var obj = JSON.parse(textMsg);
@@ -1264,6 +1301,27 @@ L.TileLayer = L.GridLayer.extend({
}
},
+ goToViewCursor: function(viewId) {
+ if (viewId === this._viewId) {
+ this._onUpdateCursor();
+ return;
+ }
+
+ if (this._viewCursors[viewId] && this._viewCursors[viewId].visible && !this._isEmptyRectangle(this._viewCursors[viewId].bounds)) {
+ if (!this._map.getBounds().contains(this._viewCursors[viewId].bounds)) {
+ var viewCursorPos = this._viewCursors[viewId].bounds.getNorthWest();
+ var center = this._map.project(viewCursorPos);
+ center = center.subtract(this._map.getSize().divideBy(2));
+ center.x = Math.round(center.x < 0 ? 0 : center.x);
+ center.y = Math.round(center.y < 0 ? 0 : center.y);
+
+ this._map.fire('scrollto', {x: center.x, y: center.y});
+ }
+
+ this._viewCursors[viewId].marker.showCursorHeader();
+ }
+ },
+
_onUpdateTextViewSelection: function (viewId) {
viewId = parseInt(viewId);
var viewPolygons = this._viewSelections[viewId].polygons;
@@ -1443,7 +1501,7 @@ L.TileLayer = L.GridLayer.extend({
}
}
else {
- var spacingX = Math.abs((this._cellCursor.getEast() - this._cellCursor.getWest())) / 4.0;
+ var spacingX = Math.abs(this._cellCursor.getEast() - this._cellCursor.getWest()) / 4.0;
var spacingY = Math.abs((this._cellCursor.getSouth() - this._cellCursor.getNorth())) / 4.0;
if (horizontalDirection === -1 && this._cellCursor.getWest() < mapBounds.getWest()) {
scrollX = this._cellCursor.getWest() - mapBounds.getWest() - spacingX;
More information about the Libreoffice-commits
mailing list