diff --git a/umap/static/umap/js/umap.core.js b/umap/static/umap/js/umap.core.js index e3ce8f02..2cf791ba 100644 --- a/umap/static/umap/js/umap.core.js +++ b/umap/static/umap/js/umap.core.js @@ -260,6 +260,18 @@ L.Util.hasVar = (value) => { return typeof value === 'string' && value.indexOf('{') != -1 } +L.Util.isPath = function (value) { + return value && value.length && value.startsWith('/') +} + +L.Util.isRemoteUrl = function (value) { + return value && value.length && value.startsWith('http') +} + +L.Util.isDataImage = function (value) { + return value && value.length && value.startsWith('data:image') +} + L.Util.copyToClipboard = function (textToCopy) { // https://stackoverflow.com/a/65996386 // Navigator clipboard api needs a secure context (https) diff --git a/umap/static/umap/js/umap.forms.js b/umap/static/umap/js/umap.forms.js index fb7a41c1..b3970973 100644 --- a/umap/static/umap/js/umap.forms.js +++ b/umap/static/umap/js/umap.forms.js @@ -538,8 +538,8 @@ L.FormBuilder.IconUrl = L.FormBuilder.BlurInput.extend({ this.footer.innerHTML = '' this.buildTabs() const value = this.value() - if (!value || value.startsWith('/')) this.showSymbolsTab() - else if (value.startsWith('http')) this.showURLTab() + if (!value || L.Util.isPath(value)) this.showSymbolsTab() + else if (L.Util.isRemoteUrl(value) || L.Util.isDataImage(value)) this.showURLTab() else this.showCharsTab() const closeButton = L.DomUtil.createButton( 'button action-button', @@ -596,18 +596,11 @@ L.FormBuilder.IconUrl = L.FormBuilder.BlurInput.extend({ this.body.innerHTML = '' }, - isPath: function () { - const value = this.value() - return value && value.length && value.startsWith('/') - }, - - isRemoteUrl: function () { - const value = this.value() - return value && value.length && value.startsWith('http') - }, - isImg: function () { - return this.isPath() || this.isRemoteUrl() + const value = this.value() + return ( + L.Util.isPath(value) || L.Util.isRemoteUrl(value) || L.Util.isDataImage(value) + ) }, updatePreview: function () { @@ -731,7 +724,10 @@ L.FormBuilder.IconUrl = L.FormBuilder.BlurInput.extend({ showURLTab: function () { this.openTab('url') - const value = this.isRemoteUrl() ? this.value() : null + const value = + L.Util.isRemoteUrl(this.value()) || L.Util.isDataImage(this.value()) + ? this.value() + : null const input = this.buildInput(this.body, value) input.placeholder = L._('Add image URL') input.type = 'url'