Abstract conditional script loading and allow jsPDF to load as needed (as with canvg); update jsPDF

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@2847 eee81c28-f429-11dd-99c0-75d572ba1ddd
This commit is contained in:
Brett Zamir
2014-05-22 02:34:37 +00:00
parent 4ffd994c49
commit 9bda441c77
3 changed files with 1712 additions and 1878 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -25,10 +25,6 @@
<script src="spinbtn/JQuerySpinBtn.min.js"></script>
<script src="touch.js"></script>
<script src="jspdf/underscore-min.js"></script>
<script src="jspdf/jspdf.js"></script>
<script src="jspdf/jspdf.plugin.svgToPdf.js"></script>
<!--{if svg_edit_release}>
<script src="svgedit.compiled.js"></script>
<!{else}-->

View File

@@ -202,19 +202,37 @@ var saveAs;
}
}
function checkCanvg (callCanvg) {
return function (win, data) {
if (window.canvg) {
callCanvg(win, data);
} else { // Might not be set up yet
$.getScript('canvg/rgbcolor.js', function() {
$.getScript('canvg/canvg.js', function() {
callCanvg(win, data);
});
});
/**
* @param {string} globalCheck A global which can be used to determine if the script is already loaded
* @param {array} scripts An array of scripts to preload (in order)
* @param {function} cb The callback to execute upon load.
*/
function executeAfterLoads (globalCheck, scripts, cb) {
return function () {
var args = arguments;
function endCallback () {
cb.apply(null, args);
}
if (window[globalCheck]) {
endCallback();
}
else {
scripts.reduceRight(function (oldFunc, script) {
return function () {
$.getScript(script, oldFunc);
};
}, endCallback)();
}
};
}
function checkCanvg (callCanvg) {
return executeAfterLoads('canvg', ['canvg/rgbcolor.js', 'canvg/canvg.js'], callCanvg);
}
function executeJSPDF (callJSPDF) {
return executeAfterLoads('jsPDF', ['jspdf/underscore-min.js', 'jspdf/jspdf.js', 'jspdf/jspdf.plugin.svgToPdf.js'], callJSPDF)();
}
/**
* EXPORTS
@@ -1127,17 +1145,20 @@ var saveAs;
var res = svgCanvas.getResolution();
var orientation = res.w > res.h ? 'landscape' : 'portrait';
var units = 'pt'; // curConfig.baseUnit; // We could use baseUnit, but that is presumably not intended for export purposes
var doc = new jsPDF(orientation, units, [res.w, res.h]); // Todo: Give options to use predefined jsPDF formats like "a4", etc. from pull-down (with option to keep customizable)
var docTitle = svgCanvas.getDocumentTitle();
doc.setProperties({
title: docTitle/*,
subject: '',
author: '',
keywords: '',
creator: ''*/
executeJSPDF(function () {
var doc = new jsPDF(orientation, units, [res.w, res.h]); // Todo: Give options to use predefined jsPDF formats like "a4", etc. from pull-down (with option to keep customizable)
var docTitle = svgCanvas.getDocumentTitle();
doc.setProperties({
title: docTitle/*,
subject: '',
author: '',
keywords: '',
creator: ''*/
});
svgElementToPdf(data.svg, doc, {});
doc.save(docTitle + '.pdf');
});
svgElementToPdf(data.svg, doc, {});
doc.save(docTitle + '.pdf');
return;
}
c.width = svgCanvas.contentW;