Fix support for requirejs/amd

This commit is contained in:
Niklas von Hertzen 2015-08-30 02:27:38 +03:00
parent 98ee30643a
commit 4b37909f09
6 changed files with 39 additions and 6 deletions

View File

@ -15,5 +15,5 @@
"globals": { "globals": {
"jQuery": true "jQuery": true
}, },
"predef": ["-Promise"] "predef": ["-Promise", "define"]
} }

10
dist/html2canvas.js vendored
View File

@ -1978,10 +1978,18 @@ html2canvas.NodeContainer = NodeContainer;
html2canvas.log = log; html2canvas.log = log;
html2canvas.utils = utils; html2canvas.utils = utils;
module.exports = (typeof(document) === "undefined" || typeof(Object.create) !== "function" || typeof(document.createElement("canvas").getContext) !== "function") ? function() { var html2canvasExport = (typeof(document) === "undefined" || typeof(Object.create) !== "function" || typeof(document.createElement("canvas").getContext) !== "function") ? function() {
return Promise.reject("No canvas support"); return Promise.reject("No canvas support");
} : html2canvas; } : html2canvas;
module.exports = html2canvasExport;
if (typeof(define) === 'function' && define.amd) {
define('html2canvas', [], function() {
return html2canvasExport;
});
}
function renderDocument(document, options, windowWidth, windowHeight, html2canvasIndex) { function renderDocument(document, options, windowWidth, windowHeight, html2canvasIndex) {
return createWindowClone(document, document, windowWidth, windowHeight, options, document.defaultView.pageXOffset, document.defaultView.pageYOffset).then(function(container) { return createWindowClone(document, document, windowWidth, windowHeight, options, document.defaultView.pageXOffset, document.defaultView.pageYOffset).then(function(container) {
log("Document cloned"); log("Document cloned");

File diff suppressed because one or more lines are too long

View File

@ -39,6 +39,7 @@
"humanize-duration": "^2.0.1", "humanize-duration": "^2.0.1",
"lodash": "^2.4.1", "lodash": "^2.4.1",
"png-js": ">= 0.1.1", "png-js": ">= 0.1.1",
"requirejs": "^2.1.20",
"wd": "^0.2.21" "wd": "^0.2.21"
}, },
"scripts": { "scripts": {

View File

@ -57,10 +57,18 @@ html2canvas.NodeContainer = NodeContainer;
html2canvas.log = log; html2canvas.log = log;
html2canvas.utils = utils; html2canvas.utils = utils;
module.exports = (typeof(document) === "undefined" || typeof(Object.create) !== "function" || typeof(document.createElement("canvas").getContext) !== "function") ? function() { var html2canvasExport = (typeof(document) === "undefined" || typeof(Object.create) !== "function" || typeof(document.createElement("canvas").getContext) !== "function") ? function() {
return Promise.reject("No canvas support"); return Promise.reject("No canvas support");
} : html2canvas; } : html2canvas;
module.exports = html2canvasExport;
if (typeof(define) === 'function' && define.amd) {
define('html2canvas', [], function() {
return html2canvasExport;
});
}
function renderDocument(document, options, windowWidth, windowHeight, html2canvasIndex) { function renderDocument(document, options, windowWidth, windowHeight, html2canvasIndex) {
return createWindowClone(document, document, windowWidth, windowHeight, options, document.defaultView.pageXOffset, document.defaultView.pageYOffset).then(function(container) { return createWindowClone(document, document, windowWidth, windowHeight, options, document.defaultView.pageXOffset, document.defaultView.pageYOffset).then(function(container) {
log("Document cloned"); log("Document cloned");

View File

@ -1,4 +1,5 @@
var assert = require('assert'); var assert = require('assert');
var path = require('path');
var html2canvas = require('../../'); var html2canvas = require('../../');
describe("Package", function() { describe("Package", function() {
@ -6,3 +7,18 @@ describe("Package", function() {
assert.equal(typeof(html2canvas), "function"); assert.equal(typeof(html2canvas), "function");
}); });
}); });
describe.only("requirejs", function() {
var requirejs = require('requirejs');
requirejs.config({
baseUrl: path.resolve(__dirname, '../../dist')
});
it("should have html2canvas defined", function(done) {
requirejs(['html2canvas'], function(h2c) {
assert.equal(typeof(h2c), "function");
done();
});
});
});