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