Allow override of jsPDF saveAs function (jsPDF work not complete however); apply fix for issue #1209 on push buttons; fix comment

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@2839 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Brett Zamir 2014-05-08 03:47:14 +00:00
parent 35e171a15f
commit 978315f944
1 changed files with 37 additions and 32 deletions

View File

@ -22,7 +22,7 @@
TODOS
1. JSDoc
*/
var saveAs;
(function() {
if (window.svgEditor) {
@ -396,7 +396,7 @@ TODOS
* opts.open's responsibilities are:
* - invoke a file chooser dialog in 'open' mode
* - let user pick a SVG file
* - calls setCanvas.setSvgString() with the string contents of that file
* - calls svgCanvas.setSvgString() with the string contents of that file
* opts.save's responsibilities are:
* - accept the string contents of the current document
* - invoke a file chooser dialog in 'save' mode
@ -1079,41 +1079,46 @@ TODOS
};
// Export global for use by jsPDF
saveAs = function (blob, options) {
var blobUrl = URL.createObjectURL(blob);
try {
// This creates a bookmarkable data URL,
// but it doesn't currently work in
// Firefox, and although it works in Chrome,
// Chrome doesn't make the full "data:" URL
// visible unless you right-click to "Inspect
// element" and then right-click on the element
// to "Copy link address".
var xhr = new XMLHttpRequest();
xhr.responseType = 'blob';
xhr.onload = function() {
var recoveredBlob = xhr.response;
var reader = new FileReader();
reader.onload = function() {
var blobAsDataUrl = reader.result;
exportWindow.location.href = blobAsDataUrl;
if (!saveAs) {
saveAs = function (blob, options) {
var blobUrl = URL.createObjectURL(blob);
try {
// This creates a bookmarkable data URL,
// but it doesn't currently work in
// Firefox, and although it works in Chrome,
// Chrome doesn't make the full "data:" URL
// visible unless you right-click to "Inspect
// element" and then right-click on the element
// to "Copy link address".
var xhr = new XMLHttpRequest();
xhr.responseType = 'blob';
xhr.onload = function() {
var recoveredBlob = xhr.response;
var reader = new FileReader();
reader.onload = function() {
var blobAsDataUrl = reader.result;
exportWindow.location.href = blobAsDataUrl;
};
reader.readAsDataURL(recoveredBlob);
};
reader.readAsDataURL(recoveredBlob);
};
xhr.open('GET', blobUrl);
xhr.send();
}
catch (e) {
exportWindow.location.href = blobUrl;
}
};
xhr.open('GET', blobUrl);
xhr.send();
}
catch (e) {
exportWindow.location.href = blobUrl;
}
};
}
var exportHandler = function(win, data) {
var issues = data.issues,
type = data.type || 'PNG',
exportWindowName = data.exportWindowName,
dataURLType = (type === 'ICO' ? 'BMP' : type).toLowerCase();
exportWindow = window.open('', data.exportWindowName); // A hack to get the window via JSON-able name without opening a new one
if (exportWindowName) {
exportWindow = window.open('', exportWindowName); // A hack to get the window via JSON-able name without opening a new one
}
if (!$('#export_canvas').length) {
$('<canvas>', {id: 'export_canvas'}).hide().appendTo('body');
}
@ -3981,8 +3986,8 @@ TODOS
var all_tools = '';
var cur_class = 'tool_button_current';
$.each(toolnames, function(i,item) {
all_tools += '#tool_' + item + (i == toolnames.length-1 ? ',' : '');
$.each(toolnames, function(i, item) {
all_tools += (i ? ',' : '') + '#tool_' + item;
});
$(all_tools).mousedown(function() {