forked from mrdoob/three.js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathResizer.js
58 lines (33 loc) · 1.4 KB
/
Resizer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { UIElement } from './libs/ui.js';
function Resizer( editor ) {
const signals = editor.signals;
const dom = document.createElement( 'div' );
dom.id = 'resizer';
function onPointerDown( event ) {
if ( event.isPrimary === false ) return;
dom.ownerDocument.addEventListener( 'pointermove', onPointerMove );
dom.ownerDocument.addEventListener( 'pointerup', onPointerUp );
}
function onPointerUp( event ) {
if ( event.isPrimary === false ) return;
dom.ownerDocument.removeEventListener( 'pointermove', onPointerMove );
dom.ownerDocument.removeEventListener( 'pointerup', onPointerUp );
}
function onPointerMove( event ) {
// PointerEvent's movementX/movementY are 0 in WebKit
if ( event.isPrimary === false ) return;
const offsetWidth = document.body.offsetWidth;
const clientX = event.clientX;
const cX = clientX < 0 ? 0 : clientX > offsetWidth ? offsetWidth : clientX;
const x = Math.max( 260, offsetWidth - cX ); // .TabbedPanel min-width: 260px
dom.style.right = x + 'px';
document.getElementById( 'sidebar' ).style.width = x + 'px';
document.getElementById( 'player' ).style.right = x + 'px';
document.getElementById( 'script' ).style.right = x + 'px';
document.getElementById( 'viewport' ).style.right = x + 'px';
signals.windowResize.dispatch();
}
dom.addEventListener( 'pointerdown', onPointerDown );
return new UIElement( dom );
}
export { Resizer };