Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade jsdom #2547

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ node_js:
- "0.12"
- "0.11"
- "0.10"
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.8
script: 'npm run build && npm run test && npm run lint && npm run lint_tests'
before_install:
- sudo apt-get install -qq libgif-dev libpng-dev libjpeg8-dev libpango1.0-dev libcairo2-dev
- if [[ $TRAVIS_OS_NAME == "linux" ]]; then export CXX=g++-4.8; fi
9 changes: 3 additions & 6 deletions HEADER.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@ else {
// assume we're running under node.js when document/window are not present
fabric.document = require("jsdom")
.jsdom("<!DOCTYPE html><html><head></head><body></body></html>");

if (fabric.document.createWindow) {
fabric.window = fabric.document.createWindow();
} else {
fabric.window = fabric.document.parentWindow;
}

// assign window
fabric.window = fabric.document.defaultView;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
},
"dependencies": {
"canvas": "1.2.x",
"jsdom": "1.1.x",
"jsdom": "6.5.x",
"xmldom": "0.1.x"
},
"devDependencies": {
Expand Down
5 changes: 3 additions & 2 deletions src/mixins/canvas_dataurl_exporter.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,21 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati

var croppedCanvasEl,
croppedCtx,
croppedNodeCanvasEl,
shouldCrop = 'left' in cropping ||
'top' in cropping ||
'width' in cropping ||
'height' in cropping;

if (shouldCrop) {

croppedCanvasEl = fabric.util.createCanvasElement();
croppedNodeCanvasEl = fabric.isLikelyNode ? canvasEl._nodeCanvas : canvasEl;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks like a big change.
or am i wrong? looks like that canvasEl is no more the same between browser and nodecanvas

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a big change. Canvas was never the same between browser and node. The previous version of jsdom just returned the canvas when you did fabric.document.createElement('canvas'), but in the new version of jsdom, they create a wrapper around the canvas returned, but have it accessible via _nodeCanvas. (https://github.com/tmpvar/jsdom/blob/master/lib/jsdom/level2/html.js#L1472)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i was thinking about other places where we use the canvasEl directly. But i didn't found yet.
Other places we use just the context. Maybe in (StaticCanvas / Canvas).getElement() we should make the same check and return.

Also we use
in other places like:
https://github.com/kangax/fabric.js/blob/master/dist/fabric.js#L780
https://github.com/kangax/fabric.js/blob/master/dist/fabric.js#L6246
https://github.com/kangax/fabric.js/blob/master/dist/fabric.js#L8052

Some of them returns the element directly.

croppedCtx = croppedCanvasEl.getContext('2d');

croppedCanvasEl.width = cropping.width || this.width;
croppedCanvasEl.height = cropping.height || this.height;

croppedCtx.drawImage(canvasEl, -cropping.left || 0, -cropping.top || 0);
croppedCtx.drawImage(croppedNodeCanvasEl, -cropping.left || 0, -cropping.top || 0);
}

return croppedCanvasEl;
Expand Down