Skip to content

Commit 4b37909

Browse files
committed
Fix support for requirejs/amd
1 parent 98ee306 commit 4b37909

File tree

6 files changed

+39
-6
lines changed

6 files changed

+39
-6
lines changed

.jshintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@
1515
"globals": {
1616
"jQuery": true
1717
},
18-
"predef": ["-Promise"]
18+
"predef": ["-Promise", "define"]
1919
}

dist/html2canvas.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1978,10 +1978,18 @@ html2canvas.NodeContainer = NodeContainer;
19781978
html2canvas.log = log;
19791979
html2canvas.utils = utils;
19801980

1981-
module.exports = (typeof(document) === "undefined" || typeof(Object.create) !== "function" || typeof(document.createElement("canvas").getContext) !== "function") ? function() {
1981+
var html2canvasExport = (typeof(document) === "undefined" || typeof(Object.create) !== "function" || typeof(document.createElement("canvas").getContext) !== "function") ? function() {
19821982
return Promise.reject("No canvas support");
19831983
} : html2canvas;
19841984

1985+
module.exports = html2canvasExport;
1986+
1987+
if (typeof(define) === 'function' && define.amd) {
1988+
define('html2canvas', [], function() {
1989+
return html2canvasExport;
1990+
});
1991+
}
1992+
19851993
function renderDocument(document, options, windowWidth, windowHeight, html2canvasIndex) {
19861994
return createWindowClone(document, document, windowWidth, windowHeight, options, document.defaultView.pageXOffset, document.defaultView.pageYOffset).then(function(container) {
19871995
log("Document cloned");

dist/html2canvas.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"humanize-duration": "^2.0.1",
4040
"lodash": "^2.4.1",
4141
"png-js": ">= 0.1.1",
42+
"requirejs": "^2.1.20",
4243
"wd": "^0.2.21"
4344
},
4445
"scripts": {

src/core.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,18 @@ html2canvas.NodeContainer = NodeContainer;
5757
html2canvas.log = log;
5858
html2canvas.utils = utils;
5959

60-
module.exports = (typeof(document) === "undefined" || typeof(Object.create) !== "function" || typeof(document.createElement("canvas").getContext) !== "function") ? function() {
60+
var html2canvasExport = (typeof(document) === "undefined" || typeof(Object.create) !== "function" || typeof(document.createElement("canvas").getContext) !== "function") ? function() {
6161
return Promise.reject("No canvas support");
6262
} : html2canvas;
6363

64+
module.exports = html2canvasExport;
65+
66+
if (typeof(define) === 'function' && define.amd) {
67+
define('html2canvas', [], function() {
68+
return html2canvasExport;
69+
});
70+
}
71+
6472
function renderDocument(document, options, windowWidth, windowHeight, html2canvasIndex) {
6573
return createWindowClone(document, document, windowWidth, windowHeight, options, document.defaultView.pageXOffset, document.defaultView.pageYOffset).then(function(container) {
6674
log("Document cloned");

tests/node/package.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
11
var assert = require('assert');
2+
var path = require('path');
23
var html2canvas = require('../../');
34

45
describe("Package", function() {
56
it("should have html2canvas defined", function() {
67
assert.equal(typeof(html2canvas), "function");
78
});
89
});
10+
11+
describe.only("requirejs", function() {
12+
var requirejs = require('requirejs');
13+
14+
requirejs.config({
15+
baseUrl: path.resolve(__dirname, '../../dist')
16+
});
17+
18+
it("should have html2canvas defined", function(done) {
19+
requirejs(['html2canvas'], function(h2c) {
20+
assert.equal(typeof(h2c), "function");
21+
done();
22+
});
23+
});
24+
});

0 commit comments

Comments
 (0)