Move back to string messages for postMessage for sake of IE9 (though not with eval); avoid IE9 error with localStorage and missing select icon

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@2590 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Brett Zamir 2013-10-14 01:24:52 +00:00
parent 52419049fe
commit 80c16aa6ef
3 changed files with 36 additions and 16 deletions

View File

@ -82,17 +82,22 @@ function EmbeddedSVGEdit(frame){
}
// Older IE may need a polyfill for addEventListener, but so it would for SVG
window.addEventListener("message", function(e){
if (!e.data || typeof e.data !== "object" || e.data.namespace !== "svg-edit") {
window.addEventListener('message', function(e){
// We accept and post strings for the sake of IE9 support
if (typeof e.data !== 'string') {
return;
}
var data = e.data.result || e.data.error,
cbid = e.data.id;
var data = e.data && JSON.parse(e.data);
if (!data || typeof data !== 'object' || data.namespace !== 'svg-edit') {
return;
}
var result = data.result || data.error,
cbid = data.id;
if(t.callbacks[cbid]){
if(e.data.result){
t.callbacks[cbid](data);
if(data.result){
t.callbacks[cbid](result);
}else{
t.callbacks[cbid](data, "error");
t.callbacks[cbid](result, "error");
}
}
}, false);
@ -105,7 +110,8 @@ EmbeddedSVGEdit.prototype.send = function(name, args, callback){
this.callbacks[cbid] = callback;
setTimeout(function(){ // delay for the callback to be set in case its synchronous
// Todo: Handle non-JSON arguments and return values (undefined, nonfinite numbers, functions, and built-in objects like Date, RegExp), etc.?
t.frame.contentWindow.postMessage({namespace: "svgCanvas", id: cbid, name: name, args: args}, '*');
// We accept and post strings for the sake of IE9 support
t.frame.contentWindow.postMessage(JSON.stringify({namespace: "svgCanvas", id: cbid, name: name, args: args}), '*');
}, 0);
return cbid;
};

View File

@ -68,6 +68,13 @@ svgEditor.addExtension("imagelib", function() {
// Do nothing
return;
}
try { // This block can be removed if embedAPI moves away from a string to an object (if IE9 support not needed)
var res = JSON.parse(response);
if (res.namespace) { // Part of embedAPI communications
return;
}
}
catch (e) {}
var char1 = response.charAt(0);

View File

@ -259,7 +259,7 @@
}
} else {
var name = 'svgedit-' + Editor.curConfig.canvasName;
var cached = window.localStorage.getItem(name);
var cached = window.localStorage && window.localStorage.getItem(name);
if (cached) {
Editor.loadFromString(cached);
}
@ -597,7 +597,9 @@
selectedElement = elems[0];
}
} else {
setTimeout(function () {
setIcon('#tool_select', 'select');
}, 1000);
}
};
@ -4571,16 +4573,21 @@
// Callback handler for embedapi.js
try {
window.addEventListener('message', function(e) {
if (!e.data || typeof e.data !== 'object' || e.data.namespace !== 'svgCanvas') {
// We accept and post strings for the sake of IE9 support
if (typeof e.data !== 'string') {
return;
}
var cbid = e.data.id,
name = e.data.name,
args = e.data.args;
var data = JSON.parse(e.data);
if (!data || typeof data !== 'object' || data.namespace !== 'svgCanvas') {
return;
}
var cbid = data.id,
name = data.name,
args = data.args;
try {
e.source.postMessage({namespace: 'svg-edit', id: cbid, result: svgCanvas[name](args)}, '*');
e.source.postMessage(JSON.stringify({namespace: 'svg-edit', id: cbid, result: svgCanvas[name](args)}), '*');
} catch(err) {
e.source.postMessage({namespace: 'svg-edit', id: cbid, error: err.message}, '*');
e.source.postMessage(JSON.stringify({namespace: 'svg-edit', id: cbid, error: err.message}), '*');
}
}, false);
} catch(err) {