Skip to content

Commit

Permalink
- Fix: Have export handler, if triggered, always open a window even i…
Browse files Browse the repository at this point in the history
…f no

  window name was given (needed in Chrome to avoid opening an extra window)
- Fix (Embedded editor regression): Ensure event handlers are added even if
    document cannot be directly modified
- Enhancement: Add `opts` object to `rasterExport` with `avoidEvent` property
  to avoid calling the `exported` event
- Docs (CHANGES): Update
- Docs (README): Deemphasize unstable embedded editor fixes
  • Loading branch information
brettz9 committed Oct 24, 2018
1 parent 07f59ba commit 283ef0b
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 45 deletions.
16 changes: 11 additions & 5 deletions CHANGES.md
@@ -1,16 +1,21 @@
# 3.1.0

- 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): (Though cross-origin DOM access of iframes apparently
doesn't work now in Chrome or Firefox (which we had been using to disable a
button) nor does cross-origin storage access work in Chrome), PDF export has
been fixed (we download the PDF to workaround data URI limitations in Chrome)
and we avoid opening an extra tab in Chrome PNG export
- 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
- Fix: Have export handler, if triggered, always open a window even if no
window name was given (needed in Chrome to avoid opening an extra window)
- Enhancement: For anyone visiting the ES6 modules entrance file without ESM
support, redirect to non-modular version
- Enhancement: For PDF export, switch Chrome by default to "save" `outputType`
- Enhancement: Add `opts` object to `rasterExport` with `avoidEvent` property
to avoid calling the `exported` event
- Refactoring (canvg): Better type-checking on `canvasRGBA_` (but set
correctly by default anyways)
- Refactoring: Avoid redundant use of \*AttributeNS methods with
Expand All @@ -20,7 +25,8 @@
- Refactoring: Line breaks
- Refactoring: Reorder path config to group (non-modular-dependent) image
paths together (and correct code comment)
- Docs: CHANGES clarifications/fixes
- Docs (CHANGES): clarifications/fixes
- Docs (README): Deemphasize unstable embedded editor fixes
- Docs: Versions section (for migrating)
- Docs: More info on `importLocale` for extensions
- Docs: Add code comment re: use of `extIconsPath` in Mathjax
Expand Down
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -92,8 +92,8 @@ incorporating SVGEdit.

## Recent news

