- Fix (Embedded editor): (Though embedding cross-origin iframes apparently

only working now in Chrome if same origin or if https?--at least not
  localhost of different ports), PDF export has been fixed (we download the
  PDF to workaround data URI limitations in Chrome)
- Fix (Embedded editor): Avoid using same origin shortcut if there is no
  global available to use (e.g., if using the modular editor)
- Fix (Embedded editor): Add events only after load is complete and
  svgCanvas is available; also log blocked error objects
- Enhancement: For PDF export, switch Chrome by default to "save" `outputType`
- Docs (JSdoc): Denote optional arguments
This commit is contained in:
Brett Zamir
2018-10-23 22:24:09 +08:00
parent 5b4dae0d30
commit a714c122d3
13 changed files with 68 additions and 41 deletions

View File

@@ -4,6 +4,7 @@
* @module EmbeddedSVGEditDOM
*/
import EmbeddedSVGEdit from './embedapi.js';
import {isChrome} from './browser.js';
const $ = jQuery;
@@ -29,7 +30,6 @@ function saveSvg () {
function exportPNG () {
svgCanvas.getUIStrings()(function (uiStrings) {
const str = uiStrings.notification.loadingImage;
const exportWindow = window.open(
'data:text/html;charset=utf-8,' + encodeURIComponent('<title>' + str + '</title><h1>' + str + '</h1>'),
'svg-edit-exportWindow'
@@ -51,22 +51,20 @@ function exportPDF () {
return;
*/
const exportWindow = window.open(
'data:text/html;charset=utf-8,' + encodeURIComponent('<title>' + str + '</title><h1>' + str + '</h1>'),
'svg-edit-exportWindow'
);
svgCanvas.exportPDF(exportWindow && exportWindow.name);
if (isChrome()) {
svgCanvas.exportPDF();
} else {
const exportWindow = window.open(
'data:text/html;charset=utf-8,' + encodeURIComponent('<title>' + str + '</title><h1>' + str + '</h1>'),
'svg-edit-exportWindow'
);
svgCanvas.exportPDF(exportWindow && exportWindow.name);
}
});
}
// Add event handlers
$('#load').click(loadSvg);
$('#save').click(saveSvg);
$('#exportPNG').click(exportPNG);
$('#exportPDF').click(exportPDF);
const frameBase = 'https://raw.githack.com/SVG-Edit/svgedit/master';
// const frameBase = 'http://localhost:8001';
// const frameBase = 'http://localhost:8000';
const framePath = '/editor/xdomain-svg-editor-es.html?extensions=ext-xdomain-messaging.js';
const iframe = $('<iframe width="900px" height="600px" id="svgedit"></iframe>');
iframe[0].src = frameBase + framePath +
@@ -81,11 +79,17 @@ iframe[0].addEventListener('load', function () {
try {
doc = frame.contentDocument || frame.contentWindow.document;
} catch (err) {
console.log('Blocked from accessing document');
console.log('Blocked from accessing document', err);
return;
}
const mainButton = doc.getElementById('main_button');
mainButton.style.display = 'none';
// Add event handlers now that `svgCanvas` is ready
$('#load').click(loadSvg);
$('#save').click(saveSvg);
$('#exportPNG').click(exportPNG);
$('#exportPDF').click(exportPDF);
});
$('body').append(iframe);
const frame = document.getElementById('svgedit');