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

Szymon KÅ‚os (via logerrit) logerrit at kemper.freedesktop.org
Wed Apr 15 09:19:37 UTC 2020


 loleaflet/Makefile.am                        |    1 
 loleaflet/src/control/Control.SearchBar.js   |  111 +++++++++++++++++++++++++++
 loleaflet/src/control/Control.Toolbar.js     |   17 ----
 loleaflet/src/layer/tile/CalcTileLayer.js    |   40 ---------
 loleaflet/src/layer/tile/ImpressTileLayer.js |   40 ---------
 loleaflet/src/layer/tile/WriterTileLayer.js  |   40 ---------
 6 files changed, 115 insertions(+), 134 deletions(-)

New commits:
commit b0be9c7b35049c6ca94702392f59322f3f49e2a0
Author:     Szymon Kłos <szymon.klos at collabora.com>
AuthorDate: Fri Apr 10 15:19:56 2020 +0200
Commit:     Szymon Kłos <szymon.klos at collabora.com>
CommitDate: Wed Apr 15 11:19:19 2020 +0200

    Move SearchBar to separate file
    
    Change-Id: I6db64d35f40f3a762f50df010ead9395a873fb20
    Reviewed-on: https://gerrit.libreoffice.org/c/online/+/92037
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Szymon Kłos <szymon.klos at collabora.com>

diff --git a/loleaflet/Makefile.am b/loleaflet/Makefile.am
index 89d4952d2..cef67ce69 100644
--- a/loleaflet/Makefile.am
+++ b/loleaflet/Makefile.am
@@ -263,6 +263,7 @@ LOLEAFLET_JS =\
 	src/control/Control.MobileSlide.js \
 	src/control/Control.Scale.js \
 	src/control/Control.StatusBar.js \
+	src/control/Control.SearchBar.js \
 	src/control/Control.Layers.js \
 	src/control/Search.js \
 	src/control/Permission.js \
diff --git a/loleaflet/src/control/Control.SearchBar.js b/loleaflet/src/control/Control.SearchBar.js
new file mode 100644
index 000000000..d6714002a
--- /dev/null
+++ b/loleaflet/src/control/Control.SearchBar.js
@@ -0,0 +1,111 @@
+/* -*- js-indent-level: 8 -*- */
+/*
+ * L.Control.SearchBar
+ */
+
+/* global $ w2ui _ _UNO */
+L.Control.SearchBar = L.Control.extend({
+
+	onAdd: function (map) {
+		this.map = map;
+		this.create();
+	},
+
+	create: function() {
+		var that = this;
+		var toolbar = $('#toolbar-search');
+		toolbar.w2toolbar({
+			name: 'searchbar',
+			tooltip: 'top',
+			items: [
+				{
+					type: 'html', id: 'search',
+					html: '<div id="search-input-group" style="padding: 3px 10px;" class="loleaflet-font">' +
+						'    <label for="search-input">Search:</label>' +
+						'    <input size="10" id="search-input"' +
+						'style="padding: 3px; border-radius: 2px; border: 1px solid silver"/>' +
+						'</div>'
+				},
+				{type: 'button', id: 'searchprev', img: 'prev', hint: _UNO('.uno:UpSearch'), disabled: true},
+				{type: 'button', id: 'searchnext', img: 'next', hint: _UNO('.uno:DownSearch'), disabled: true},
+				{type: 'button', id: 'cancelsearch', img: 'cancel', hint: _('Clear the search field'), hidden: true},
+				{type: 'html', id: 'left'},
+				{type: 'button', id: 'hidesearchbar', img: 'unfold', hint: _('Hide the search bar')}
+			],
+			onClick: function (e) {
+				that.onClick(e, e.target, e.item, e.subItem);
+			},
+			onRefresh: function () {
+				window.setupSearchInput();
+			}
+		});
+
+		toolbar.bind('touchstart', function(e) {
+			w2ui['searchbar'].touchStarted = true;
+			var touchEvent = e.originalEvent;
+			if (touchEvent && touchEvent.touches.length > 1) {
+				L.DomEvent.preventDefault(e);
+			}
+		});
+
+		$(w2ui.searchbar.box).find('.w2ui-scroll-left, .w2ui-scroll-right').hide();
+		w2ui.searchbar.on('resize', function(target, e) {
+			e.isCancelled = true;
+		});
+	},
+
+	onClick: function(e, id, item) {
+		if (w2ui['searchbar'].get(id) !== null) {
+			var toolbar = w2ui['searchbar'];
+			item = toolbar.get(id);
+		}
+
+		// In the iOS app we don't want clicking on the toolbar to pop up the keyboard.
+		if (!window.ThisIsTheiOSApp && id !== 'zoomin' && id !== 'zoomout' && id !== 'mobile_wizard' && id !== 'insertion_mobile_wizard') {
+			this.map.focus(this.map.canAcceptKeyboardInput()); // Maintain same keyboard state.
+		}
+
+		if (item.disabled) {
+			return;
+		}
+
+		if (id === 'searchprev') {
+			this.map.search(L.DomUtil.get('search-input').value, true);
+		}
+		else if (id === 'searchnext') {
+			this.map.search(L.DomUtil.get('search-input').value);
+		}
+		else if (id === 'cancelsearch') {
+			this._cancelSearch();
+		}
+		else if (id === 'hidesearchbar') {
+			$('#toolbar-search').hide();
+			if (this.map._permission === 'edit')
+				$('#toolbar-down').show();
+			/** show edit button if only we are able to edit but in readonly mode */
+			if (window.docPermission  === 'edit' && this.map._permission === 'readonly')
+				$('#mobile-edit-button').show();
+		}
+	},
+
+	_cancelSearch: function() {
+		var toolbar = window.mode.isMobile() ? w2ui['searchbar'] : w2ui['actionbar'];
+		var searchInput = L.DomUtil.get('search-input');
+		this.map.resetSelection();
+		toolbar.hide('cancelsearch');
+		toolbar.disable('searchprev');
+		toolbar.disable('searchnext');
+		searchInput.value = '';
+		if (window.mode.isMobile()) {
+			searchInput.focus();
+			// odd, but on mobile we need to invoke it twice
+			toolbar.hide('cancelsearch');
+		}
+
+		this.map._onGotFocus();
+	}
+});
+
+L.control.searchBar = function () {
+	return new L.Control.SearchBar();
+};
diff --git a/loleaflet/src/control/Control.Toolbar.js b/loleaflet/src/control/Control.Toolbar.js
index b4a923787..73c693010 100644
--- a/loleaflet/src/control/Control.Toolbar.js
+++ b/loleaflet/src/control/Control.Toolbar.js
@@ -160,23 +160,6 @@ function onClick(e, id, item) {
 		$('#toolbar-search').show();
 		L.DomUtil.get('search-input').focus();
 	}
