- 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)
- 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
This commit is contained in:
@@ -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)();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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(
|
||||
@@ -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 +
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -17458,7 +17461,10 @@
|
||||
quality: quality,
|
||||
exportWindowName: exportWindowName
|
||||
};
|
||||
call('exported', obj);
|
||||
|
||||
if (!opts.avoidEvent) {
|
||||
call('exported', obj);
|
||||
}
|
||||
|
||||
if (cb) {
|
||||
cb(obj);
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user