From 2a04af162af4df63b36b73609e48b6754c401854 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Wed, 21 Jun 2023 12:00:34 +0200 Subject: [PATCH 1/3] Make outlink and outlinkTarget available for each feature It was only for polygon until then. cf #323 --- umap/static/umap/js/umap.features.js | 15 ++------------- umap/static/umap/js/umap.forms.js | 11 +++++++++++ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/umap/static/umap/js/umap.features.js b/umap/static/umap/js/umap.features.js index 9b7ac8b2..67d1e346 100644 --- a/umap/static/umap/js/umap.features.js +++ b/umap/static/umap/js/umap.features.js @@ -173,6 +173,8 @@ L.U.FeatureMixin = { 'properties._umap_options.showLabel', 'properties._umap_options.labelDirection', 'properties._umap_options.labelInteractive', + 'properties._umap_options.outlink', + 'properties._umap_options.outlinkTarget', ] }, @@ -1045,19 +1047,6 @@ L.U.Polygon = L.Polygon.extend({ inheritable: true, }, ], - [ - 'properties._umap_options.outlink', - { - label: L._('Link to…'), - helpEntries: 'outlink', - placeholder: 'http://...', - inheritable: true, - }, - ], - [ - 'properties._umap_options.outlinkTarget', - { handler: 'OutlinkTarget', label: L._('Open link in…'), inheritable: true }, - ], ] return options.concat(L.U.FeatureMixin.getInteractionOptions()) }, diff --git a/umap/static/umap/js/umap.forms.js b/umap/static/umap/js/umap.forms.js index 7883e306..19f6ad90 100644 --- a/umap/static/umap/js/umap.forms.js +++ b/umap/static/umap/js/umap.forms.js @@ -1045,6 +1045,17 @@ L.U.FormBuilder = L.FormBuilder.extend({ label: L._('Labels are clickable'), inheritable: true, }, + outlink: { + label: L._('Link to…'), + helpEntries: 'outlink', + placeholder: 'http://...', + inheritable: true, + }, + outlinkTarget: { + handler: 'OutlinkTarget', + label: L._('Open link in…'), + inheritable: true, + }, labelKey: { helpEntries: 'labelKey', placeholder: L._('Default: name'), From 3f8db1191f5bba05a27d84d37c35c78a1ca49ad3 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Wed, 21 Jun 2023 12:19:01 +0200 Subject: [PATCH 2/3] Allow to control popup links target --- umap/static/umap/js/umap.core.js | 13 +++++++------ umap/static/umap/js/umap.popup.js | 3 ++- umap/static/umap/test/Util.js | 7 +++++++ 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/umap/static/umap/js/umap.core.js b/umap/static/umap/js/umap.core.js index 84ef5f2e..4e5ad8bb 100644 --- a/umap/static/umap/js/umap.core.js +++ b/umap/static/umap/js/umap.core.js @@ -73,8 +73,9 @@ L.Util.escapeHTML = (s) => { }) return s } -L.Util.toHTML = (r) => { +L.Util.toHTML = (r, options) => { if (!r) return '' + const target = options && options.target || 'blank' let ii // detect newline format @@ -100,14 +101,14 @@ L.Util.toHTML = (r) => { r = r.replace(/(\[\[http)/g, '[[h_t_t_p') // Escape for avoiding clash between [[http://xxx]] and http://xxx r = r.replace(/({{http)/g, '{{h_t_t_p') r = r.replace(/(=http)/g, '=h_t_t_p') // http://xxx as query string, see https://github.com/umap-project/umap/issues/607 - r = r.replace(/(https?:[^ \<)\n]*)/g, '$1') - r = r.replace(/\[\[(h_t_t_ps?:[^\]|]*?)\]\]/g, '$1') + r = r.replace(/(https?:[^ \<)\n]*)/g, `$1`) + r = r.replace(/\[\[(h_t_t_ps?:[^\]|]*?)\]\]/g, `$1`) r = r.replace( /\[\[(h_t_t_ps?:[^|]*?)\|(.*?)\]\]/g, - '$2' + `$2` ) - r = r.replace(/\[\[([^\]|]*?)\]\]/g, '$1') - r = r.replace(/\[\[([^|]*?)\|(.*?)\]\]/g, '$2') + r = r.replace(/\[\[([^\]|]*?)\]\]/g, `$1`) + r = r.replace(/\[\[([^|]*?)\|(.*?)\]\]/g, `$2`) // iframe r = r.replace( diff --git a/umap/static/umap/js/umap.popup.js b/umap/static/umap/js/umap.popup.js index b65807f0..173cba39 100644 --- a/umap/static/umap/js/umap.popup.js +++ b/umap/static/umap/js/umap.popup.js @@ -98,6 +98,7 @@ L.U.PopupTemplate.Default = L.Class.extend({ renderBody: function () { const template = this.feature.getOption('popupContentTemplate') + const target = this.feature.getOption('outlinkTarget') const container = L.DomUtil.create('div', 'umap-popup-container') let content = '' let properties @@ -109,7 +110,7 @@ L.U.PopupTemplate.Default = L.Class.extend({ properties ) content = L.Util.greedyTemplate(template, properties) - content = L.Util.toHTML(content) + content = L.Util.toHTML(content, {target: target}) container.innerHTML = content return container }, diff --git a/umap/static/umap/test/Util.js b/umap/static/umap/test/Util.js index 311e25a5..8ed8e6d9 100644 --- a/umap/static/umap/test/Util.js +++ b/umap/static/umap/test/Util.js @@ -84,6 +84,13 @@ describe('L.Util', function () { ) }) + it('should handle target option', function () { + assert.equal( + L.Util.toHTML('A simple http://osm.org link', {target: 'self'}), + 'A simple http://osm.org link' + ) + }) + it('should handle image', function () { assert.equal( L.Util.toHTML('A simple image: {{http://osm.org/pouet.png}}'), From a1ec50ed8c99f34858e2f59198e704caaf33a2ee Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Wed, 21 Jun 2023 12:24:29 +0200 Subject: [PATCH 3/3] Allow to define outlinkTarget at layer level --- umap/static/umap/js/umap.features.js | 4 ++-- umap/static/umap/js/umap.layer.js | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/umap/static/umap/js/umap.features.js b/umap/static/umap/js/umap.features.js index 67d1e346..461215e2 100644 --- a/umap/static/umap/js/umap.features.js +++ b/umap/static/umap/js/umap.features.js @@ -57,8 +57,8 @@ L.U.FeatureMixin = { view: function (e) { if (this.map.editEnabled) return - const outlink = this.properties._umap_options.outlink, - target = this.properties._umap_options.outlinkTarget + const outlink = this.getOption('outlink'), + target = this.getOption('outlinkTarget') if (outlink) { switch (target) { case 'self': diff --git a/umap/static/umap/js/umap.layer.js b/umap/static/umap/js/umap.layer.js index adebd44f..5647b89b 100644 --- a/umap/static/umap/js/umap.layer.js +++ b/umap/static/umap/js/umap.layer.js @@ -862,6 +862,7 @@ L.U.DataLayer = L.Evented.extend({ 'options.showLabel', 'options.labelDirection', 'options.labelInteractive', + 'options.outlinkTarget', ] builder = new L.U.FormBuilder(this, popupFields, { callback: redrawCallback }) const popupFieldset = L.DomUtil.createFieldset(