@openglobus/og 0.14.10 → 0.15.1

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.
Files changed (140) hide show
  1. package/css/og.css +378 -275
  2. package/dist/@openglobus/og.css +1 -1
  3. package/dist/@openglobus/og.esm.js +2 -2
  4. package/dist/@openglobus/og.esm.js.map +1 -1
  5. package/dist/@openglobus/og.umd.js +2 -2
  6. package/dist/@openglobus/og.umd.js.map +1 -1
  7. package/package.json +18 -17
  8. package/src/og/Clock.js +218 -194
  9. package/src/og/Globe.js +5 -5
  10. package/src/og/Object3d.js +104 -145
  11. package/src/og/camera/Camera.js +31 -27
  12. package/src/og/camera/PlanetCamera.js +22 -14
  13. package/src/og/cons.js +107 -107
  14. package/src/og/control/Atmosphere.js +396 -0
  15. package/src/og/control/CompassButton.js +11 -18
  16. package/src/og/control/Control.js +197 -188
  17. package/src/og/control/GeoImageDragControl.js +84 -66
  18. package/src/og/control/LayerSwitcher.js +56 -138
  19. package/src/og/control/Lighting.js +314 -186
  20. package/src/og/control/MouseNavigation.js +2 -2
  21. package/src/og/control/RulerSwitcher.js +24 -19
  22. package/src/og/control/ScaleControl.js +30 -10
  23. package/src/og/control/SimpleSkyBackground.js +210 -0
  24. package/src/og/control/Sun.js +3 -1
  25. package/src/og/control/ZoomControl.js +30 -42
  26. package/src/og/control/index.js +6 -0
  27. package/src/og/control/ruler/RulerScene.js +5 -23
  28. package/src/og/control/selection/Selection.js +99 -0
  29. package/src/og/control/selection/SelectionScene.js +350 -0
  30. package/src/og/control/timeline/TimelineControl.js +99 -0
  31. package/src/og/control/timeline/TimelineModel.js +133 -0
  32. package/src/og/control/timeline/TimelineView.js +449 -0
  33. package/src/og/control/timeline/timelineUtils.js +132 -0
  34. package/src/og/ellipsoid/Ellipsoid.js +120 -93
  35. package/src/og/ellipsoid/wgs84.js +13 -13
  36. package/src/og/entity/Entity.js +36 -9
  37. package/src/og/entity/EntityCollection.js +0 -2
  38. package/src/og/entity/GeoObject.js +72 -56
  39. package/src/og/entity/GeoObjectHandler.js +487 -656
  40. package/src/og/entity/GeometryHandler.js +1341 -1337
  41. package/src/og/entity/Polyline.js +0 -16
  42. package/src/og/entity/Ray.js +0 -10
  43. package/src/og/entity/RayHandler.js +3 -44
  44. package/src/og/entity/Strip.js +1 -6
  45. package/src/og/index.js +13 -7
  46. package/src/og/input/input.js +3 -1
  47. package/src/og/layer/CanvasTiles.js +39 -34
  48. package/src/og/layer/Layer.js +69 -9
  49. package/src/og/layer/Material.js +1 -8
  50. package/src/og/layer/WMS.js +16 -5
  51. package/src/og/light/LightSource.js +2 -0
  52. package/src/og/math/Line3.js +140 -139
  53. package/src/og/math/Plane.js +118 -117
  54. package/src/og/math/Ray.js +242 -239
  55. package/src/og/math/Vec3.js +56 -37
  56. package/src/og/math/Vec4.js +3 -4
  57. package/src/og/math.js +21 -21
  58. package/src/og/quadTree/Node.js +5 -4
  59. package/src/og/quadTree/index.js +12 -0
  60. package/src/og/renderer/Renderer.js +64 -37
  61. package/src/og/renderer/RendererEvents.js +1071 -1065
  62. package/src/og/scene/Planet.js +354 -174
  63. package/src/og/scene/RenderNode.js +27 -12
  64. package/src/og/segment/Segment.js +0 -5
  65. package/src/og/shaders/atmos.js +332 -0
  66. package/src/og/shaders/drawnode.js +475 -109
  67. package/src/og/shaders/geoObject.js +96 -51
  68. package/src/og/shaders/polyline.js +212 -17
  69. package/src/og/shaders/ray.js +13 -6
  70. package/src/og/shaders/toneMapping.js +5 -5
  71. package/src/og/shaders/utils.js +88 -0
  72. package/src/og/terrain/GlobusTerrain.js +5 -4
  73. package/src/og/terrain/MapboxTerrain.js +231 -52
  74. package/src/og/ui/Button.js +106 -0
  75. package/src/og/ui/ButtonGroup.js +57 -0
  76. package/src/og/ui/Dialog.js +242 -0
  77. package/src/og/ui/Slider.js +144 -0
  78. package/src/og/ui/ToggleButton.js +51 -0
  79. package/src/og/{control → ui}/UIhelpers.js +11 -2
  80. package/src/og/ui/View.js +190 -0
  81. package/src/og/utils/shared.js +960 -942
  82. package/src/og/webgl/Framebuffer.js +308 -387
  83. package/src/og/webgl/Handler.js +90 -30
  84. package/src/og/webgl/Multisample.js +8 -0
  85. package/types/Clock.d.ts +7 -2
  86. package/types/Object3d.d.ts +14 -3
  87. package/types/camera/Camera.d.ts +18 -17
  88. package/types/camera/PlanetCamera.d.ts +3 -1
  89. package/types/control/Atmosphere.d.ts +15 -0
  90. package/types/control/CompassButton.d.ts +1 -2
  91. package/types/control/GeoImageDragControl.d.ts +7 -1
  92. package/types/control/LayerSwitcher.d.ts +5 -6
  93. package/types/control/Lighting.d.ts +32 -7
  94. package/types/control/ScaleControl.d.ts +2 -1
  95. package/types/control/SimpleSkyBackground.d.ts +15 -0
  96. package/types/control/ZoomControl.d.ts +0 -1
  97. package/types/control/index.d.ts +4 -1
  98. package/types/control/ruler/RulerScene.d.ts +0 -1
  99. package/types/control/selection/Selection.d.ts +49 -0
  100. package/types/control/selection/SelectionScene.d.ts +34 -0
  101. package/types/ellipsoid/Ellipsoid.d.ts +3 -2
  102. package/types/entity/Entity.d.ts +8 -0
  103. package/types/entity/GeoObject.d.ts +28 -22
  104. package/types/entity/GeoObjectHandler.d.ts +16 -56
  105. package/types/entity/Ray.d.ts +0 -3
  106. package/types/entity/RayHandler.d.ts +0 -4
  107. package/types/index.d.ts +9 -6
  108. package/types/input/input.d.ts +2 -0
  109. package/types/layer/CanvasTiles.d.ts +1 -0
  110. package/types/layer/Layer.d.ts +9 -0
  111. package/types/layer/WMS.d.ts +7 -3
  112. package/types/math/Plane.d.ts +1 -1
  113. package/types/math/Vec3.d.ts +19 -16
  114. package/types/math/Vec4.d.ts +2 -3
  115. package/types/math.d.ts +20 -20
  116. package/types/quadTree/index.d.ts +10 -0
  117. package/types/renderer/Renderer.d.ts +11 -37
  118. package/types/scene/Planet.d.ts +27 -1
  119. package/types/scene/RenderNode.d.ts +2 -1
  120. package/types/segment/Segment.d.ts +1 -1
  121. package/types/shaders/atmos.d.ts +4 -0
  122. package/types/shaders/drawnode.d.ts +3 -2
  123. package/types/shaders/utils.d.ts +1 -0
  124. package/types/terrain/GlobusTerrain.d.ts +1 -1
  125. package/types/terrain/MapboxTerrain.d.ts +2 -1
  126. package/types/ui/Button.d.ts +21 -0
  127. package/types/ui/Dialog.d.ts +41 -0
  128. package/types/ui/Slider.d.ts +30 -0
  129. package/types/ui/ToggleButton.d.ts +10 -0
  130. package/types/{control → ui}/UIhelpers.d.ts +1 -1
  131. package/types/ui/View.d.ts +32 -0
  132. package/types/utils/shared.d.ts +16 -14
  133. package/types/webgl/Framebuffer.d.ts +2 -5
  134. package/types/webgl/Handler.d.ts +15 -10
  135. package/types/webgl/Multisample.d.ts +2 -0
  136. package/src/og/ajax.js +0 -204
  137. package/src/og/entity/Object3d.js +0 -504
  138. package/src/og/utils/quadTreeType.js +0 -11
  139. package/types/ajax.d.ts +0 -24
  140. package/types/utils/quadTreeType.d.ts +0 -8
