Skip to content

Commit 6565fac

Browse files
committed
Merge pull request #30 from DavidWells/master
Fix for node server side react rendering. window undefined
2 parents a195ee4 + 126242a commit 6565fac

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

lib/draggable.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,17 @@ function matchesSelector(el, selector) {
4949
}
5050

5151
// @credits: http://stackoverflow.com/questions/4817029/whats-the-best-way-to-detect-a-touch-screen-device-using-javascript/4819886#4819886
52-
var isTouchDevice = 'ontouchstart' in window // works on most browsers
52+
/* Conditional to fix node server side rendering of component */
53+
if (typeof window === 'undefined') {
54+
// Do Node Stuff
55+
var isTouchDevice = false;
56+
} else {
57+
// Do Browser Stuff
58+
var isTouchDevice = 'ontouchstart' in window // works on most browsers
5359
|| 'onmsgesturechange' in window; // works on ie10 on ms surface
5460

61+
}
62+
5563
// look ::handleDragStart
5664
//function isMultiTouch(e) {
5765
// return e.touches && Array.isArray(e.touches) && e.touches.length > 1
@@ -402,7 +410,7 @@ module.exports = React.createClass({
402410
var directionY = clientY < parseInt(this.state.clientY, 10) ? -1 : 1;
403411

404412
clientX = Math.abs(clientX - parseInt(this.state.clientX, 10)) >= this.props.grid[0]
405-
? (parseInt(this.state.clientX, 10) + (this.props.grid[0] * directionX))
413+
? (parseInt(this.state.clientX, 10) + (this.props.grid[0] * directionX))
406414
: this.state.clientX;
407415

408416
clientY = Math.abs(clientY - parseInt(this.state.clientY, 10)) >= this.props.grid[1]

0 commit comments

Comments
 (0)