From 096abcb0286be067efd9a0dbb635762274ead1a1 Mon Sep 17 00:00:00 2001 From: agriyadev5 Date: Thu, 10 Jun 2021 14:01:58 +0530 Subject: [PATCH] #431 Need help about image tags --- src/editor/Editor.js | 21 ++++++++++++++++----- src/editor/panels/TopPanel.js | 14 ++++++++------ src/svgcanvas/svg-exec.js | 2 +- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/editor/Editor.js b/src/editor/Editor.js index 39234007..7bfd6d78 100644 --- a/src/editor/Editor.js +++ b/src/editor/Editor.js @@ -417,11 +417,22 @@ class Editor extends EditorStartup { $id("change_image_url").style.display = 'block'; } else { // regular URL - this.svgCanvas.embedImage(url, function (dataURI) { - // Couldn't embed, so show warning - $id('url_notice').style.display = (!dataURI) ? 'block' : 'none'; - this.defaultImageURL = url; - }); + const self = this; + const promised = this.svgCanvas.embedImage(url); + // eslint-disable-next-line promise/catch-or-return + promised + .then( function (dataURI) { + // eslint-disable-next-line promise/always-return + $id('url_notice').style.display = (!dataURI) ? 'block' : 'none'; + // switch into "select" mode if we've clicked on an element + self.svgCanvas.setMode('select'); + self.svgCanvas.selectOnly(self.svgCanvas.getSelectedElems(), true); + }, function (error) { + // eslint-disable-next-line no-console + console.log("error =", error); + seAlert(self.i18next.t('tools.no_embed')); + self.svgCanvas.deleteSelectedElements(); + }); $id("image_url").style.display = 'block'; $id("change_image_url").style.display = 'none'; } diff --git a/src/editor/panels/TopPanel.js b/src/editor/panels/TopPanel.js index c8a03715..c0a5fcb6 100644 --- a/src/editor/panels/TopPanel.js +++ b/src/editor/panels/TopPanel.js @@ -292,12 +292,14 @@ class TopPanel { $id("g_panel").style.display = 'block'; } // siblings - const selements = Array.prototype.filter.call(elem.parentNode.children, function(child){ - return child !== elem; - }); - if (elem.parentNode.tagName === "a" && !selements.length) { - $id("a_panel").style.display = 'block'; - linkHref = this.editor.svgCanvas.getHref(elem.parentNode); + if (elem.parentNode) { + const selements = Array.prototype.filter.call(elem.parentNode.children, function(child){ + return child !== elem; + }); + if (elem.parentNode.tagName === "a" && !selements.length) { + $id("a_panel").style.display = 'block'; + linkHref = this.editor.svgCanvas.getHref(elem.parentNode); + } } // Hide/show the make_link buttons diff --git a/src/svgcanvas/svg-exec.js b/src/svgcanvas/svg-exec.js index b4dd6a91..3052deb3 100644 --- a/src/svgcanvas/svg-exec.js +++ b/src/svgcanvas/svg-exec.js @@ -651,7 +651,7 @@ export const embedImage = function (src) { resolve(svgContext_.getEncodableImages(src)); }); imgI.addEventListener("error", (e) => { - reject(new Error(`error loading image: ${e.currentTarget.attributes.src.value}`)); + reject(`error loading image: ${e.currentTarget.attributes.src.value}`); }); imgI.setAttribute('src', src); });