@@ -0,0 +1,242 @@
1
+ 'use strict'
2
+
3
+ import { View } from './View.js';
4
+ import { getDefault, stringTemplate } from '../utils/shared.js';
5
+ import { Button } from './Button.js';
6
+
7
+ const TEMPLATE = `<div class="og-ddialog"
8
+ style="display:{display}; resize:{resize}; width: {width}px; {height}; top: {top}px; left: {left}px; min-height: {minHeight}; max-height: {maxHeight}; min-width: {minWidth}; max-width: {maxWidth};">
9
+ <div class="og-ddialog-header">
10
+ <div class="og-ddialog-header__title">{title}</div>
11
+ <div class="og-ddialog-header__buttons"></div>
12
+ </div>
13
+ <div class="og-ddialog-container"></div>
14
+ </div>>`;
15
+
16
+ const CLOSE_ICON = `<svg className="svg-icon" style="width: 1em; height: 1em;vertical-align: middle;fill: currentColor; overflow: hidden;" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg">
17
+ <path d="M777.856 280.192l-33.92-33.952-231.872 231.872-231.84-231.872-33.984 33.888 231.872 231.904-231.84 231.84 33.888 33.984 231.904-231.904 231.84 231.872 33.952-33.888-231.872-231.904z"/>
18
+ </svg>`
19
+
20
+ class Dialog extends View {
21
+ constructor(options = {}) {
22
+ super({
23
+ template: stringTemplate(TEMPLATE, {
24
+ title: options.title || "",
25
+ display: getDefault(options.visible, true) ? "flex" : "none",
26
+ resize: getDefault(options.resizable, true) ? "both" : "none",
27
+ width: options.width || 300,
28
+ height: options.height ? `height:${options.height || 200}` : "",
29
+ left: options.left || 0,
30
+ top: options.top || 0,
31
+ minHeight: options.minHeight ? `${options.minHeight}px` : 'unset',
32
+ maxHeight: options.maxHeight ? `${options.maxHeight}px` : 'unset',
33
+ minWidth: options.minWidth ? `${options.minWidth}px` : 'unset',
34
+ maxWidth: options.maxWidth ? `${options.maxWidth}px` : 'unset',
35
+ }),
36
+ ...options,
37
+ eventList: ["resize", "focus", "visibility", "dragstart", "dragend", ...(options.eventList || [])],
38
+ });
39
+
40
+ this._startPosX = 0;
41
+ this._startPosY = 0;
42
+
43
+ this.$header;
44
+ this.$title;
45
+ this.$constainer;
46
+ this.$buttons;
47
+
48
+ this._closeBtn;
49
+
50
+ this.useHide = options.useHide || false;
51
+
52
+ this._visibility = getDefault(options.visible, true);
53
+ }
54
+
55
+ static set __zIndex(n) {
56
+ this.__zIndex__ = n;
57
+ }
58
+
59
+ static get __zIndex() {
60
+ if (!this.__zIndex__ && this.__zIndex__ !== 0) {
61
+ this.__zIndex__ = 0;
62
+ }
63
+ return this.__zIndex__;
64
+ }
65
+
66
+ setContainer(htmlStr) {
67
+ this.$constainer.innerHTML = htmlStr;
68
+ }
69
+
70
+ get container() {
71
+ return this.$container;
72
+ }
73
+
74
+ get width() {
75
+ return this.el ? parseFloat(this.el.style.width) : 0;
76
+ }
77
+
78
+ get height() {
79
+ return this.el ? parseFloat(this.el.style.height) : 0;
80
+ }
81
+
82
+ bringToFront() {
83
+ this.el.style.zIndex = Dialog.__zIndex++;
84
+ }
85
+
86
+ render(params) {
87
+ super.render(params);
88
+ this.bringToFront();
89
+ this.$header = this.select(".og-ddialog-header");
90
+ this.$title = this.select(".og-ddialog-header__title");
91
+ this.$container = this.select(".og-ddialog-container");
92
+ this.$buttons = this.select(".og-ddialog-header__buttons");
93
+ this._initEvents();
94
+ this._initButtons();
95
+ return this;
96
+ }
97
+
98
+ show() {
99
+ if (!this._visibility) {
100
+ this._visibility = true;
101
+ this.el.style.display = "flex";
102
+ this.bringToFront();
103
+ this._events.dispatch(this._events.visibility, true, this);
104
+ }
105
+ }
106
+
107
+ hide() {
108
+ if (this._visibility) {
109
+ this._visibility = false;
110
+ this.el.style.display = "none";
111
+ this._events.dispatch(this._events.visibility, false, this);
112
+ }
113
+ }
114
+
115
+ close() {
116
+ if (this.useHide) {
117
+ this.hide();
118
+ } else {
119
+ this.remove();
120
+ }
121
+ }
122
+
123
+ setVisibility(visibility) {
124
+ if (visibility) {
125
+ this.show();
126
+ } else {
127
+ this.hide();
128
+ }
129
+ }
130
+
131
+ _initButtons() {
132
+ this._closeBtn = new Button({
133
+ icon: CLOSE_ICON,
134
+ classList: ["og-button-size__20"]
135
+ });
136
+
137
+ this._onCloseBtnClick_ = this._onCloseBtnClick.bind(this);
138
+ this._closeBtn.on("click", this._onCloseBtnClick_);
139
+
140
+ this._closeBtn.appendTo(this.$buttons);
141
+ }
142
+
143
+ _initEvents() {
144
+ this._onMouseDown_ = this._onMouseDown.bind(this);
145
+ this.$header.addEventListener("mousedown", this._onMouseDown_);
146
+
147
+ this._onMouseDownAll_ = this._onMouseDownAll.bind(this);
148
+ this.el.addEventListener("mousedown", this._onMouseDownAll_);
149
+ }
150
+
151
+ _onCloseBtnClick(e) {
152
+ this.close();
153
+ }
154
+
155
+ _onMouseDownAll() {
156
+ this.bringToFront();
157
+ }
158
+
159
+ _onMouseDown(e) {
160
+ e = e || window.event;
161
+ e.preventDefault();
162
+
163
+ this._startDragging();
164
+
165
+ this._startPosX = e.clientX;
166
+ this._startPosY = e.clientY;
167
+
168
+ this._onMouseMove_ = this._onMouseMove.bind(this)
169
+ document.addEventListener("mousemove", this._onMouseMove_);
170
+
171
+ this._onMouseUp_ = this._onMouseUp.bind(this);
172
+ document.addEventListener("mouseup", this._onMouseUp_);
173
+ }
174
+
175
+ setPosition(x, y) {
176
+ if (x != undefined) {
177
+ this.el.style.left = `${x}px`;
178
+ }
179
+ if (y != undefined) {
180
+ this.el.style.top = `${y}px`;
181
+ }
182
+ }
183
+
184
+ _onMouseMove(e) {
185
+ e = e || window.event;
186
+ e.preventDefault();
187
+ let dx = this._startPosX - e.clientX;
188
+ let dy = this._startPosY - e.clientY;
189
+ this._startPosX = e.clientX;
190
+ this._startPosY = e.clientY;
191
+ this.setPosition(this.el.offsetLeft - dx, this.el.offsetTop - dy);
192
+ }
193
+
194
+ _startDragging() {
195
+ if (!this.el.classList.contains("dragging")) {
196
+ this.el.classList.add("dragging");
197
+ this._events.dispatch(this._events.dragstart, this);
198
+ }
199
+ }
200
+
201
+ _clearDragging() {
202
+ if (this.el.classList.contains("dragging")) {
203
+ this._events.dispatch(this._events.dragend, this);
204
+ this.el.classList.remove("dragging");
205
+ }
206
+ }
207
+
208
+ _onMouseUp() {
209
+ this._clearDragging();
210
+
211
+ document.removeEventListener("mouseup", this._onMouseUp_);
212
+ this._onMouseUp_ = undefined;
213
+
214
+ document.removeEventListener("mousemove", this._onMouseMove_);
215
+ this._onMouseMove_ = undefined;
216
+ }
217
+
218
+ remove() {
219
+ this._clearDragging();
220
+ this._clearEvents();
221
+ super.remove();
222
+ }
223
+
224
+ _clearEvents() {
225
+ this._closeBtn.off("click", this._onCloseBtnClick_);
226
+ this._onCloseBtnClick_ = undefined;
227
+
228
+ document.removeEventListener("mouseup", this._onMouseUp_);
229
+ this._onMouseUp_ = undefined;
230
+
231
+ document.removeEventListener("mousemove", this._onMouseMove_);
232
+ this._onMouseMove_ = undefined;
233
+
234
+ this.$header.removeEventListener("mousedown", this._onMouseDown_);
235
+ this._onMouseDown_ = undefined;
236
+
237
+ this.el.removeEventListener("mousedown", this._onMouseDownAll_);
238
+ this._onMouseDownAll_ = undefined;
239
+ }
240
+ }
241
+
242
+ export { Dialog }
@@ -0,0 +1,144 @@
1
+ 'use strict';
2
+
3
+ import { View } from './View.js';
4
+ import { stringTemplate } from '../utils/shared.js';
5
+ import { clamp } from '../math.js';
6
+
7
+ const TEMPLATE = `<div class="og-slider">
8
+ <div class="og-slider-label">{label}</div>
9
+ <div class="og-slider-panel">
10
+ <div class="og-slider-progress"></div>
11
+ <div class="og-slider-pointer"></div>
12
+ </div>
13
+ <input type="number"/>
14
+ </div>`;
15
+
16
+ class Slider extends View {
17
+ constructor(options = {}) {
18
+ super({
19
+ template: stringTemplate(TEMPLATE, {
20
+ label: options.label || ""
21
+ }), ...options, eventList: ["change", ...(options.eventList || [])]
22
+ });
23
+
24
+ this._value = options.value || 0.0;
25
+ this._min = options.min || 0.0;
26
+ this._max = options.max || 1.0;
27
+ //this._step = options.step || ((this._max - this._min) / 10.0);
28
+
29
+ this._onResize_ = this._onResize.bind(this);
30
+ this._resizeObserver = new ResizeObserver(this._onResize_);
31
+
32
+ this.$label;
33
+ this.$pointer;
34
+ this.$progress;
35
+ this.$input;
36
+ this.$panel;
37
+ }
38
+
39
+ render(params) {
40
+ super.render(params);
41
+ this.$label = this.select(".og-slider-label");
42
+ if (this.$label.innerHTML === "") {
43
+ this.$label.style.display = "none";
44
+ }
45
+ this.$pointer = this.select(".og-slider-pointer");
46
+ this.$progress = this.select(".og-slider-progress");
47
+ this.$panel = this.select(".og-slider-panel");
48
+ this.$input = this.select("input");
49
+
50
+
51
+ this._resizeObserver.observe(this.el);
52
+
53
+ this._initEvents();
54
+
55
+ return this;
56
+ }
57
+
58
+ _onResize(e) {
59
+ this._setOffset(this._value * this.$panel.clientWidth / (this._max - this._min));
60
+ }
61
+
62
+ set value(val) {
63
+ if (val !== this._value) {
64
+ this._value = clamp(val, this._min, this._max);
65
+ this.$input.value = this._value.toString();
66
+ this._setOffset(this._value * this.$panel.clientWidth / (this._max - this._min));
67
+ this._events.dispatch(this._events.change, this._value, this);
68
+ }
69
+ }
70
+
71
+ get value() {
72
+ return this._value;
73
+ }
74
+
75
+ _initEvents() {
76
+ this._onMouseDown_ = this._onMouseDown.bind(this);
77
+ this.$panel.addEventListener("mousedown", this._onMouseDown_);
78
+
79
+ this._onInput_ = this._onInput.bind(this);
80
+ this.$input.addEventListener("input", this._onInput_);
81
+
82
+ this._onMouseWheel_ = this._onMouseWheel.bind(this);
83
+ this.$panel.addEventListener("mousewheel", this._onMouseWheel_);
84
+ }
85
+
86
+ _onMouseWheel(e) {
87
+ e = e || window.event;
88
+ e.preventDefault();
89
+ e.stopPropagation();
90
+ this.value = this._value + Math.sign(e.wheelDelta) * (this._max - this._min) / 100.0;
91
+ }
92
+
93
+ _onInput(e) {
94
+ e = e || window.event;
95
+ e.preventDefault();
96
+ e.stopPropagation();
97
+ this.value = parseFloat(e.target.value);
98
+ }
99
+
100
+ _onMouseDown(e) {
101
+ e = e || window.event;
102
+ e.preventDefault();
103
+
104
+ this._startPosX = e.clientX;
105
+
106
+ this.value = this._min + (this._max - this._min) * (e.offsetX / this.$panel.clientWidth);
107
+
108
+ this._onMouseMove_ = this._onMouseMove.bind(this)
109
+ document.addEventListener("mousemove", this._onMouseMove_);
110
+
111
+ this._onMouseUp_ = this._onMouseUp.bind(this);
112
+ document.addEventListener("mouseup", this._onMouseUp_);
113
+ }
114
+
115
+ _setOffset(x) {
116
+ if (x >= 0 && x <= this.$panel.clientWidth) {
117
+ this.$pointer.style.left = this.$progress.style.width = `${x * 100 / this.$panel.clientWidth}%`;
118
+ }
119
+ }
120
+
121
+ _onMouseMove(e) {
122
+ e = e || window.event;
123
+ e.preventDefault();
124
+ e.stopPropagation();
125
+
126
+ let rect = this.$panel.getBoundingClientRect();
127
+ let clientX = clamp(e.clientX, rect.left, rect.right);
128
+ let dx = this._startPosX - clientX;
129
+ this._startPosX = clientX;
130
+ this.value = (this.$pointer.offsetLeft - dx) * (this._max - this._min) / this.$panel.clientWidth;
131
+ }
132
+
133
+ _onMouseUp() {
134
+ document.removeEventListener("mouseup", this._onMouseUp_);
135
+ this._onMouseUp_ = undefined;
136
+
137
+ document.removeEventListener("mousemove", this._onMouseMove_);
138
+ this._onMouseMove_ = undefined;
139
+ }
140
+ }
141
+
142
+ export {
143
+ Slider
144
+ }
@@ -0,0 +1,51 @@
1
+ 'use strict';
2
+
3
+ import { Button } from './Button.js';
4
+
5
+ class ToggleButton extends Button {
6
+ constructor(options) {
7
+ super({
8
+ ...options,
9
+ eventList: ["change", ...(options.eventList || [])]
10
+ });
11
+
12
+ this._isActive = options.isActive || false;
13
+
14
+ this.preventClick = options.preventClick || false;
15
+ }
16
+
17
+ setActive(isActive, stopPropagation) {
18
+ if (isActive !== this._isActive) {
19
+ this._isActive = isActive;
20
+ this._toggle();
21
+ if (!stopPropagation) {
22
+ this._events.dispatch(this._events.change, isActive, this);
23
+ }
24
+ }
25
+ }
26
+
27
+ _toggle() {
28
+ this.el.classList.toggle("og-button__active");
29
+ }
30
+
31
+ get isActive() {
32
+ return this._isActive;
33
+ }
34
+
35
+ render(params) {
36
+ super.render(params);
37
+ if (this._isActive) {
38
+ this._toggle();
39
+ }
40
+ return this;
41
+ }
42
+
43
+ _onMouseClick(e) {
44
+ if (!this.preventClick) {
45
+ super._onMouseClick(e);
46
+ this.setActive(!this.isActive);
47
+ }
48
+ }
49
+ }
50
+
51
+ export { ToggleButton }
@@ -108,12 +108,16 @@ function isString(v) {
108
108
  }
