Skip to content

Commit e55562f

Browse files
committed
further fixes for node.
1 parent 5967a29 commit e55562f

File tree

4 files changed

+39
-30
lines changed

4 files changed

+39
-30
lines changed

dist/Thumb.js

+19-14
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,18 @@ function (_React$Component) {
7575

7676
_this.dragStartOffsetX = ev.clientX - rect.left - rect.width / 2;
7777
_this.dragStartOffsetY = ev.clientY - rect.top - rect.height / 2;
78-
document.addEventListener("mousemove", _this.handleDragEvent);
79-
document.addEventListener("mouseup", _this.handleDragEnd);
80-
_this.prevUserSelect = document.body.style.userSelect;
81-
document.body.style.userSelect = "none";
82-
_this.prevOnSelectStart = document.onselectstart;
8378

84-
document.onselectstart = function () {
85-
return false;
86-
};
79+
if (global.document) {
80+
global.document.addEventListener("mousemove", _this.handleDragEvent);
81+
global.document.addEventListener("mouseup", _this.handleDragEnd);
82+
_this.prevUserSelect = global.document.body.style.userSelect;
83+
global.document.body.style.userSelect = "none";
84+
_this.prevOnSelectStart = global.document.onselectstart;
85+
86+
global.document.onselectstart = function () {
87+
return false;
88+
};
89+
}
8790

8891
_this.props.onDragStart && _this.props.onDragStart({
8992
axis: _this.props.type,
@@ -114,18 +117,20 @@ function (_React$Component) {
114117

115118
_this.element.classList.remove("dragging");
116119

117-
document.removeEventListener("mousemove", _this.handleDragEvent);
118-
document.removeEventListener("mouseup", _this.handleDragEnd);
120+
if (global.document) {
121+
global.document.removeEventListener("mousemove", _this.handleDragEvent);
122+
global.document.removeEventListener("mouseup", _this.handleDragEnd);
123+
global.document.body.style.userSelect = _this.prevUserSelect;
124+
_this.prevUserSelect = null;
125+
global.document.onselectstart = _this.prevOnSelectStart;
126+
_this.prevOnSelectStart = null;
127+
}
119128

120129
if (!_this.isDragging) {
121130
return;
122131
}
123132

124133
_this.isDragging = false;
125-
document.body.style.userSelect = _this.prevUserSelect;
126-
_this.prevUserSelect = null;
127-
document.onselectstart = _this.prevOnSelectStart;
128-
_this.prevOnSelectStart = null;
129134
_this.props.onDragEnd && _this.props.onDragEnd({
130135
axis: _this.props.type
131136
});

dist/util/getScrollbarWidth.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ exports.dbgSetScrollbarWidth = dbgSetScrollbarWidth;
88
exports.dbgSetDocument = dbgSetDocument;
99
exports.dbgGetDocument = dbgGetDocument;
1010
var scrollbarWidth = null;
11-
var doc = typeof document !== "undefined" ? document : null;
11+
var doc = global.document || null;
1212
/**
1313
* @description Returns scrollbar width specific for current environment
1414
* @return {number}

src/Thumb.js

+18-14
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,15 @@ export default class Thumb extends React.Component {
4242
this.dragStartOffsetX = ev.clientX - rect.left - rect.width / 2;
4343
this.dragStartOffsetY = ev.clientY - rect.top - rect.height / 2;
4444

45-
document.addEventListener("mousemove", this.handleDragEvent);
46-
document.addEventListener("mouseup", this.handleDragEnd);
47-
48-
this.prevUserSelect = document.body.style.userSelect;
49-
document.body.style.userSelect = "none";
50-
this.prevOnSelectStart = document.onselectstart;
51-
document.onselectstart = () => false;
45+
if (global.document) {
46+
global.document.addEventListener("mousemove", this.handleDragEvent);
47+
global.document.addEventListener("mouseup", this.handleDragEnd);
48+
49+
this.prevUserSelect = global.document.body.style.userSelect;
50+
global.document.body.style.userSelect = "none";
51+
this.prevOnSelectStart = global.document.onselectstart;
52+
global.document.onselectstart = () => false;
53+
}
5254

5355
this.props.onDragStart &&
5456
this.props.onDragStart({
@@ -84,19 +86,21 @@ export default class Thumb extends React.Component {
8486
this.dragStartOffsetY = false;
8587
this.element.classList.remove("dragging");
8688

87-
document.removeEventListener("mousemove", this.handleDragEvent);
88-
document.removeEventListener("mouseup", this.handleDragEnd);
89+
if (global.document) {
90+
global.document.removeEventListener("mousemove", this.handleDragEvent);
91+
global.document.removeEventListener("mouseup", this.handleDragEnd);
92+
93+
global.document.body.style.userSelect = this.prevUserSelect;
94+
this.prevUserSelect = null;
95+
global.document.onselectstart = this.prevOnSelectStart;
96+
this.prevOnSelectStart = null;
97+
}
8998

9099
if (!this.isDragging) {
91100
return;
92101
}
93102
this.isDragging = false;
94103

95-
document.body.style.userSelect = this.prevUserSelect;
96-
this.prevUserSelect = null;
97-
document.onselectstart = this.prevOnSelectStart;
98-
this.prevOnSelectStart = null;
99-
100104
this.props.onDragEnd && this.props.onDragEnd({axis: this.props.type});
101105
};
102106

src/util/getScrollbarWidth.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
let scrollbarWidth = null;
2-
let doc = typeof document !== "undefined" ? document : null;
2+
let doc = global.document || null;
33

44
/**
55
* @description Returns scrollbar width specific for current environment

0 commit comments

Comments
 (0)