Hopefully prevent PNG export popup by opening a placeholder window first

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1539 eee81c28-f429-11dd-99c0-75d572ba1ddd
This commit is contained in:
Alexis Deveria
2010-04-22 15:22:01 +00:00
parent d0ec5bd9d0
commit 1f00603359

View File

@@ -400,7 +400,8 @@
path = svgCanvas.pathActions, path = svgCanvas.pathActions,
default_img_url = curConfig.imgPath + "logo.png", default_img_url = curConfig.imgPath + "logo.png",
workarea = $("#workarea"), workarea = $("#workarea"),
show_save_warning = false; show_save_warning = false,
exportWindow = null;
// This sets up alternative dialog boxes. They mostly work the same way as // This sets up alternative dialog boxes. They mostly work the same way as
// their UI counterparts, expect instead of returning the result, a callback // their UI counterparts, expect instead of returning the result, a callback
@@ -520,7 +521,6 @@
}; };
var exportHandler = function(window, data) { var exportHandler = function(window, data) {
var issues = data.issues; var issues = data.issues;
if(!$('#export_canvas').length) { if(!$('#export_canvas').length) {
@@ -532,7 +532,7 @@
c.height = svgCanvas.contentH; c.height = svgCanvas.contentH;
canvg(c, data.svg); canvg(c, data.svg);
var datauri = c.toDataURL('image/png'); var datauri = c.toDataURL('image/png');
var win = window.open(datauri); exportWindow.location.href = datauri;
var note = 'Select "Save As..." in your browser to save this image as a PNG file.'; var note = 'Select "Save As..." in your browser to save this image as a PNG file.';
@@ -542,7 +542,7 @@
var pre = "\n \u2022 "; var pre = "\n \u2022 ";
note += ("\n\nAlso note these issues:" + pre + issues.join(pre)); note += ("\n\nAlso note these issues:" + pre + issues.join(pre));
} }
win.alert(note); exportWindow.alert(note);
}; };
// called when we've selected a different element // called when we've selected a different element
@@ -2037,32 +2037,19 @@
}; };
var clickExport = function() { var clickExport = function() {
// Open placeholder window (prevents popup)
var str = "Loading image, please wait...";
exportWindow = window.open("data:text/html;charset=utf-8,<title>" + str + "<\/title><h1>" + str + "<\/h1>");
if(window.canvg) { if(window.canvg) {
svgCanvas.rasterExport(); svgCanvas.rasterExport();
return;
} else { } else {
$.getScript('canvg/rgbcolor.js', function() { $.getScript('canvg/rgbcolor.js', function() {
$.getScript('canvg/canvg.js'); $.getScript('canvg/canvg.js', function() {
// Would normally run svgCanvas.rasterExport() here, svgCanvas.rasterExport();
// but that causes popup dialog box });
}); });
} }
var count = 0;
// Run export when window.canvg is created
var timer = setInterval(function() {
count++;
if(window.canvg) {
clearInterval(timer);
svgCanvas.rasterExport();
return;
}
if(count > 100) { // 5 seconds
clearInterval(timer);
$.alert("Error: Failed to load CanVG script");
}
}, 50);
} }
// by default, svgCanvas.open() is a no-op. // by default, svgCanvas.open() is a no-op.