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 // Older IE may need a polyfill for addEventListener, but so it would for SVG
window.addEventListener("message", function(e){ window.addEventListener('message', function(e){
if (!e.data || typeof e.data !== "object" || e.data.namespace !== "svg-edit") { // We accept and post strings for the sake of IE9 support
if (typeof e.data !== 'string') {
return;
}
var data = e.data && JSON.parse(e.data);
if (!data || typeof data !== 'object' || data.namespace !== 'svg-edit') {
return; return;
} }
var data = e.data.result || e.data.error, var result = data.result || data.error,
cbid = e.data.id; cbid = data.id;
if(t.callbacks[cbid]){ if(t.callbacks[cbid]){
if(e.data.result){ if(data.result){
t.callbacks[cbid](data); t.callbacks[cbid](result);
}else{ }else{
t.callbacks[cbid](data, "error"); t.callbacks[cbid](result, "error");
} }
} }
}, false); }, false);
@ -105,7 +110,8 @@ EmbeddedSVGEdit.prototype.send = function(name, args, callback){
this.callbacks[cbid] = callback; this.callbacks[cbid] = callback;
setTimeout(function(){ // delay for the callback to be set in case its synchronous 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.? // 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); }, 0);
return cbid; return cbid;
}; };

View File

@ -68,6 +68,13 @@ svgEditor.addExtension("imagelib", function() {
// Do nothing // Do nothing
return; 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); var char1 = response.charAt(0);

View File

@ -259,7 +259,7 @@
} }
} else { } else {
var name = 'svgedit-' + Editor.curConfig.canvasName; var name = 'svgedit-' + Editor.curConfig.canvasName;
var cached = window.localStorage.getItem(name); var cached = window.localStorage && window.localStorage.getItem(name);
if (cached) { if (cached) {
Editor.loadFromString(cached); Editor.loadFromString(cached);
} }
@ -597,7 +597,9 @@
selectedElement = elems[0]; selectedElement = elems[0];
} }
} else { } else {
setIcon('#tool_select', 'select'); setTimeout(function () {
setIcon('#tool_select', 'select');
}, 1000);
} }
}; };
@ -4571,16 +4573,21 @@
// Callback handler for embedapi.js // Callback handler for embedapi.js
try { try {
window.addEventListener('message', function(e) { 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 data = JSON.parse(e.data);
if (!data || typeof data !== 'object' || data.namespace !== 'svgCanvas') {
return; return;
} }
var cbid = e.data.id, var cbid = data.id,
name = e.data.name, name = data.name,
args = e.data.args; args = data.args;
try { 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) { } 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); }, false);
} catch(err) { } catch(err) {