From 478ba7a417830d9fa13a0fb803995eb963daa794 Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Thu, 30 Dec 2021 23:47:47 -0800 Subject: [PATCH] Finish img support --- .../mindplot/src/components/widget/Menu.js | 21 ++++++++++++++----- .../playground/map-render/html/editor.html | 2 -- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/packages/mindplot/src/components/widget/Menu.js b/packages/mindplot/src/components/widget/Menu.js index 450d4ad0..26ef5922 100644 --- a/packages/mindplot/src/components/widget/Menu.js +++ b/packages/mindplot/src/components/widget/Menu.js @@ -213,13 +213,25 @@ class Menu extends IMenu { this._addButton('export', false, false, () => { const svgContent = designer.export('svg'); + + // Encode content ... + const blob = new Blob([svgContent], { type: 'image/svg+xml' }); + const win = window.URL || window.webkitURL || window; + const svgUri = win.createObjectURL(blob); console.log(svgContent); - const anchor = $('#export_anchor'); - anchor.attr('download', `${mapId}.svg`); - anchor.attr('href', `data:image/svg+xml;base64,${btoa(svgContent)}`); + // Create anchor element ... + const anchor = document.createElement('a'); + anchor.style = 'display: none'; + anchor.download = `${mapId}.svg`; + anchor.href = svgUri; + document.body.appendChild(anchor); + // Trigger click ... anchor.click(); + + // Clean up ... + document.body.removeChild(anchor); }); Menu._registerTooltip('export', $msg('EXPORT')); @@ -457,13 +469,12 @@ class Menu extends IMenu { } _addButton(buttonId, topic, rel, fn) { - const me = this; // Register Events ... let result = null; if ($(`#${buttonId}`)) { const button = new ToolbarItem(buttonId, ((event) => { fn(event); - me.clear(); + this.clear(); }), { topicAction: topic, relAction: rel }); this._toolbarElems.push(button); diff --git a/packages/mindplot/test/playground/map-render/html/editor.html b/packages/mindplot/test/playground/map-render/html/editor.html index faee12bf..e5c0c670 100644 --- a/packages/mindplot/test/playground/map-render/html/editor.html +++ b/packages/mindplot/test/playground/map-render/html/editor.html @@ -10,7 +10,6 @@ -