- Fix (Embedded API): Cross-domain may fail to even access `origin` or `contentDocument`

- Fix (Embedded API): Avoid adding URL to iframe src if there are no arguments
- Fix (Cross-domain usage): Recover from exceptions with `localStorage`
- Docs (JSDoc): Missing function
master
Brett Zamir 2018-05-30 19:39:00 +08:00
parent f2b1a1ff0c
commit d173df34d2
10 changed files with 76 additions and 22 deletions

23
dist/index-es.js vendored
View File

@ -19832,6 +19832,11 @@ var SvgCanvas = function SvgCanvas(container, config) {
$$9('#cmenu_canvas').enableContextMenuItems('#paste,#paste_in_place'); $$9('#cmenu_canvas').enableContextMenuItems('#paste,#paste_in_place');
}; };
/**
* @param {"in_place"|"point"|undefined} type
* @param {Number|undefined} x Expected if type is "point"
* @param {Number|undefined} y Expected if type is "point"
*/
this.pasteElements = function (type, x, y) { this.pasteElements = function (type, x, y) {
var cb = JSON.parse(localStorage.getItem('svgedit_clipboard')); var cb = JSON.parse(localStorage.getItem('svgedit_clipboard'));
var len = cb.length; var len = cb.length;
@ -30302,11 +30307,21 @@ editor.init = function () {
$$b('#cmenu_canvas li').disableContextMenu(); $$b('#cmenu_canvas li').disableContextMenu();
canvMenu.enableContextMenuItems('#delete,#cut,#copy'); canvMenu.enableContextMenuItems('#delete,#cut,#copy');
canvMenu[(localStorage.getItem('svgedit_clipboard') ? 'en' : 'dis') + 'ableContextMenuItems']('#paste,#paste_in_place'); function enableOrDisableClipboard() {
window.addEventListener('storage', function (e) { var svgeditClipboard = void 0;
if (e.key !== 'svgedit_clipboard') return; try {
svgeditClipboard = localStorage.getItem('svgedit_clipboard');
} catch (err) {}
canvMenu[(svgeditClipboard ? 'en' : 'dis') + 'ableContextMenuItems']('#paste,#paste_in_place');
}
enableOrDisableClipboard();
canvMenu[(localStorage.getItem('svgedit_clipboard') ? 'en' : 'dis') + 'ableContextMenuItems']('#paste,#paste_in_place'); window.addEventListener('storage', function (e) {
if (e.key !== 'svgedit_clipboard') {
return;
}
enableOrDisableClipboard();
}); });
window.addEventListener('beforeunload', function (e) { window.addEventListener('beforeunload', function (e) {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

23
dist/index-umd.js vendored
View File

@ -19838,6 +19838,11 @@
$$9('#cmenu_canvas').enableContextMenuItems('#paste,#paste_in_place'); $$9('#cmenu_canvas').enableContextMenuItems('#paste,#paste_in_place');
}; };
/**
* @param {"in_place"|"point"|undefined} type
* @param {Number|undefined} x Expected if type is "point"
* @param {Number|undefined} y Expected if type is "point"
*/
this.pasteElements = function (type, x, y) { this.pasteElements = function (type, x, y) {
var cb = JSON.parse(localStorage.getItem('svgedit_clipboard')); var cb = JSON.parse(localStorage.getItem('svgedit_clipboard'));
var len = cb.length; var len = cb.length;
@ -30308,11 +30313,21 @@
$$b('#cmenu_canvas li').disableContextMenu(); $$b('#cmenu_canvas li').disableContextMenu();
canvMenu.enableContextMenuItems('#delete,#cut,#copy'); canvMenu.enableContextMenuItems('#delete,#cut,#copy');
canvMenu[(localStorage.getItem('svgedit_clipboard') ? 'en' : 'dis') + 'ableContextMenuItems']('#paste,#paste_in_place'); function enableOrDisableClipboard() {
window.addEventListener('storage', function (e) { var svgeditClipboard = void 0;
if (e.key !== 'svgedit_clipboard') return; try {
svgeditClipboard = localStorage.getItem('svgedit_clipboard');
} catch (err) {}
canvMenu[(svgeditClipboard ? 'en' : 'dis') + 'ableContextMenuItems']('#paste,#paste_in_place');
}
enableOrDisableClipboard();
canvMenu[(localStorage.getItem('svgedit_clipboard') ? 'en' : 'dis') + 'ableContextMenuItems']('#paste,#paste_in_place'); window.addEventListener('storage', function (e) {
if (e.key !== 'svgedit_clipboard') {
return;
}
enableOrDisableClipboard();
}); });
window.addEventListener('beforeunload', function (e) { window.addEventListener('beforeunload', function (e) {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -62,13 +62,21 @@ $('#exportPNG').click(exportPNG);
$('#exportPDF').click(exportPDF); $('#exportPDF').click(exportPDF);
const iframe = $('<iframe src="svg-editor-es.html?extensions=ext-xdomain-messaging.js' + const iframe = $('<iframe src="svg-editor-es.html?extensions=ext-xdomain-messaging.js' +
window.location.href.replace(/\?(.*)$/, '&$1') + // Append arguments to this file onto the iframe (location.href.includes('?')
? location.href.replace(/\?(.*)$/, '&$1')
: '') + // Append arguments to this file onto the iframe
'" width="900px" height="600px" id="svgedit""></iframe>' '" width="900px" height="600px" id="svgedit""></iframe>'
); );
iframe[0].addEventListener('load', function () { iframe[0].addEventListener('load', function () {
svgCanvas = new EmbeddedSVGEdit(frame); svgCanvas = new EmbeddedSVGEdit(frame);
// Hide main button, as we will be controlling new, load, save, etc. from the host document // Hide main button, as we will be controlling new, load, save, etc. from the host document
const doc = frame.contentDocument || frame.contentWindow.document; let doc;
try {
doc = frame.contentDocument || frame.contentWindow.document;
} catch (err) {
console.log('Blocked from accessing document');
return;
}
const mainButton = doc.getElementById('main_button'); const mainButton = doc.getElementById('main_button');
mainButton.style.display = 'none'; mainButton.style.display = 'none';
}); });

View File

@ -297,7 +297,12 @@ class EmbeddedSVGEdit {
* made compatile with all API functionality * made compatile with all API functionality
*/ */
// We accept and post strings for the sake of IE9 support // We accept and post strings for the sake of IE9 support
if (window.location.origin === t.frame.contentWindow.location.origin) { let sameOrigin = false;
try {
sameOrigin = window.location.origin === t.frame.contentWindow.location.origin;
} catch (err) {}
if (sameOrigin) {
// Although we do not really need this API if we are working same // Although we do not really need this API if we are working same
// domain, it could allow us to write in a way that would work // domain, it could allow us to write in a way that would work
// cross-domain as well, assuming we stick to the argument limitations // cross-domain as well, assuming we stick to the argument limitations

View File

@ -4951,15 +4951,21 @@ editor.init = function () {
$('#cmenu_canvas li').disableContextMenu(); $('#cmenu_canvas li').disableContextMenu();
canvMenu.enableContextMenuItems('#delete,#cut,#copy'); canvMenu.enableContextMenuItems('#delete,#cut,#copy');
canvMenu[(localStorage.getItem('svgedit_clipboard') ? 'en' : 'dis') + 'ableContextMenuItems']( function enableOrDisableClipboard () {
let svgeditClipboard;
try {
svgeditClipboard = localStorage.getItem('svgedit_clipboard');
} catch (err) {}
canvMenu[(svgeditClipboard ? 'en' : 'dis') + 'ableContextMenuItems'](
'#paste,#paste_in_place' '#paste,#paste_in_place'
); );
window.addEventListener('storage', function (e) { }
if (e.key !== 'svgedit_clipboard') return; enableOrDisableClipboard();
canvMenu[(localStorage.getItem('svgedit_clipboard') ? 'en' : 'dis') + 'ableContextMenuItems']( window.addEventListener('storage', function (e) {
'#paste,#paste_in_place' if (e.key !== 'svgedit_clipboard') { return; }
);
enableOrDisableClipboard();
}); });
window.addEventListener('beforeunload', function (e) { window.addEventListener('beforeunload', function (e) {

View File

@ -5270,6 +5270,11 @@ this.copySelectedElements = function () {
$('#cmenu_canvas').enableContextMenuItems('#paste,#paste_in_place'); $('#cmenu_canvas').enableContextMenuItems('#paste,#paste_in_place');
}; };
/**
* @param {"in_place"|"point"|undefined} type
* @param {Number|undefined} x Expected if type is "point"
* @param {Number|undefined} y Expected if type is "point"
*/
this.pasteElements = function (type, x, y) { this.pasteElements = function (type, x, y) {
let cb = JSON.parse(localStorage.getItem('svgedit_clipboard')); let cb = JSON.parse(localStorage.getItem('svgedit_clipboard'));
let len = cb.length; let len = cb.length;