-	else if (id === 'hidesearchbar') {
-		$('#toolbar-search').hide();
-		if (map._permission === 'edit')
-			$('#toolbar-down').show();
-		/** show edit button if only we are able to edit but in readonly mode */
-		if (window.docPermission  === 'edit' && map._permission === 'readonly')
-			$('#mobile-edit-button').show();
-	}
-	else if (id === 'searchprev') {
-		map.search(L.DomUtil.get('search-input').value, true);
-	}
-	else if (id === 'searchnext') {
-		map.search(L.DomUtil.get('search-input').value);
-	}
-	else if (id === 'cancelsearch') {
-		_cancelSearch();
-	}
 	else if ((id === 'presentation' || id === 'fullscreen-presentation') && map.getDocType() === 'presentation') {
 		map.fire('fullscreen');
 	}
diff --git a/loleaflet/src/layer/tile/CalcTileLayer.js b/loleaflet/src/layer/tile/CalcTileLayer.js
index da8b51a1d..a1af6f75e 100644
--- a/loleaflet/src/layer/tile/CalcTileLayer.js
+++ b/loleaflet/src/layer/tile/CalcTileLayer.js
@@ -210,45 +210,7 @@ L.CalcTileLayer = L.TileLayer.extend({
 			}
 		});
 
-		toolbar = $('#toolbar-search');
-		toolbar.w2toolbar({
-			name: 'searchbar',
-			tooltip: 'top',
-			items: [
-				{
-					type: 'html', id: 'search',
-					html: '<div id="search-input-group" style="padding: 3px 10px;" class="loleaflet-font">' +
-						'    <label for="search-input">Search:</label>' +
-						'    <input size="10" id="search-input"' +
-						'style="padding: 3px; border-radius: 2px; border: 1px solid silver"/>' +
-						'</div>'
-				},
-				{type: 'button', id: 'searchprev', img: 'prev', hint: _UNO('.uno:UpSearch'), disabled: true},
-				{type: 'button', id: 'searchnext', img: 'next', hint: _UNO('.uno:DownSearch'), disabled: true},
-				{type: 'button', id: 'cancelsearch', img: 'cancel', hint: _('Clear the search field'), hidden: true},
-				{type: 'html', id: 'left'},
-				{type: 'button', id: 'hidesearchbar', img: 'unfold', hint: _('Hide the search bar')}
-			],
-			onClick: function (e) {
-				window.onClick(e, e.target, e.item, e.subItem);
-			},
-			onRefresh: function () {
-				window.setupSearchInput();
-			}
-		});
-
-		toolbar.bind('touchstart', function(e) {
-			w2ui['searchbar'].touchStarted = true;
-			var touchEvent = e.originalEvent;
-			if (touchEvent && touchEvent.touches.length > 1) {
-				L.DomEvent.preventDefault(e);
-			}
-		});
-
-		$(w2ui.searchbar.box).find('.w2ui-scroll-left, .w2ui-scroll-right').hide();
-		w2ui.searchbar.on('resize', function(target, e) {
-			e.isCancelled = true;
-		});
+		map.addControl(L.control.searchBar());
 
 		map.on('updatetoolbarcommandvalues', function() {
 			w2ui['editbar'].refresh();
diff --git a/loleaflet/src/layer/tile/ImpressTileLayer.js b/loleaflet/src/layer/tile/ImpressTileLayer.js
index d2a8dc4c4..e91d32094 100644
--- a/loleaflet/src/layer/tile/ImpressTileLayer.js
+++ b/loleaflet/src/layer/tile/ImpressTileLayer.js
@@ -205,45 +205,7 @@ L.ImpressTileLayer = L.TileLayer.extend({
 			}
 		});
 
-		toolbar = $('#toolbar-search');
-		toolbar.w2toolbar({
-			name: 'searchbar',
-			tooltip: 'top',
-			items: [
-				{
-					type: 'html', id: 'search',
-					html: '<div id="search-input-group" style="padding: 3px 10px;" class="loleaflet-font">' +
-						'    <label for="search-input">Search:</label>' +
-						'    <input size="10" id="search-input"' +
-						'style="padding: 3px; border-radius: 2px; border: 1px solid silver"/>' +
-						'</div>'
-				},
-				{type: 'button', id: 'searchprev', img: 'prev', hint: _UNO('.uno:UpSearch'), disabled: true},
-				{type: 'button', id: 'searchnext', img: 'next', hint: _UNO('.uno:DownSearch'), disabled: true},
-				{type: 'button', id: 'cancelsearch', img: 'cancel', hint: _('Clear the search field'), hidden: true},
-				{type: 'html', id: 'left'},
-				{type: 'button', id: 'hidesearchbar', img: 'unfold', hint: _('Hide the search bar')}
-			],
-			onClick: function (e) {
-				window.onClick(e, e.target, e.item, e.subItem);
-			},
-			onRefresh: function () {
-				window.setupSearchInput();
-			}
-		});
-
-		toolbar.bind('touchstart', function(e) {
-			w2ui['searchbar'].touchStarted = true;
-			var touchEvent = e.originalEvent;
-			if (touchEvent && touchEvent.touches.length > 1) {
-				L.DomEvent.preventDefault(e);
-			}
-		});
-
-		$(w2ui.searchbar.box).find('.w2ui-scroll-left, .w2ui-scroll-right').hide();
-		w2ui.searchbar.on('resize', function(target, e) {
-			e.isCancelled = true;
-		});
+		map.addControl(L.control.searchBar());
 
 		map.on('updatetoolbarcommandvalues', function() {
 			w2ui['editbar'].refresh();
diff --git a/loleaflet/src/layer/tile/WriterTileLayer.js b/loleaflet/src/layer/tile/WriterTileLayer.js
index bc34beadc..caff2e102 100644
--- a/loleaflet/src/layer/tile/WriterTileLayer.js
+++ b/loleaflet/src/layer/tile/WriterTileLayer.js
@@ -142,45 +142,7 @@ L.WriterTileLayer = L.TileLayer.extend({
 			}
 		});
 
-		toolbar = $('#toolbar-search');
-		toolbar.w2toolbar({
-			name: 'searchbar',
-			tooltip: 'top',
-			items: [
-				{
-					type: 'html', id: 'search',
-					html: '<div id="search-input-group" style="padding: 3px 10px;" class="loleaflet-font">' +
-						'    <label for="search-input">Search:</label>' +
-						'    <input size="10" id="search-input"' +
-						'style="padding: 3px; border-radius: 2px; border: 1px solid silver"/>' +
-						'</div>'
-				},
-				{type: 'button', id: 'searchprev', img: 'prev', hint: _UNO('.uno:UpSearch'), disabled: true},
-				{type: 'button', id: 'searchnext', img: 'next', hint: _UNO('.uno:DownSearch'), disabled: true},
-				{type: 'button', id: 'cancelsearch', img: 'cancel', hint: _('Clear the search field'), hidden: true},
-				{type: 'html', id: 'left'},
-				{type: 'button', id: 'hidesearchbar', img: 'unfold', hint: _('Hide the search bar')}
-			],
-			onClick: function (e) {
-				window.onClick(e, e.target, e.item, e.subItem);
-			},
-			onRefresh: function () {
-				window.setupSearchInput();
-			}
-		});
-
-		toolbar.bind('touchstart', function(e) {
-			w2ui['searchbar'].touchStarted = true;
-			var touchEvent = e.originalEvent;
-			if (touchEvent && touchEvent.touches.length > 1) {
-				L.DomEvent.preventDefault(e);
-			}
-		});
-
-		$(w2ui.searchbar.box).find('.w2ui-scroll-left, .w2ui-scroll-right').hide();
-		w2ui.searchbar.on('resize', function(target, e) {
-			e.isCancelled = true;
-		});
+		map.addControl(L.control.searchBar());
 
 		map.on('updatepermission', window.onUpdatePermission);
 	},


More information about the Libreoffice-commits mailing list