- 2018-10-24 Published 3.1.0 (Embedded editor fixes and redirect on modular
page for non-module-support; versions document (for migrating))
- 2018-10-24 Published 3.1.0 (Redirect on modular page for non-module-support;
versions document (for migrating))
- 2018-10-22 Published 3.0.1 (Revert fix affecting polygon selection)
- 2018-10-21 Published 3.0.0 (misc. improvements including centering canvas and
key locale fixes since last RC)
Expand Down
13 changes: 8 additions & 5 deletions dist/index-es.js
Expand Up @@ -17417,12 +17417,15 @@ function SvgCanvas(container, config) {
* @param {Float} [quality] Between 0 and 1
* @param {string} [exportWindowName]
* @param {module:svgcanvas.ImageExportedCallback} [cb]
* @param {PlainObject} [opts]
* @param {boolean} [opts.avoidEvent]
* @fires module:svgcanvas.SvgCanvas#event:exported
* @todo Confirm/fix ICO type
* @returns {Promise} Resolves to {@link module:svgcanvas.ImageExportedResults}
*/

this.rasterExport = function (imgType, quality, exportWindowName, cb) {
var opts = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
var type = imgType === 'ICO' ? 'BMP' : imgType || 'PNG';
var mimeType = 'image/' + type.toLowerCase();

Expand Down Expand Up @@ -17455,7 +17458,10 @@ function SvgCanvas(container, config) {
quality: quality,
exportWindowName: exportWindowName
};
call('exported', obj);

if (!opts.avoidEvent) {
call('exported', obj);
}

if (cb) {
cb(obj);
Expand Down Expand Up @@ -29416,10 +29422,7 @@ editor.init = function () {
var exportHandler = function exportHandler(win, data) {
var issues = data.issues,
exportWindowName = data.exportWindowName;

if (exportWindowName) {
exportWindow = window.open(blankPageObjectURL || '', exportWindowName); // A hack to get the window via JSON-able name without opening a new one
}
exportWindow = window.open(blankPageObjectURL || '', exportWindowName); // A hack to get the window via JSON-able name without opening a new one

if (!exportWindow || exportWindow.closed) {
$$b.alert(uiStrings$1.notification.popupWindowBlocked);
Expand Down
2 changes: 1 addition & 1 deletion dist/index-es.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index-es.min.js.map

Large diffs are not rendered by default.

13 changes: 8 additions & 5 deletions dist/index-umd.js
Expand Up @@ -17423,12 +17423,15 @@
* @param {Float} [quality] Between 0 and 1
* @param {string} [exportWindowName]
* @param {module:svgcanvas.ImageExportedCallback} [cb]
* @param {PlainObject} [opts]
* @param {boolean} [opts.avoidEvent]
* @fires module:svgcanvas.SvgCanvas#event:exported
* @todo Confirm/fix ICO type
* @returns {Promise} Resolves to {@link module:svgcanvas.ImageExportedResults}
*/

this.rasterExport = function (imgType, quality, exportWindowName, cb) {
var opts = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
var type = imgType === 'ICO' ? 'BMP' : imgType || 'PNG';
var mimeType = 'image/' + type.toLowerCase();

Expand Down Expand Up @@ -17461,7 +17464,10 @@
quality: quality,
exportWindowName: exportWindowName
};
call('exported', obj);

if (!opts.avoidEvent) {
call('exported', obj);
}

if (cb) {
cb(obj);
Expand Down Expand Up @@ -29422,10 +29428,7 @@
var exportHandler = function exportHandler(win, data) {
var issues = data.issues,
exportWindowName = data.exportWindowName;

if (exportWindowName) {
exportWindow = window.open(blankPageObjectURL || '', exportWindowName); // A hack to get the window via JSON-able name without opening a new one
}
exportWindow = window.open(blankPageObjectURL || '', exportWindowName); // A hack to get the window via JSON-able name without opening a new one

if (!exportWindow || exportWindow.closed) {
$$b.alert(uiStrings$1.notification.popupWindowBlocked);
Expand Down
2 changes: 1 addition & 1 deletion dist/index-umd.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index-umd.min.js.map

Large diffs are not rendered by default.

24 changes: 15 additions & 9 deletions editor/embedapi-dom.js
Expand Up @@ -30,11 +30,14 @@ 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'
);
svgCanvas.rasterExport('PNG', null, exportWindow && exportWindow.name);
let exportWindow;
if (!isChrome()) {
exportWindow = window.open(
'data:text/html;charset=utf-8,' + encodeURIComponent('<title>' + str + '</title><h1>' + str + '</h1>'),
'svg-edit-exportWindow'
);
}
svgCanvas.rasterExport('PNG', null, exportWindow && exportWindow.name)();
});
}

Expand All @@ -52,6 +55,7 @@ function exportPDF () {
*/

if (isChrome()) {
// Chrome will open an extra window if we follow the approach below
svgCanvas.exportPDF();
} else {
const exportWindow = window.open(
Expand All @@ -64,7 +68,7 @@ function exportPDF () {
}

const frameBase = 'https://raw.githack.com/SVG-Edit/svgedit/master';
// const frameBase = 'http://localhost:8000';
// const frameBase = 'http://localhost:8001';
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 +
Expand All @@ -80,10 +84,12 @@ iframe[0].addEventListener('load', function () {
doc = frame.contentDocument || frame.contentWindow.document;
} catch (err) {
console.log('Blocked from accessing document', err);
return;
}
const mainButton = doc.getElementById('main_button');
mainButton.style.display = 'none';
if (doc) {
// Todo: Provide a way to get this to occur by `postMessage`
const mainButton = doc.getElementById('main_button');
mainButton.style.display = 'none';
}

// Add event handlers now that `svgCanvas` is ready
$('#load').click(loadSvg);
Expand Down
4 changes: 1 addition & 3 deletions editor/svg-editor.js
Expand Up @@ -1738,9 +1738,7 @@ editor.init = function () {
const exportHandler = function (win, data) {
const {issues, exportWindowName} = data;

if (exportWindowName) {
exportWindow = window.open(Utils.blankPageObjectURL || '', exportWindowName); // A hack to get the window via JSON-able name without opening a new one
}
exportWindow = window.open(Utils.blankPageObjectURL || '', exportWindowName); // A hack to get the window via JSON-able name without opening a new one

if (!exportWindow || exportWindow.closed) {
$.alert(uiStrings.notification.popupWindowBlocked);
Expand Down
8 changes: 6 additions & 2 deletions editor/svgcanvas.js
Expand Up @@ -3871,11 +3871,13 @@ let canvg;
* @param {Float} [quality] Between 0 and 1
* @param {string} [exportWindowName]
* @param {module:svgcanvas.ImageExportedCallback} [cb]
* @param {PlainObject} [opts]
* @param {boolean} [opts.avoidEvent]
* @fires module:svgcanvas.SvgCanvas#event:exported
* @todo Confirm/fix ICO type
* @returns {Promise} Resolves to {@link module:svgcanvas.ImageExportedResults}
*/
this.rasterExport = function (imgType, quality, exportWindowName, cb) {
this.rasterExport = function (imgType, quality, exportWindowName, cb, opts = {}) {
const type = imgType === 'ICO' ? 'BMP' : (imgType || 'PNG');
const mimeType = 'image/' + type.toLowerCase();
const {issues, issueCodes} = getIssues();
Expand Down Expand Up @@ -3905,7 +3907,9 @@ this.rasterExport = function (imgType, quality, exportWindowName, cb) {
datauri, bloburl, svg, issues, issueCodes, type: imgType,
mimeType, quality, exportWindowName
};
call('exported', obj);
if (!opts.avoidEvent) {
call('exported', obj);
}
if (cb) {
cb(obj);
}
Expand Down
13 changes: 8 additions & 5 deletions editor/xdomain-svgedit-config-iife.js
Expand Up @@ -17420,12 +17420,15 @@
* @param {Float} [quality] Between 0 and 1
* @param {string} [exportWindowName]
* @param {module:svgcanvas.ImageExportedCallback} [cb]
* @param {PlainObject} [opts]
* @param {boolean} [opts.avoidEvent]
* @fires module:svgcanvas.SvgCanvas#event:exported
* @todo Confirm/fix ICO type
* @returns {Promise} Resolves to {@link module:svgcanvas.ImageExportedResults}
*/

this.rasterExport = function (imgType, quality, exportWindowName, cb) {
var opts = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
var type = imgType === 'ICO' ? 'BMP' : imgType || 'PNG';
var mimeType = 'image/' + type.toLowerCase();

Expand Down Expand Up @@ -17458,7 +17461,10 @@
quality: quality,
exportWindowName: exportWindowName
};
call('exported', obj);

if (!opts.avoidEvent) {
call('exported', obj);
}

if (cb) {
cb(obj);
Expand Down Expand Up @@ -29419,10 +29425,7 @@
var exportHandler = function exportHandler(win, data) {
var issues = data.issues,
exportWindowName = data.exportWindowName;

if (exportWindowName) {
exportWindow = window.open(blankPageObjectURL || '', exportWindowName); // A hack to get the window via JSON-able name without opening a new one
}
exportWindow = window.open(blankPageObjectURL || '', exportWindowName); // A hack to get the window via JSON-able name without opening a new one

if (!exportWindow || exportWindow.closed) {
$$b.alert(uiStrings$1.notification.popupWindowBlocked);
Expand Down
13 changes: 8 additions & 5 deletions svgedit-config-iife.js
Expand Up @@ -17420,12 +17420,15 @@
* @param {Float} [quality] Between 0 and 1
* @param {string} [exportWindowName]
* @param {module:svgcanvas.ImageExportedCallback} [cb]
* @param {PlainObject} [opts]
* @param {boolean} [opts.avoidEvent]
* @fires module:svgcanvas.SvgCanvas#event:exported
* @todo Confirm/fix ICO type
* @returns {Promise} Resolves to {@link module:svgcanvas.ImageExportedResults}
*/

this.rasterExport = function (imgType, quality, exportWindowName, cb) {
var opts = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
var type = imgType === 'ICO' ? 'BMP' : imgType || 'PNG';
var mimeType = 'image/' + type.toLowerCase();

Expand Down Expand Up @@ -17458,7 +17461,10 @@
quality: quality,
exportWindowName: exportWindowName
};
call('exported', obj);

if (!opts.avoidEvent) {
call('exported', obj);
}

if (cb) {
cb(obj);
Expand Down Expand Up @@ -29419,10 +29425,7 @@
var exportHandler = function exportHandler(win, data) {
var issues = data.issues,
exportWindowName = data.exportWindowName;

if (exportWindowName) {
exportWindow = window.open(blankPageObjectURL || '', exportWindowName); // A hack to get the window via JSON-able name without opening a new one
}
exportWindow = window.open(blankPageObjectURL || '', exportWindowName); // A hack to get the window via JSON-able name without opening a new one

if (!exportWindow || exportWindow.closed) {
$$b.alert(uiStrings$1.notification.popupWindowBlocked);
Expand Down

0 comments on commit 283ef0b

Please sign in to comment.