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

Aditya Dewan aditya.dewan at collabora.co.uk
Thu Dec 7 13:26:29 UTC 2017


 loleaflet/src/control/Ruler.js |   44 +++++++++++++++++++++++++++--------------
 loleaflet/src/map/Map.js       |    3 +-
 2 files changed, 31 insertions(+), 16 deletions(-)

New commits:
commit a508d5b490fa246174ed9754cb93ecaef3880452
Author: Aditya Dewan <aditya.dewan at collabora.co.uk>
Date:   Wed Dec 6 20:05:44 2017 +0530

    Disable interactive ruler for readonly docs
    
    Change-Id: I7982387d5dd913dd5e4ca5ff5d188ad0eed00fa6
    Reviewed-on: https://gerrit.libreoffice.org/45962
    Reviewed-by: pranavk <pranavk at collabora.co.uk>
    Tested-by: pranavk <pranavk at collabora.co.uk>

diff --git a/loleaflet/src/control/Ruler.js b/loleaflet/src/control/Ruler.js
index 22453cee..68ccbfd0 100644
--- a/loleaflet/src/control/Ruler.js
+++ b/loleaflet/src/control/Ruler.js
@@ -24,6 +24,7 @@ L.Control.Ruler = L.Control.extend({
 		map.on('rulerupdate', this._updateOptions, this);
 		map.on('docsize', this._updatePaintTimer, this);
 		map.on('scrolloffset resize', this._fixOffset, this);
+		map.on('updatepermission', this._changeInteractions, this);
 		this._map = map;
 
 		return this._initLayout();
@@ -34,6 +35,22 @@ L.Control.Ruler = L.Control.extend({
 		this.options.timer = setTimeout(L.bind(this._updateBreakPoints, this), 300);
 	},
 
+	_changeInteractions: function(e) {
+		if (e.perm === 'edit') {
+			this._lMarginDrag.style.cursor = 'e-resize';
+			this._rMarginDrag.style.cursor = 'w-resize';
+
+			L.DomEvent.on(this._rMarginDrag, 'mousedown', this._initiateDrag, this);
+			L.DomEvent.on(this._lMarginDrag, 'mousedown', this._initiateDrag, this);
+		}
+		else {
+			this._lMarginDrag.style.cursor = 'default';
+			this._rMarginDrag.style.cursor = 'default';
+
+			L.DomEvent.off(this._rMarginDrag, 'mousedown', this._initiateDrag, this);
+			L.DomEvent.off(this._lMarginDrag, 'mousedown', this._initiateDrag, this);
+		}
+	},
 
 	_initLayout: function() {
 		this._rWrapper = L.DomUtil.create('div', 'loleaflet-ruler leaflet-bar leaflet-control leaflet-control-custom');
@@ -112,28 +129,25 @@ L.Control.Ruler = L.Control.extend({
 			this._lMarginMarker = L.DomUtil.create('div', classMargin + ' ' + leftComp, this._rFace);
 			this._rMarginMarker =  L.DomUtil.create('div', classMargin + ' ' + rightComp, this._rFace);
 
-			if (this.options.interactive) {
-				this._lMarginDrag = L.DomUtil.create('div', classDraggable + ' ' + leftComp, this._rMarginWrapper);
-				this._lToolTip = L.DomUtil.create('div', lToolTip, this._lMarginDrag)
-				this._rMarginDrag = L.DomUtil.create('div', classDraggable + ' ' + rightComp, this._rMarginWrapper);
-				this._rToolTip = L.DomUtil.create('div', rToolTip, this._rMarginDrag)
-				this._lMarginDrag.style.cursor = 'e-resize';
-				this._rMarginDrag.style.cursor = 'w-resize';
-				this._lMarginDrag.title = leftMarginStr;
-				this._rMarginDrag.title = rightMarginStr;
-			}
+			this._lMarginDrag = L.DomUtil.create('div', classDraggable + ' ' + leftComp, this._rMarginWrapper);
+			this._lToolTip = L.DomUtil.create('div', lToolTip, this._lMarginDrag)
+			this._rMarginDrag = L.DomUtil.create('div', classDraggable + ' ' + rightComp, this._rMarginWrapper);
+			this._rToolTip = L.DomUtil.create('div', rToolTip, this._rMarginDrag)
+			this._lMarginDrag.title = leftMarginStr;
+			this._rMarginDrag.title = rightMarginStr;
 		}
 
 		this._lMarginMarker.style.width = (DraggableConvertRatio*lMargin) + 'px';
 		this._rMarginMarker.style.width = (DraggableConvertRatio*rMargin) + 'px';
+		this._lMarginDrag.style.width = (DraggableConvertRatio*lMargin) + 'px';
+		this._rMarginDrag.style.width = (DraggableConvertRatio*rMargin) + 'px';
 
 		if (this.options.interactive) {
-			this._lMarginDrag.style.width = (DraggableConvertRatio*lMargin) + 'px';
-			this._rMarginDrag.style.width = (DraggableConvertRatio*rMargin) + 'px';
+			this._changeInteractions({perm:'edit'});
+		}
+		else {
+			this._changeInteractions({perm:'readonly'});
 		}
-
-		L.DomEvent.on(this._rMarginDrag, 'mousedown', this._initiateDrag, this);
-		L.DomEvent.on(this._lMarginDrag, 'mousedown', this._initiateDrag, this);
 	},
 
 	_fixOffset: function() {
diff --git a/loleaflet/src/map/Map.js b/loleaflet/src/map/Map.js
index f4696cb9..6c5d8f71 100644
--- a/loleaflet/src/map/Map.js
+++ b/loleaflet/src/map/Map.js
@@ -119,7 +119,8 @@ L.Map = L.Evented.extend({
 				this._fireInitComplete('doclayerinit');
 			}
 			if (this._docLayer._docType == 'text') {
-				L.control.ruler({position:'topleft'}).addTo(this);
+				var interactiveRuler = this._permission === 'edit' ? true : false;
+				L.control.ruler({position:'topleft', interactive:interactiveRuler}).addTo(this);
 			}
 		});
 		this.on('updatetoolbarcommandvalues', function(e) {


More information about the Libreoffice-commits mailing list