From cc479ab21d1826f7700f7472e606df16c5978b9c Mon Sep 17 00:00:00 2001 From: Steven Spungin Date: Wed, 3 Jun 2015 11:01:42 -0400 Subject: [PATCH] Fix 'canvas not defined' issue https://github.com/MrRio/jsPDF/issues/503 --- libs/html2pdf.js | 2 +- libs/require/config.js | 194 +++++++++++++++++++++-------------------- 2 files changed, 100 insertions(+), 96 deletions(-) diff --git a/libs/html2pdf.js b/libs/html2pdf.js index da22cc393..7c22e10d5 100644 --- a/libs/html2pdf.js +++ b/libs/html2pdf.js @@ -6,7 +6,7 @@ * http://opensource.org/licenses/mit-license */ -html2pdf = function(html,pdf,callback) { +function html2pdf (html,pdf,callback) { var canvas = pdf.canvas; if (!canvas) { alert('jsPDF canvas plugin not installed'); diff --git a/libs/require/config.js b/libs/require/config.js index 5918629e2..8639b868e 100644 --- a/libs/require/config.js +++ b/libs/require/config.js @@ -13,103 +13,107 @@ * This allows a host page to simply include require.js and bootstrap the page with a single require statement. */ -if (typeof require_baseUrl_override === 'undefined'){ - require_baseUrl_override = '../'; -} - -require.config({ - baseUrl: require_baseUrl_override, - shim:{ - 'plugins/standard_fonts_metrics':{ - deps:[ - 'jspdf' - ] - }, - - 'plugins/split_text_to_size':{ - deps:[ - 'jspdf' - ] - }, - - 'plugins/annotations' : { - deps:[ - 'jspdf', - 'plugins/standard_fonts_metrics', - 'plugins/split_text_to_size' - ] - }, +if (typeof require === 'object') { - 'plugins/outline':{ - deps:[ - 'jspdf' - ] - }, - - 'plugins/addimage':{ - deps:[ - 'jspdf' - ] - }, - - 'plugins/png_support':{ - deps:[ + if (typeof require_baseUrl_override === 'undefined'){ + require_baseUrl_override = '../'; + } + + require.config({ + baseUrl: require_baseUrl_override, + shim:{ + 'plugins/standard_fonts_metrics':{ + deps:[ + 'jspdf' + ] + }, + + 'plugins/split_text_to_size':{ + deps:[ + 'jspdf' + ] + }, + + 'plugins/annotations' : { + deps:[ 'jspdf', - 'libs/png_support/png', - 'libs/png_support/zlib' - ] - }, - - 'plugins/from_html':{ - deps:[ - 'jspdf' - ] - }, - - 'plugins/context2d':{ - deps:[ + 'plugins/standard_fonts_metrics', + 'plugins/split_text_to_size' + ] + }, + + 'plugins/outline':{ + deps:[ + 'jspdf' + ] + }, + + 'plugins/addimage':{ + deps:[ + 'jspdf' + ] + }, + + 'plugins/png_support':{ + deps:[ + 'jspdf', + 'libs/png_support/png', + 'libs/png_support/zlib' + ] + }, + + 'plugins/from_html':{ + deps:[ + 'jspdf' + ] + }, + + 'plugins/context2d':{ + deps:[ + 'jspdf', + 'plugins/png_support', + 'plugins/addimage', + 'libs/css_colors' + ] + }, + + 'libs/html2canvas/dist/html2canvas':{ + deps:[ + 'jspdf' + ] + }, + + 'plugins/canvas' : { + deps:[ + 'jspdf' + ] + }, + + 'html2pdf' : { + deps:[ 'jspdf', + 'plugins/standard_fonts_metrics', + 'plugins/split_text_to_size', 'plugins/png_support', - 'plugins/addimage', - 'libs/css_colors' - ] - }, - - 'libs/html2canvas/dist/html2canvas':{ - deps:[ - 'jspdf' - ] - }, - - 'plugins/canvas' : { - deps:[ - 'jspdf' - ] - }, - - 'html2pdf' : { - deps:[ - 'jspdf', - 'plugins/standard_fonts_metrics', - 'plugins/split_text_to_size', - 'plugins/png_support', - 'plugins/context2d', - 'plugins/canvas', - 'plugins/annotations', + 'plugins/context2d', + 'plugins/canvas', + 'plugins/annotations', + + 'libs/html2canvas/dist/html2canvas' + ] + }, + + 'test/test_harness':{ + deps:[ + 'jspdf', + 'jspdf.plugin.standard_fonts_metrics', + 'jspdf.plugin.split_text_to_size' + ] + } + }, + paths:{ + 'html2pdf': 'libs/html2pdf' + } + }); - 'libs/html2canvas/dist/html2canvas' - ] - }, - - 'test/test_harness':{ - deps:[ - 'jspdf', - 'jspdf.plugin.standard_fonts_metrics', - 'jspdf.plugin.split_text_to_size' - ] - } - }, - paths:{ - 'html2pdf': 'libs/html2pdf' - } -}); +}