Finish img support

This commit is contained in:
Paulo Gustavo Veiga 2021-12-30 23:47:47 -08:00
parent b747ca9a47
commit 478ba7a417
2 changed files with 16 additions and 7 deletions

View File

@ -213,13 +213,25 @@ class Menu extends IMenu {
this._addButton('export', false, false, () => { this._addButton('export', false, false, () => {
const svgContent = designer.export('svg'); 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); console.log(svgContent);
const anchor = $('#export_anchor'); // Create anchor element ...
anchor.attr('download', `${mapId}.svg`); const anchor = document.createElement('a');
anchor.attr('href', `data:image/svg+xml;base64,${btoa(svgContent)}`); anchor.style = 'display: none';
anchor.download = `${mapId}.svg`;
anchor.href = svgUri;
document.body.appendChild(anchor);
// Trigger click ...
anchor.click(); anchor.click();
// Clean up ...
document.body.removeChild(anchor);
}); });
Menu._registerTooltip('export', $msg('EXPORT')); Menu._registerTooltip('export', $msg('EXPORT'));
@ -457,13 +469,12 @@ class Menu extends IMenu {
} }
_addButton(buttonId, topic, rel, fn) { _addButton(buttonId, topic, rel, fn) {
const me = this;
// Register Events ... // Register Events ...
let result = null; let result = null;
if ($(`#${buttonId}`)) { if ($(`#${buttonId}`)) {
const button = new ToolbarItem(buttonId, ((event) => { const button = new ToolbarItem(buttonId, ((event) => {
fn(event); fn(event);
me.clear(); this.clear();
}), { topicAction: topic, relAction: rel }); }), { topicAction: topic, relAction: rel });
this._toolbarElems.push(button); this._toolbarElems.push(button);

View File

@ -10,7 +10,6 @@
</head> </head>
<body> <body>
<div id='load' class="modal fade"> <div id='load' class="modal fade">
<div class="modal-dialog"> <div class="modal-dialog">
<div style="height: 120px; text-align: center; border: 2px solid orange" class="modal-content"> <div style="height: 120px; text-align: center; border: 2px solid orange" class="modal-content">
@ -38,7 +37,6 @@
<div id="export" class="buttonOn"> <div id="export" class="buttonOn">
<img src="images/export.svg" /> <img src="images/export.svg" />
</div> </div>
<a id="export_anchor" href="" download=""></a>
</div> </div>
<div id="edit" class="buttonContainer"> <div id="edit" class="buttonContainer">
<div id="undoEdition" class="buttonOn"> <div id="undoEdition" class="buttonOn">