From b0bad24645efe27b243f09d01c1e59392d3d7ce3 Mon Sep 17 00:00:00 2001 From: Brett Zamir Date: Thu, 13 Sep 2018 09:13:05 +0800 Subject: [PATCH] - Linting (ESLint): Apply coding standards - Breaking change (minor): Change export filename to check `exportWindowName` and change default from `download.pdf` to `svg.pdf` to distinguish from other downloads - Enhancement: Restore old dataURI functionality for non-Chrome browsers --- editor/jspdf/jspdf.plugin.svgToPdf.js | 16 ++++++++-------- editor/svg-editor.js | 19 +++++++++++++++++-- editor/svgcanvas.js | 4 ++-- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/editor/jspdf/jspdf.plugin.svgToPdf.js b/editor/jspdf/jspdf.plugin.svgToPdf.js index 74aa7d73..b8d99172 100644 --- a/editor/jspdf/jspdf.plugin.svgToPdf.js +++ b/editor/jspdf/jspdf.plugin.svgToPdf.js @@ -181,17 +181,17 @@ const svgElementToPdf = function (element, pdf, options) { const getWidth = (node) => { let box; - try{ - box = node.getBBox(); //Firefox on MacOS will raise error here - }catch(err){ - //copy and append to body so that getBBox is available - let nodeCopy = node.cloneNode(true); - let svg = node.ownerSVGElement.cloneNode(false); + try { + box = node.getBBox(); // Firefox on MacOS will raise error here + } catch (err) { + // copy and append to body so that getBBox is available + const nodeCopy = node.cloneNode(true); + const svg = node.ownerSVGElement.cloneNode(false); svg.appendChild(nodeCopy); document.body.appendChild(svg); - try{ + try { box = nodeCopy.getBBox(); - }catch(err){ + } catch (err) { box = {width: 0}; } document.body.removeChild(svg); diff --git a/editor/svg-editor.js b/editor/svg-editor.js index 738bf8cb..e0eae9e8 100644 --- a/editor/svg-editor.js +++ b/editor/svg-editor.js @@ -2,7 +2,7 @@ import './touch.js'; import {NS} from './namespaces.js'; -import {isWebkit, isGecko, isIE, isMac, isTouch} from './browser.js'; +import {isWebkit, isChrome, isGecko, isIE, isMac, isTouch} from './browser.js'; import * as Utils from './utilities.js'; import {getTypeMap, convertUnit, isValidUnit} from './units.js'; import { @@ -3382,6 +3382,18 @@ editor.init = function () { svgCanvas.bind('saved', saveHandler); svgCanvas.bind('exported', exportHandler); svgCanvas.bind('exportedPDF', function (win, data) { + if (!data.output) { // Ignore Chrome + return; + } + const {exportWindowName} = data; + if (exportWindowName) { + exportWindow = window.open('', exportWindowName); // A hack to get the window via JSON-able name without opening a new one + } + if (!exportWindow || exportWindow.closed) { + $.alert(uiStrings.notification.popupWindowBlocked); + return; + } + exportWindow.location.href = data.output; }); svgCanvas.bind('zoomed', zoomChanged); svgCanvas.bind('zoomDone', zoomDone); @@ -4199,7 +4211,10 @@ editor.init = function () { exportWindow = window.open(popURL, exportWindowName); } if (imgType === 'PDF') { - svgCanvas.exportPDF(exportWindowName, 'save'); + if (!customExportPDF && !isChrome()) { + openExportWindow(); + } + svgCanvas.exportPDF(exportWindowName, isChrome() ? 'save' : undefined); } else { if (!customExportImage) { openExportWindow(); diff --git a/editor/svgcanvas.js b/editor/svgcanvas.js index a9553032..2d5c25dd 100644 --- a/editor/svgcanvas.js +++ b/editor/svgcanvas.js @@ -3956,7 +3956,7 @@ this.rasterExport = function (imgType, quality, exportWindowName, cb) { * Generates a PDF based on the current image, then calls "exportedPDF" with * an object including the string, the data URL, and any issues found * @function module:svgcanvas.SvgCanvas#exportPDF -* @param {string} exportWindowName +* @param {string} exportWindowName Will also be used for the download file name here * @param {external:jsPDF.OutputType} [outputType="dataurlstring"] * @param {module:svgcanvas.PDFExportedCallback} cb * @fires module:svgcanvas.SvgCanvas#event:exportedPDF @@ -4015,7 +4015,7 @@ this.exportPDF = function (exportWindowName, outputType, cb) { // opposed to opening a new tab outputType = outputType || 'dataurlstring'; const obj = {svg, issues, issueCodes, exportWindowName, outputType}; - obj.output = doc.output(outputType, outputType === 'save' ? 'Download.pdf' : void 0); + obj.output = doc.output(outputType, outputType === 'save' ? (exportWindowName || 'svg.pdf') : undefined); if (cb) { cb(obj); }