perfect-gui 3.5.1 → 3.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/index.js +46 -28
- package/test/src/js/other.js +1 -1
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import styles from './styles';
|
|
|
2
2
|
|
|
3
3
|
export default class GUI {
|
|
4
4
|
constructor(options = {}) {
|
|
5
|
+
// Process options
|
|
5
6
|
if ( options.container ) {
|
|
6
7
|
this.container = typeof options.container == "string" ? document.querySelector(options.container) : options.container;
|
|
7
8
|
this.position_type = 'absolute';
|
|
@@ -18,8 +19,17 @@ export default class GUI {
|
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
this.name = (options != undefined && typeof options.name == "string") ? options.name : '';
|
|
22
|
+
|
|
21
23
|
this.backgroundColor = options.color || null;
|
|
22
24
|
|
|
25
|
+
this.maxHeight = Math.min(this.container.clientHeight, window.innerHeight)
|
|
26
|
+
if ( options.maxHeight ) {
|
|
27
|
+
this.initMaxHeight = options.maxHeight;
|
|
28
|
+
this.maxHeight = Math.min(this.initMaxHeight, this.maxHeight);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
this.screenCorner = this._parseScreenCorner(options.position);
|
|
32
|
+
|
|
23
33
|
if ( this instanceof GUI ) {
|
|
24
34
|
if ( typeof GUI[GUI.instanceCounter] != 'number' ) {
|
|
25
35
|
GUI[GUI.instanceCounter] = 0;
|
|
@@ -39,10 +49,29 @@ export default class GUI {
|
|
|
39
49
|
// Common styles
|
|
40
50
|
if (this.instanceId == 0) {
|
|
41
51
|
this._addStyles(`${styles(this.position_type)}`);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Instance specific styles
|
|
55
|
+
this._styleInstance();
|
|
56
|
+
|
|
57
|
+
if (options.autoRepositioning != false) {
|
|
58
|
+
window.addEventListener('resize', this._handleResize.bind(this));
|
|
42
59
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
this.
|
|
60
|
+
|
|
61
|
+
this._addWrapper();
|
|
62
|
+
this.wrapper.setAttribute('data-corner-x', this.screenCorner.x);
|
|
63
|
+
this.wrapper.setAttribute('data-corner-y', this.screenCorner.y);
|
|
64
|
+
|
|
65
|
+
this.hasBeenDragged = false;
|
|
66
|
+
if (options.draggable == true) this._makeDraggable();
|
|
67
|
+
|
|
68
|
+
this.closed = false;
|
|
69
|
+
if (options.closed) this.toggleClose();
|
|
70
|
+
|
|
71
|
+
this.folders = [];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
_styleInstance() {
|
|
46
75
|
this.xOffset = this.screenCorner.x == 'left' ? 0 : this.container.clientWidth - this.wrapperWidth;
|
|
47
76
|
if (this.instanceId > 0) {
|
|
48
77
|
let existingDomInstances = this.container.querySelectorAll('.p-gui');
|
|
@@ -60,14 +89,6 @@ export default class GUI {
|
|
|
60
89
|
this.yOffset = 0;
|
|
61
90
|
this.position = {prevX:this.xOffset, prevY:this.yOffset, x:this.xOffset, y:this.yOffset};
|
|
62
91
|
|
|
63
|
-
if ( options.maxHeight ) {
|
|
64
|
-
this.maxHeight = options.maxHeight;
|
|
65
|
-
} else {
|
|
66
|
-
this.maxHeight = Math.min(this.container.clientHeight, window.innerHeight)
|
|
67
|
-
}
|
|
68
|
-
window.addEventListener('resize', () => {
|
|
69
|
-
this.maxHeight = Math.min(options.maxHeight || '', Math.min(this.container.clientHeight, window.innerHeight));
|
|
70
|
-
});
|
|
71
92
|
this._addStyles(`#p-gui-${this.instanceId} {
|
|
72
93
|
width: ${this.wrapperWidth}px;
|
|
73
94
|
max-height: ${this.maxHeight}px;
|
|
@@ -75,20 +96,6 @@ export default class GUI {
|
|
|
75
96
|
${ this.screenCorner.y == 'top' ? '' : 'top: auto; bottom: 0;' }
|
|
76
97
|
${ this.backgroundColor ? 'background: ' + this.backgroundColor + ';' : '' }
|
|
77
98
|
}`);
|
|
78
|
-
|
|
79
|
-
if (options.autoRepositioning != false) window.addEventListener('resize', this._handleResize.bind(this));
|
|
80
|
-
|
|
81
|
-
this._addWrapper();
|
|
82
|
-
this.wrapper.setAttribute('data-corner-x', this.screenCorner.x);
|
|
83
|
-
this.wrapper.setAttribute('data-corner-y', this.screenCorner.y);
|
|
84
|
-
|
|
85
|
-
this.hasBeenDragged = false;
|
|
86
|
-
if (options.draggable == true) this._makeDraggable();
|
|
87
|
-
|
|
88
|
-
this.closed = false;
|
|
89
|
-
if (options.closed) this.toggleClose();
|
|
90
|
-
|
|
91
|
-
this.folders = [];
|
|
92
99
|
}
|
|
93
100
|
|
|
94
101
|
_folderConstructor(folderOptions) {
|
|
@@ -107,8 +114,20 @@ export default class GUI {
|
|
|
107
114
|
return parsedPosition;
|
|
108
115
|
}
|
|
109
116
|
|
|
117
|
+
_getScrollbarWidth(element) {
|
|
118
|
+
if (element === document.body) {
|
|
119
|
+
return window.innerWidth - document.documentElement.clientWidth;
|
|
120
|
+
} else {
|
|
121
|
+
return element.offsetWidth - element.clientWidth;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
110
125
|
_handleResize() {
|
|
111
|
-
|
|
126
|
+
this.maxHeight = Math.min(this.initMaxHeight, Math.min(this.container.clientHeight, window.innerHeight));
|
|
127
|
+
|
|
128
|
+
if (this.hasBeenDragged) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
112
131
|
|
|
113
132
|
this.xOffset = this.screenCorner.x == 'left' ? 0 : this.container.clientWidth - this.wrapperWidth;
|
|
114
133
|
if (this.instanceId > 0) {
|
|
@@ -131,8 +150,7 @@ export default class GUI {
|
|
|
131
150
|
}
|
|
132
151
|
|
|
133
152
|
_createElement(element) {
|
|
134
|
-
|
|
135
|
-
element.el = element.el ? element.el : 'div';
|
|
153
|
+
element.el = element.el || 'div';
|
|
136
154
|
var domElement = document.createElement(element.el);
|
|
137
155
|
if (element.id) domElement.id = element.id;
|
|
138
156
|
if (element.class) domElement.className = element.class;
|