109
109
 
110
110
  // Handles the click inside/outside a dialog - closes dialog when click outside
111
- export function btnClickHandler(btn_id, dialog_id, dialog_selector, btn_icon_id) {
111
+ export function btnClickHandler(btn_id, dialog_id, dialog_selector, btn_icon_id, callback) {
112
112
  let btn = isString(btn_id) ? document.getElementById(btn_id) : btn_id;
113
113
  let dialog = document.getElementById(dialog_id);
114
114
  btn.onclick = function (e) {
115
+
116
+ let off = true;
117
+
115
118
  if (this.classList.contains('og-OFF')) {
116
119
  // Turn to ON
120
+ off = false;
117
121
  allMenuBtnOFF();
118
122
  allDialogsHide();
119
123
  this.classList.remove('og-OFF');
@@ -137,10 +141,15 @@ export function btnClickHandler(btn_id, dialog_id, dialog_selector, btn_icon_id)
137
141
  }
138
142
  } else {
139
143
  // Turn to OFF
144
+ off = true;
140
145
  this.classList.add('og-OFF');
141
146
  if (dialog) {
142
147
  dialog.classList.add('og-hide');
143
148
  }
144
149
  }
150
+
151
+ if (callback && typeof callback === 'function'){
152
+ callback(off);
153
+ }
145
154
  }
146
- }
155
+ }
@@ -0,0 +1,190 @@
1
+ 'use strict';
2
+
3
+
4
+ import { stringTemplate } from '../utils/shared.js';
5
+ import { parseHTML } from "../utils/shared.js";
6
+ import { Events } from '../Events.js';
7
+
8
+ class View {
9
+ constructor(options = {}) {
10
+ this.__id = View.__staticCounter++;
11
+ this._events = new Events(options.eventList || []);
12
+ this.model = options.model || null;
13
+ this.template = options.template || "";
14
+ this.parent = options.parent || null;
15
+ this._classList = options.classList || [];
16
+ if (options.appendTo) {
17
+ this.appendTo(options.appendTo);
18
+ }
19
+ }
20
+
21
+ static set __staticCounter(n) {
22
+ this.__counter__ = n;
23
+ }
24
+
25
+ static get __staticCounter() {
26
+ if (!this.__counter__ && this.__counter__ !== 0) {
27
+ this.__counter__ = 0;
28
+ }
29
+ return this.__counter__;
30
+ }
31
+
32
+ static getHTML(template, params) {
33
+ return stringTemplate(template, params);
34
+ }
35
+
36
+ static parseHTML(htmlStr) {
37
+ return parseHTML(htmlStr);
38
+ }
39
+
40
+ static insertAfter(newNodes, referenceNode) {
41
+ if (!Array.isArray(newNodes)) {
42
+ newNodes = [newNodes];
43
+ }
44
+ for (let i = 0; i < newNodes.length; i++) {
45
+ if (referenceNode.parentNode) {
46
+ referenceNode.parentNode.insertBefore(newNodes[i], referenceNode.nextSibling);
47
+ }
48
+ }
49
+ return newNodes;
50
+ }
51
+
52
+ static insertBefore(newNodes, referenceNode) {
53
+ if (!Array.isArray(newNodes)) {
54
+ newNodes = [newNodes];
55
+ }
56
+ for (let i = 0; i < newNodes.length; i++) {
57
+ if (referenceNode.parentNode) {
58
+ referenceNode.parentNode.insertBefore(newNodes[i], referenceNode);
59
+ }
60
+ }
61
+ }
62
+
63
+ on(eventName, callback, sender) {
64
+ return this._events.on(eventName, callback, sender);
65
+ }
66
+
67
+ off(eventName, callback) {
68
+ return this._events.off(eventName, callback);
69
+ }
70
+
71
+ insertBefore(view) {
72
+ if (!this.el) {
73
+ this.render();
74
+ }
75
+ if (this.el) {
76
+ if (view instanceof HTMLElement && view.parentNode) {
77
+ View.insertBefore(this.el, view);
78
+ }
79
+ if (view instanceof View && view.el.parentNode) {
80
+ View.insertBefore(this.el, view.el);
81
+ }
82
+ }
83
+ }
84
+
85
+ insertAfter(view) {
86
+ if (!this.el) {
87
+ this.render();
88
+ }
89
+ if (this.el) {
90
+ if (view instanceof HTMLElement && view.parentNode) {
91
+ View.insertAfter(this.el, view);
92
+ }
93
+ if (view instanceof View && view.el.parentNode) {
94
+ View.insertAfter(this.el, view.el);
95
+ }
96
+ }
97
+ }
98
+
99
+ isEqual(view) {
100
+ return view.__id === this.__id;
101
+ }
102
+
103
+ appendTo(node, clean, firstPosition) {
104
+ if (node) {
105
+ if (!this.el) {
106
+ this.beforeRender(node);
107
+ this.render();
108
+ }
109
+
110
+ if (this.el && this.el.parentNode) {
111
+ this.el.parentNode.removeChild(this.el);
112
+ }
113
+
114
+ if (clean) {
115
+ node.innerHTML = "";
116
+ }
117
+
118
+ if (firstPosition) {
119
+ if (node.childNodes[0]) {
120
+ View.insertBefore(this.el, node.childNodes[0]);
121
+ } else {
122
+ node.appendChild(this.el);
123
+ }
124
+ } else {
125
+ node.appendChild(this.el);
126
+ }
127
+ this.afterRender(node);
128
+ }
129
+
130
+ return this;
131
+ }
132
+
133
+ afterRender(parentNode) {
134
+ //virtual
135
+ }
136
+
137
+ beforeRender(parentNode) {
138
+ //virtual
139
+ }
140
+
141
+ stopPropagation() {
142
+ this._events.stopPropagation();
143
+ }
144
+
145
+ renderTemplate(params) {
146
+ return View.parseHTML(View.getHTML(this.template, params || {}))[0];
147
+ }
148
+
149
+ render(params) {
150
+ this.el = this.renderTemplate(params);
151
+ for (let i = 0, len = this._classList.length; i < len; i++) {
152
+ this.el.classList.add(this._classList[i]);
153
+ }
154
+ return this;
155
+ }
156
+
157
+ select(queryStr) {
158
+ return this.el.querySelector(queryStr);
159
+ }
160
+
161
+ selectRemove(queryStr) {
162
+ if (this.el) {
163
+ let r = this.select(queryStr);
164
+ if (r && r.parentNode) {
165
+ r.parentNode.removeChild(r);
166
+ return r;
167
+ }
168
+ }
169
+ }
170
+
171
+ selectAll(queryStr, callback) {
172
+ if (this.el) {
173
+ const res = this.el.querySelectorAll(queryStr);
174
+ if (callback) {
175
+ for (let i = 0, len = res.length; i < len; i++) {
176
+ callback(res[i], i);
177
+ }
178
+ }
179
+ return res;
180
+ }
181
+ }
182
+
183
+ remove() {
184
+ if (this.el && this.el.parentNode) {
185
+ this.el.parentNode.removeChild(this.el);
186
+ }
187
+ }
188
+ }
189
+
190
+ export { View };