@urso/core 0.5.11 → 0.5.12

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 (159) hide show
  1. package/.babelrc +11 -11
  2. package/LICENSE +20 -20
  3. package/README.md +220 -220
  4. package/build/js/index.js +1 -1
  5. package/build/js/index.js.LICENSE.txt +222 -38
  6. package/package.json +52 -52
  7. package/src/js/app.js +78 -78
  8. package/src/js/components/_info.js +10 -10
  9. package/src/js/components/base/_info.js +3 -3
  10. package/src/js/components/base/controller.js +78 -78
  11. package/src/js/components/debug/_info.js +7 -7
  12. package/src/js/components/debug/controller.js +38 -38
  13. package/src/js/components/debug/coords.js +23 -23
  14. package/src/js/components/debug/fps.js +34 -34
  15. package/src/js/components/debug/template.js +55 -55
  16. package/src/js/components/debug/timescale.js +60 -60
  17. package/src/js/components/deviceRotate/_info.js +3 -3
  18. package/src/js/components/deviceRotate/controller.js +86 -86
  19. package/src/js/components/fullscreen/_info.js +6 -6
  20. package/src/js/components/fullscreen/android.js +104 -104
  21. package/src/js/components/fullscreen/controller.js +76 -76
  22. package/src/js/components/fullscreen/desktop.js +49 -49
  23. package/src/js/components/fullscreen/ios.js +115 -115
  24. package/src/js/components/layersSwitcher/_info.js +4 -4
  25. package/src/js/components/layersSwitcher/config.js +26 -26
  26. package/src/js/components/layersSwitcher/controller.js +34 -34
  27. package/src/js/components/loader/_info.js +4 -4
  28. package/src/js/components/loader/controller.js +65 -65
  29. package/src/js/components/loader/template.js +70 -70
  30. package/src/js/components/soundInitialPopup/_info.js +3 -3
  31. package/src/js/components/soundInitialPopup/controller.js +42 -42
  32. package/src/js/components/soundInitialPopup/template.js +109 -109
  33. package/src/js/components/stateDriven/_info.js +3 -3
  34. package/src/js/components/stateDriven/controller.js +118 -118
  35. package/src/js/config/load.js +5 -5
  36. package/src/js/config/main.js +12 -12
  37. package/src/js/extra/_info.js +26 -26
  38. package/src/js/extra/browserEvents.js +51 -51
  39. package/src/js/extra/pixiPatch.js +148 -148
  40. package/src/js/extra/setTimeout.js +7 -7
  41. package/src/js/index.js +8 -8
  42. package/src/js/lib/_info.js +13 -13
  43. package/src/js/lib/cache.js +105 -105
  44. package/src/js/lib/composition.js +85 -85
  45. package/src/js/lib/device.js +1286 -1286
  46. package/src/js/lib/helper.js +539 -539
  47. package/src/js/lib/loader.js +136 -136
  48. package/src/js/lib/localData.js +15 -15
  49. package/src/js/lib/logger.js +69 -69
  50. package/src/js/lib/math.js +35 -35
  51. package/src/js/lib/objectPool.js +54 -54
  52. package/src/js/lib/time.js +18 -18
  53. package/src/js/lib/tween.js +147 -147
  54. package/src/js/modules/_info.js +12 -12
  55. package/src/js/modules/assets/_info.js +7 -7
  56. package/src/js/modules/assets/baseModel.js +18 -18
  57. package/src/js/modules/assets/config.js +37 -37
  58. package/src/js/modules/assets/controller.js +46 -46
  59. package/src/js/modules/assets/models/_info.js +11 -11
  60. package/src/js/modules/assets/models/atlas.js +8 -8
  61. package/src/js/modules/assets/models/audiosprite.js +27 -27
  62. package/src/js/modules/assets/models/bitmapFont.js +8 -8
  63. package/src/js/modules/assets/models/container.js +16 -16
  64. package/src/js/modules/assets/models/font.js +8 -8
  65. package/src/js/modules/assets/models/image.js +13 -13
  66. package/src/js/modules/assets/models/json.js +8 -8
  67. package/src/js/modules/assets/models/sound.js +14 -14
  68. package/src/js/modules/assets/models/spine.js +14 -14
  69. package/src/js/modules/assets/service.js +365 -365
  70. package/src/js/modules/i18n/_info.js +4 -4
  71. package/src/js/modules/i18n/config.js +17 -17
  72. package/src/js/modules/i18n/controller.js +79 -79
  73. package/src/js/modules/instances/_info.js +3 -3
  74. package/src/js/modules/instances/controller.js +261 -261
  75. package/src/js/modules/logic/_info.js +4 -4
  76. package/src/js/modules/logic/config/_info.js +2 -2
  77. package/src/js/modules/logic/config/sounds.js +23 -23
  78. package/src/js/modules/logic/controller.js +48 -48
  79. package/src/js/modules/logic/sounds.js +103 -103
  80. package/src/js/modules/objects/_info.js +13 -13
  81. package/src/js/modules/objects/baseModel.js +198 -198
  82. package/src/js/modules/objects/cache.js +99 -99
  83. package/src/js/modules/objects/controller.js +131 -131
  84. package/src/js/modules/objects/find.js +58 -58
  85. package/src/js/modules/objects/models/_info.js +27 -27
  86. package/src/js/modules/objects/models/atlasImage.js +50 -50
  87. package/src/js/modules/objects/models/bitmapText.js +37 -37
  88. package/src/js/modules/objects/models/button.js +189 -189
  89. package/src/js/modules/objects/models/buttonComposite.js +35 -35
  90. package/src/js/modules/objects/models/checkbox.js +96 -96
  91. package/src/js/modules/objects/models/collection.js +54 -54
  92. package/src/js/modules/objects/models/component.js +44 -44
  93. package/src/js/modules/objects/models/container.js +19 -19
  94. package/src/js/modules/objects/models/dragContainer.js +675 -675
  95. package/src/js/modules/objects/models/emitter.js +67 -67
  96. package/src/js/modules/objects/models/emitterFx.js +99 -99
  97. package/src/js/modules/objects/models/graphics.js +38 -38
  98. package/src/js/modules/objects/models/group.js +19 -19
  99. package/src/js/modules/objects/models/hitArea.js +104 -104
  100. package/src/js/modules/objects/models/image.js +34 -34
  101. package/src/js/modules/objects/models/imagesAnimation.js +113 -113
  102. package/src/js/modules/objects/models/mask.js +38 -38
  103. package/src/js/modules/objects/models/nineSlicePlane.js +30 -30
  104. package/src/js/modules/objects/models/scrollbox.js +64 -64
  105. package/src/js/modules/objects/models/slider.js +253 -253
  106. package/src/js/modules/objects/models/spine.js +276 -276
  107. package/src/js/modules/objects/models/text.js +59 -59
  108. package/src/js/modules/objects/models/textInput.js +66 -66
  109. package/src/js/modules/objects/models/toggle.js +180 -180
  110. package/src/js/modules/objects/models/world.js +19 -19
  111. package/src/js/modules/objects/propertyAdapter.js +587 -587
  112. package/src/js/modules/objects/proxy.js +294 -294
  113. package/src/js/modules/objects/selector.js +136 -136
  114. package/src/js/modules/objects/service.js +242 -242
  115. package/src/js/modules/objects/styles.js +210 -210
  116. package/src/js/modules/observer/_info.js +4 -4
  117. package/src/js/modules/observer/controller.js +99 -99
  118. package/src/js/modules/observer/events.js +51 -51
  119. package/src/js/modules/scenes/_info.js +8 -8
  120. package/src/js/modules/scenes/controller.js +103 -103
  121. package/src/js/modules/scenes/model.js +28 -28
  122. package/src/js/modules/scenes/pixiWrapper.js +237 -237
  123. package/src/js/modules/scenes/resolutions.js +173 -173
  124. package/src/js/modules/scenes/resolutionsConfig.js +73 -73
  125. package/src/js/modules/scenes/service.js +142 -142
  126. package/src/js/modules/soundManager/_info.js +3 -3
  127. package/src/js/modules/soundManager/controller.js +100 -100
  128. package/src/js/modules/soundManager/soundSprite.js +250 -250
  129. package/src/js/modules/statesManager/_info.js +12 -12
  130. package/src/js/modules/statesManager/action.js +60 -60
  131. package/src/js/modules/statesManager/actions/_info.js +3 -3
  132. package/src/js/modules/statesManager/all.js +23 -23
  133. package/src/js/modules/statesManager/configStates.js +71 -71
  134. package/src/js/modules/statesManager/controller.js +170 -170
  135. package/src/js/modules/statesManager/functionsStorage.js +82 -82
  136. package/src/js/modules/statesManager/helper.js +27 -27
  137. package/src/js/modules/statesManager/race.js +75 -75
  138. package/src/js/modules/statesManager/sequence.js +47 -47
  139. package/src/js/modules/template/_info.js +6 -6
  140. package/src/js/modules/template/controller.js +28 -28
  141. package/src/js/modules/template/model.js +11 -11
  142. package/src/js/modules/template/service.js +137 -137
  143. package/src/js/modules/template/types.js +46 -46
  144. package/src/js/modules/transport/_info.js +8 -8
  145. package/src/js/modules/transport/baseConnectionType.js +24 -24
  146. package/src/js/modules/transport/config.js +13 -13
  147. package/src/js/modules/transport/connectionTypes/_info.js +3 -3
  148. package/src/js/modules/transport/connectionTypes/websocket.js +74 -74
  149. package/src/js/modules/transport/connectionTypes/xhr.js +44 -44
  150. package/src/js/modules/transport/controller.js +48 -48
  151. package/src/js/modules/transport/decorator.js +17 -17
  152. package/src/js/modules/transport/service.js +153 -153
  153. package/src/js/templates/_info.js +4 -4
  154. package/src/js/templates/groups/_info.js +1 -1
  155. package/src/js/templates/scenes/_info.js +1 -1
  156. package/webpack.config.js +47 -47
  157. package/src/js/components/editor/_info.js +0 -4
  158. package/src/js/components/editor/api.js +0 -72
  159. package/src/js/components/editor/controller.js +0 -13
@@ -1,675 +1,675 @@
1
- const ModulesObjectsModelsContainer = require('./container.js');
2
- const containers = [];
3
-
4
- class ModulesObjectsModelsDragContainer extends ModulesObjectsModelsContainer {
5
- _mask = null;
6
- _interactiveLayer = null;
7
- _startPosition = null;
8
- _startY = 0;
9
- _offsetStartY = 0;
10
- _needBlock = false;
11
- _needMoveSlider = true;
12
- _moveStartedY = 0;
13
- _dragStarted = false;
14
- _minMoveDurationForEasing = 100;
15
- _minMoveDistanceForEasing = 50;
16
- _minMoveDistance = 15;
17
-
18
- constructor(params) {
19
- super(params);
20
-
21
- this.type = Urso.types.objects.DRAGCONTAINER;
22
-
23
- this._onScrollSliderMove = this._onScrollSliderMove.bind(this);
24
- this._sliderHandleDrop = this._sliderHandleDrop.bind(this);
25
- this._setSliderHandler = this._setSliderHandler.bind(this);
26
- this._switchBlock = this._switchBlock.bind(this);
27
- this._pointerEventsHandler = this._pointerEventsHandler.bind(this);
28
-
29
- this._setupDragContainer();
30
- containers.push(this);
31
- }
32
-
33
- /**
34
- * Setups initial params on create.
35
- * @param { Object } params
36
- */
37
- setupParams(params) {
38
- super.setupParams(params);
39
- this.speed = Urso.helper.recursiveGet('speed', params, 1);
40
- this.dragIndex = Urso.helper.recursiveGet('dragIndex', params, 0);
41
- this.sliderClass = Urso.helper.recursiveGet('sliderClass', params, false);
42
- this.onMoveCallback = Urso.helper.recursiveGet('onMoveCallback', params, false);
43
- this.easingTime = Urso.helper.recursiveGet('easingTime', params, 1.5);
44
- this.easingDistance = Urso.helper.recursiveGet('easingDistance', params, 200);
45
- this.zIndex = Urso.helper.recursiveGet('zIndex', params, 10);
46
- this.width = Urso.helper.recursiveGet('width', params, 200); // Width of container visible area. Numbers only.
47
- this.height = Urso.helper.recursiveGet('height', params, 200); // Height of container visible area. Numbers only.
48
- }
49
-
50
- /**
51
- * Checks if interactive layer is visible and move in progress.
52
- * @returns { Boolean }
53
- */
54
- get _moveInProgress() {
55
- return this._interactiveLayer.visible
56
- }
57
-
58
- /**
59
- * Sets interactiveLayer visibility.
60
- */
61
- set _moveInProgress(inProgress) {
62
- this._interactiveLayer.visible = inProgress;
63
- }
64
-
65
- /**
66
- * Resizes mask and interactiveLayer according dragContainer size
67
- * @param { Boolean } needResetMaskY
68
- */
69
- resize(needResetMaskY) {
70
- this._resizeInteractiveLayer();
71
- this._resizeMask();
72
-
73
- if (needResetMaskY) {
74
- this._mask.y = 0;
75
- }
76
- }
77
-
78
- /**
79
- * Initial setup dragContainers params.
80
- */
81
- _setupDragContainer() {
82
- this._setMask();
83
- this._resizeInteractiveLayer();
84
- this._resizeMask();
85
- this._setResizeReactively();
86
- }
87
-
88
- /**
89
- * Subscribes resize() method on dragContauber width/height params change
90
- */
91
- _setResizeReactively() {
92
- Urso.helper.reactive(this, 'width', () => this.resize());
93
- Urso.helper.reactive(this, 'height', () => this.resize());
94
- }
95
-
96
- /**
97
- * Setups mask and interactive layer of dragContainer
98
- */
99
- _setMask() {
100
- this._mask = this._makeMask();
101
-
102
- this._interactiveLayer = this._makeInteractiveLayer();
103
- this._interactiveLayer.on('pointermove', (e) => this._onPointerMove(e));
104
-
105
- this._baseObject.addChild(this._mask);
106
- this._baseObject.addChild(this._interactiveLayer);
107
-
108
- this._baseObject.mask = this._mask;
109
- }
110
-
111
- /**
112
- * Function takes pointer coords and checks if pointer over current dragContainer.
113
- * @param { Object } coords
114
- * @returns { Boolean }
115
- */
116
- _isActive({ x, y }) {
117
- const pointerOverContainers = containers
118
- .filter((container) => {
119
- const points = this._getObjectPoints(container);
120
- return this._checkPointerOver({ x, y }, ...points);
121
- })
122
- .filter((container) => container._baseObject.worldVisible)
123
- .filter((container) => !container._needBlock)
124
- .filter((container) => {
125
- let height = container.getAbsoluteSize().height;
126
- return container.height - height < 0;
127
- })
128
- .sort((firstContainer, secondContainer) => secondContainer.dragIndex - firstContainer.dragIndex);
129
-
130
- return pointerOverContainers[0] === this;
131
- }
132
-
133
- /**
134
- * Hides attached slider if dragContainer cannot be scrolled
135
- */
136
- _changeSliderVisibility() {
137
- if (!this._slider)
138
- return;
139
-
140
- this._slider.visible = this.height < this._baseObject.height;
141
- }
142
-
143
- /**
144
- * Function takes pointer coords and coords of the two container's vertexes
145
- * returns relative position of pointer between two points
146
- * @param { Object } pointerCoords
147
- * @param { Object } point1
148
- * @param { Object } point2
149
- * @returns { Number }
150
- */
151
- _getPointerRelativePosition(pointerCoords, point1, point2) {
152
- const xDelta = point2.x - point1.x;
153
- const yDelta = point2.y - point1.y;
154
- const poiterDeltaY = pointerCoords.y - point1.y;
155
- const poiterDeltaX = pointerCoords.x - point1.x;
156
- return xDelta * poiterDeltaY - yDelta * poiterDeltaX;
157
- }
158
-
159
- /**
160
- * Takes pointer coords and dragContainer vertexes coords.
161
- * Checks if pointer is inside dragContainer rectangle.
162
- * @param { Object } pointerCoords
163
- * @param { Object } pointA
164
- * @param { Object } pointB
165
- * @param { Object } pointC
166
- * @param { Object } pointD
167
- * @returns { Boolean }
168
- */
169
- _checkPointerOver(pointerCoords, pointA, pointB, pointC, pointD) {
170
- const point1 = this._getPointerRelativePosition(pointerCoords, pointA, pointB);
171
- const point2 = this._getPointerRelativePosition(pointerCoords, pointB, pointC);
172
- const point3 = this._getPointerRelativePosition(pointerCoords, pointC, pointD);
173
- const point4 = this._getPointerRelativePosition(pointerCoords, pointD, pointA);
174
- return (point1 < 0 && point2 < 0 && point3 < 0 && point4 < 0) || (point1 > 0 && point2 > 0 && point3 > 0 && point4 > 0);
175
- }
176
-
177
- /**
178
- * Function takes container object and calculate it's vertexes coords.
179
- * Returns array of coords.
180
- * @param { Object } container
181
- * @returns { Array }
182
- */
183
- _getObjectPoints(container) {
184
- if (Urso.device.desktop) {
185
- const { x, y } = this._getScaleAndPositionRecursive(this);
186
- const { width, height } = container._mask;
187
- const { scaleX, scaleY } = this._getScaleAndPositionRecursive(this);
188
-
189
- return [
190
- { x, y },
191
- { x: x + width * scaleX, y },
192
- { x: x + width * scaleX, y: y + height * scaleY },
193
- { x, y: y + height * scaleY }
194
- ];
195
-
196
- } else {
197
- const { x, y } = container._mask.toGlobal(new PIXI.Point(0, 0));
198
- const { width, height } = container._mask;
199
- const { scaleX, scaleY } = this._getScaleAndPositionRecursive(this);
200
- return [
201
- { x, y },
202
- { x: x + width * scaleX, y },
203
- { x: x + width * scaleX, y: y + height * scaleY },
204
- { x, y: y + height * scaleY }
205
- ];
206
- }
207
-
208
- }
209
-
210
- /**
211
- * Function takes dragContainer object and recurcievly calculates it's global scale and position
212
- * @param { Object }
213
- * @returns
214
- */
215
- _getScaleAndPositionRecursive({ scaleX, scaleY, parent, x, y }) {
216
- if (!parent) {
217
- return { scaleX, scaleY, x, y };
218
- }
219
-
220
- const { scaleX: parentScaleX, scaleY: parentScaleY, x: parentX, y: parentY } = this._getScaleAndPositionRecursive(parent);
221
-
222
- return {
223
- scaleX: scaleX * parentScaleX,
224
- scaleY: scaleY * parentScaleY,
225
- x: x + parentX,
226
- y: y + parentY,
227
- }
228
- }
229
-
230
- /**
231
- * Callback on pointer move. Takes pointer event data.
232
- * @param { Object } e
233
- */
234
- _documentPointerMove(e) {
235
- if(!this._movePossible)
236
- return;
237
-
238
- this._moveInProgress = true;
239
- let offset = e.offsetY || e.changedTouches[0].offsetY || e.changedTouches[0].clientY;
240
-
241
- if (Math.abs(this._moveStartedY - offset) > this._minMoveDistance && !this._dragStarted) {
242
- this._dragStarted = true;
243
- this.emit(Urso.events.MODULES_OBJECTS_DRAGCONTAINER_DRAG_STARTED, { name: this.name, className: this.class, id: this.id });
244
- }
245
- }
246
-
247
- /**
248
- * Callback on move end. Unblock all dragContainers and if move was longer than requred minimum starts easing
249
- */
250
- _documentPointerEnd() {
251
- this._movePossible = false;
252
- const timeDelta = Date.now() - this._lastMoveTime;
253
- this.emit(Urso.events.MODULES_OBJECTS_DRAGCONTAINER_SWITCHBLOCK, { names: ['*'], needBlock: false });
254
-
255
- if (this._wasMoved && timeDelta < this._minMoveDurationForEasing)
256
- this._startMoveEasing();
257
- else
258
- this._startPosition = null;
259
-
260
- this._onMoveComplete();
261
- this._wasMoved = false;
262
- }
263
-
264
- /**
265
- * Starts easing animation in the end of move
266
- */
267
- _startMoveEasing() {
268
- const targetY = this._getEasingTargetY();
269
-
270
- if (!targetY) {
271
- this._startPosition = null;
272
- return
273
- };
274
-
275
- let obj = { y: this._baseObject.y };
276
-
277
- this._easingTween = gsap.to(obj, this.easingTime, {
278
- y: targetY, ease: 'power2',
279
- onUpdate: () => {
280
- this._move(obj.y, true);
281
- this._isBorder && this._killTweens();
282
- },
283
- onComplete: () => {
284
- this._startPosition = null;
285
- }
286
- })
287
- }
288
-
289
- /**
290
- * Kills al animation tweens
291
- */
292
- _killTweens() {
293
- if (this._easingTween) {
294
- this._easingTween.pause();
295
- this._easingTween.kill(true);
296
- this._easingTween = null;
297
- this._startPosition = null;
298
- };
299
- }
300
-
301
- /**
302
- * Calculates target move coordinate of easing
303
- * @returns { Number }
304
- */
305
- _getEasingTargetY() {
306
- const multipler = this._moveStartY > this._baseObject.y ? -1 : 1;
307
-
308
- if (Math.abs(this._moveStartY - this._baseObject.y) < this._minMoveDistanceForEasing)
309
- return false;
310
-
311
- return this._baseObject.y + this.easingDistance * multipler;
312
- }
313
-
314
- /**
315
- * Resets params on move callback
316
- */
317
- _onMoveComplete() {
318
- this._moveInProgress = false;
319
- this._dragStarted = false;
320
- this._isWheelMove = false;
321
- this.emit(Urso.events.MODULES_OBJECTS_DRAGCONTAINER_DRAG_FINISHED, { name: this.name, className: this.class, id: this.id });
322
- this._isBorder = false;
323
- }
324
-
325
- /**
326
- * Checks if next dragContainer Y coordinate is in possible range.
327
- * If it's out of possible range returns nearest possible point.
328
- * @param { Number } y
329
- * @param { Number } lastPosY
330
- * @param { Number } deltaY
331
- * @returns { Number }
332
- */
333
- _getValidatedY(y, lastPosY, deltaY) {
334
- if (y > 0) {
335
- this._startY = -deltaY;
336
- y = 0;
337
- }
338
-
339
- if (lastPosY > y) {
340
- this._startY = lastPosY - deltaY;
341
- this._isBorder = true;
342
- y = lastPosY;
343
- }
344
-
345
- const possibleMinY = this.height - this._calcMaxY(this._baseObject);
346
-
347
- if (y < possibleMinY) {
348
- y = possibleMinY;
349
- this._isBorder = true
350
- }
351
-
352
- return y;
353
- }
354
-
355
- /**
356
- * Calculates max possible dragContainer Y
357
- * @param { Object } pixiObject
358
- * @returns { Number }
359
- */
360
- _calcMaxY(pixiObject) {
361
- let maxY = 0;
362
-
363
- pixiObject.children.forEach(element => {
364
- if (element.isMask)
365
- return;
366
-
367
- const elementLimit = element.y + element.height;
368
-
369
- if (elementLimit > maxY)
370
- maxY = elementLimit;
371
- });
372
-
373
- return maxY;
374
- }
375
-
376
- /**
377
- * Validates next dragContainer position.
378
- * @param { Number } lastY
379
- * @param { Boolean } isWheel
380
- * @returns
381
- */
382
- _validateY(lastY, isWheel) {
383
- const deltaY = isWheel ? lastY * this.speed : ((lastY - this._startPosition.y) * this.speed);
384
- const lastPosY = this._mask.height - this._baseObject.height;
385
- const targetY = isWheel ? lastY : this._startY + deltaY
386
- return this._getValidatedY(targetY, lastPosY, deltaY);;
387
- }
388
-
389
- /**
390
- * Moves dragContainer
391
- * @param { Number } nextY
392
- * @param { Boolean } isWheel
393
- */
394
- _move(nextY, isWheel) {
395
- this._lastMoveTime = Date.now();
396
- this._onMoveCallback();
397
- const y = this._validateY(nextY, isWheel);
398
- this._setNewPosition(y);
399
- this._mask.y = -y;
400
- this._interactiveLayer.y = -y;
401
- this._needMoveSlider && this._setSliderPosition(y);
402
- }
403
-
404
- /**
405
- * Calls given onMoveCallback if it's exists
406
- */
407
- _onMoveCallback() {
408
- this.onMoveCallback && this.onMoveCallback();
409
- }
410
-
411
- /**
412
- * Sets slider.
413
- */
414
- _setSlider() {
415
- if (!this.sliderClass)
416
- return
417
-
418
- this._slider = Urso.findOne(`.${this.sliderClass}`);
419
- }
420
-
421
- /**
422
- * Updates slider position alongside with dragged container.
423
- * @param { Number } y
424
- */
425
- _setSliderPosition(y) {
426
- if (!this._slider)
427
- return;
428
-
429
- const { height } = this.getAbsoluteSize();
430
-
431
- const positionChange = y / (height - this.height);
432
- const { _sliderHandle, _sliderSize } = this._slider;
433
- _sliderHandle.y = -(_sliderSize * positionChange);
434
- }
435
-
436
- /**
437
- * Callback on move start.
438
- */
439
- _documentPointerStart() {
440
- this._startY = this._getCurrentY();
441
- this._moveStartY = this._getCurrentY();
442
- this._startTime = Date.now();
443
- this._movePossible = true;
444
- this._killTweens();
445
- }
446
-
447
- /**
448
- * Sets dragContainer validated position.
449
- * @param { Number } y
450
- */
451
- _setNewPosition(y) {
452
- this._baseObject.y = y;
453
- }
454
-
455
- /**
456
- * Returns current container position.
457
- * @returns { Number }
458
- */
459
- _getCurrentY() {
460
- return this._baseObject.y;
461
- }
462
-
463
- /**
464
- * Moves container on wheel scroll.
465
- * @param { Object }
466
- */
467
- _documentWheelScroll({ x, y, deltaY }) {
468
- if (Urso.device.desktop) {
469
- x = Urso.scenes.getMouseCoords().x;
470
- y = Urso.scenes.getMouseCoords().y;
471
- }
472
-
473
- if (!this._isActive({ x, y }))
474
- return;
475
-
476
- this._isWheelMove = true;
477
-
478
- this._killTweens();
479
- const { x: startX, y: startY } = this._baseObject;
480
- this._startPosition = { x: startX, y: startY };
481
- this._moveStartY = this._getCurrentY();
482
- const nextY = startY - deltaY;
483
-
484
- this.emit(Urso.events.MODULES_OBJECTS_DRAGCONTAINER_SCROLL, { name: this.name, className: this.class, id: this.id });
485
-
486
- this._move(nextY, true);
487
- this._startMoveEasing();
488
- }
489
-
490
- /**
491
- * Drags container on pointer move.
492
- * @param { Object } event
493
- */
494
- _onPointerMove(event) {
495
- let { data: { global: { x, y } } } = event;
496
-
497
- if (Urso.device.desktop) {
498
- x = Urso.scenes.getMouseCoords().x;
499
- y = Urso.scenes.getMouseCoords().y;
500
- }
501
-
502
- if (!this._startPosition) {
503
- this._startPosition = { x, y };
504
- }
505
-
506
-
507
- if (!this._isActive({ x, y })) {
508
- this._moveInProgress = false;
509
- return;
510
- }
511
-
512
- this._wasMoved = true;
513
- this._move(y);
514
- }
515
-
516
- /**
517
- * Resizes mask according dragContainer size.
518
- */
519
- _resizeMask() {
520
- this._mask.width = this.width;
521
- this._mask.height = this.height;
522
- }
523
-
524
- /**
525
- * Resizes interactive layer according dragContainer size.
526
- */
527
- _resizeInteractiveLayer() {
528
- this._interactiveLayer.width = this.width;
529
- this._interactiveLayer.height = this.height;
530
- }
531
-
532
- /**
533
- * Creates a PIXI.Graohics rectangle which represents area in which we can interact with dragContainer.
534
- * @returns { Object }
535
- */
536
- _makeInteractiveLayer() {
537
- let layer = new PIXI.Graphics();
538
- layer.beginFill(0xffffff);
539
- layer.drawRect(0, 0, 1, 1);
540
- layer.endFill();
541
- layer.zIndex = this.zIndex;
542
- layer.alpha = 0;
543
- layer.visible = false;
544
- layer.interactive = true;
545
- return layer;
546
- }
547
-
548
- /**
549
- * Create PIXI.Graohics object that used as mask of dragContainer.
550
- * @returns { Object }
551
- */
552
- _makeMask() {
553
- let mask = new PIXI.Graphics();
554
- mask.lineStyle(0);
555
- mask.beginFill(0xffffff);
556
- mask.drawRect(0, 0, 1, 1);
557
- mask.endFill();
558
- return mask;
559
- }
560
-
561
- /**
562
- * Moves dragContainer via attached slider.
563
- * @param { Object }
564
- */
565
- _onScrollSliderMove({ position, class: className }) {
566
- if (className !== this.sliderClass)
567
- return
568
-
569
- if (this.height >= this._baseObject.height) {
570
- this._slider._moveSlider({ x: 0, y: 0 }, true, true);
571
- return;
572
- }
573
-
574
- const { _sliderSize } = this._slider;
575
- const containerHeight = this._mask.height - this._baseObject.height;
576
- const diffY = position > 0 ? position / _sliderSize * containerHeight : 0;
577
-
578
- this._needMoveSlider = false;
579
- this._move(diffY, true)
580
- }
581
-
582
- /**
583
- * Callback on slider move end.
584
- * @param { Object }
585
- */
586
- _sliderHandleDrop({ class: className }) {
587
- if (className === this.sliderClass)
588
- this._needMoveSlider = true;
589
- }
590
-
591
- /**
592
- * function recieves object that contains an array of dragcontainer's names or ['*'] if we need block all dragContainers
593
- * @param { Object } blockParams
594
- */
595
- _switchBlock(blockParams) {
596
- if (!blockParams)
597
- return;
598
-
599
- const { names, needBlock } = blockParams;
600
-
601
- if (names.includes(this.name) || names.includes('*')) {
602
- this._needBlock = needBlock;
603
- }
604
- }
605
-
606
- /**
607
- * Checks if need to set slider. If no dragContainerName - slider will be set for all dragContainers.
608
- * @param {String} dragContainerName
609
- * @returns
610
- */
611
- _setSliderHandler(dragContainerName) {
612
- if (dragContainerName && dragContainerName !== this.name)
613
- return;
614
-
615
- this._setSlider();
616
- }
617
-
618
- /**
619
- * Sets callbacks on pointer events
620
- */
621
- _pointerEventsHandler(event) {
622
- switch (event.type) {
623
- case 'mousedown':
624
- this._moveStartedY = event.offsetY;
625
- this._documentPointerStart(e);
626
- break;
627
- case 'touchstart':
628
- this._offsetStartY = event.changedTouches[0].offsetY;
629
- this._moveStartedY = event.changedTouches[0].offsetY || event.changedTouches[0].clientY;
630
- this._documentPointerStart(event);
631
- break;
632
- case 'touchmove':
633
- this._documentPointerMove(event);
634
- break;
635
- case 'touchend':
636
- case 'mouseup':
637
- this._documentPointerEnd(event);
638
- break;
639
- case 'wheel':
640
- this._documentWheelScroll(event);
641
- break;
642
- case 'pointermove':
643
- this._onPointerMove(event);
644
- break;
645
- default:
646
- break;
647
- }
648
- }
649
-
650
- /**
651
- * Unsubscribes methods on object destroy.
652
- */
653
- _customDestroy() {
654
- this.removeListener(Urso.events.EXTRA_BROWSEREVENTS_POINTER_EVENT, this._pointerEventsHandler);
655
- this.removeListener(Urso.events.MODULES_OBJECTS_SLIDER_HANDLE_MOVE, this._onScrollSliderMove);
656
- this.removeListener(Urso.events.MODULES_OBJECTS_SLIDER_HANDLE_DROP, this._sliderHandleDrop);
657
- this.removeListener(Urso.events.MODULES_SCENES_DISPLAY_FINISHED, this._setSliderHandler);
658
- this.removeListener(Urso.events.MODULES_OBJECTS_DRAGCONTAINER_SETSLIDER, this._setSliderHandler);
659
- this.removeListener(Urso.events.MODULES_OBJECTS_DRAGCONTAINER_SWITCHBLOCK, this._switchBlock);
660
- }
661
-
662
- /**
663
- * Subscribes methods.
664
- */
665
- _subscribeOnce() {
666
- this.addListener(Urso.events.EXTRA_BROWSEREVENTS_POINTER_EVENT, this._pointerEventsHandler);
667
- this.addListener(Urso.events.MODULES_OBJECTS_SLIDER_HANDLE_MOVE, this._onScrollSliderMove);
668
- this.addListener(Urso.events.MODULES_OBJECTS_SLIDER_HANDLE_DROP, this._sliderHandleDrop);
669
- this.addListener(Urso.events.MODULES_SCENES_DISPLAY_FINISHED, this._setSliderHandler);
670
- this.addListener(Urso.events.MODULES_OBJECTS_DRAGCONTAINER_SETSLIDER, this._setSliderHandler);
671
- this.addListener(Urso.events.MODULES_OBJECTS_DRAGCONTAINER_SWITCHBLOCK, this._switchBlock);
672
- }
673
- }
674
-
675
- module.exports = ModulesObjectsModelsDragContainer;
1
+ const ModulesObjectsModelsContainer = require('./container.js');
2
+ const containers = [];
3
+
4
+ class ModulesObjectsModelsDragContainer extends ModulesObjectsModelsContainer {
5
+ _mask = null;
6
+ _interactiveLayer = null;
7
+ _startPosition = null;
8
+ _startY = 0;
9
+ _offsetStartY = 0;
10
+ _needBlock = false;
11
+ _needMoveSlider = true;
12
+ _moveStartedY = 0;
13
+ _dragStarted = false;
14
+ _minMoveDurationForEasing = 100;
15
+ _minMoveDistanceForEasing = 50;
16
+ _minMoveDistance = 15;
17
+
18
+ constructor(params) {
19
+ super(params);
20
+
21
+ this.type = Urso.types.objects.DRAGCONTAINER;
22
+
23
+ this._onScrollSliderMove = this._onScrollSliderMove.bind(this);
24
+ this._sliderHandleDrop = this._sliderHandleDrop.bind(this);
25
+ this._setSliderHandler = this._setSliderHandler.bind(this);
26
+ this._switchBlock = this._switchBlock.bind(this);
27
+ this._pointerEventsHandler = this._pointerEventsHandler.bind(this);
28
+
29
+ this._setupDragContainer();
30
+ containers.push(this);
31
+ }
32
+
33
+ /**
34
+ * Setups initial params on create.
35
+ * @param { Object } params
36
+ */
37
+ setupParams(params) {
38
+ super.setupParams(params);
39
+ this.speed = Urso.helper.recursiveGet('speed', params, 1);
40
+ this.dragIndex = Urso.helper.recursiveGet('dragIndex', params, 0);
41
+ this.sliderClass = Urso.helper.recursiveGet('sliderClass', params, false);
42
+ this.onMoveCallback = Urso.helper.recursiveGet('onMoveCallback', params, false);
43
+ this.easingTime = Urso.helper.recursiveGet('easingTime', params, 1.5);
44
+ this.easingDistance = Urso.helper.recursiveGet('easingDistance', params, 200);
45
+ this.zIndex = Urso.helper.recursiveGet('zIndex', params, 10);
46
+ this.width = Urso.helper.recursiveGet('width', params, 200); // Width of container visible area. Numbers only.
47
+ this.height = Urso.helper.recursiveGet('height', params, 200); // Height of container visible area. Numbers only.
48
+ }
49
+
50
+ /**
51
+ * Checks if interactive layer is visible and move in progress.
52
+ * @returns { Boolean }
53
+ */
54
+ get _moveInProgress() {
55
+ return this._interactiveLayer.visible
56
+ }
57
+
58
+ /**
59
+ * Sets interactiveLayer visibility.
60
+ */
61
+ set _moveInProgress(inProgress) {
62
+ this._interactiveLayer.visible = inProgress;
63
+ }
64
+
65
+ /**
66
+ * Resizes mask and interactiveLayer according dragContainer size
67
+ * @param { Boolean } needResetMaskY
68
+ */
69
+ resize(needResetMaskY) {
70
+ this._resizeInteractiveLayer();
71
+ this._resizeMask();
72
+
73
+ if (needResetMaskY) {
74
+ this._mask.y = 0;
75
+ }
76
+ }
77
+
78
+ /**
79
+ * Initial setup dragContainers params.
80
+ */
81
+ _setupDragContainer() {
82
+ this._setMask();
83
+ this._resizeInteractiveLayer();
84
+ this._resizeMask();
85
+ this._setResizeReactively();
86
+ }
87
+
88
+ /**
89
+ * Subscribes resize() method on dragContauber width/height params change
90
+ */
91
+ _setResizeReactively() {
92
+ Urso.helper.reactive(this, 'width', () => this.resize());
93
+ Urso.helper.reactive(this, 'height', () => this.resize());
94
+ }
95
+
96
+ /**
97
+ * Setups mask and interactive layer of dragContainer
98
+ */
99
+ _setMask() {
100
+ this._mask = this._makeMask();
101
+
102
+ this._interactiveLayer = this._makeInteractiveLayer();
103
+ this._interactiveLayer.on('pointermove', (e) => this._onPointerMove(e));
104
+
105
+ this._baseObject.addChild(this._mask);
106
+ this._baseObject.addChild(this._interactiveLayer);
107
+
108
+ this._baseObject.mask = this._mask;
109
+ }
110
+
111
+ /**
112
+ * Function takes pointer coords and checks if pointer over current dragContainer.
113
+ * @param { Object } coords
114
+ * @returns { Boolean }
115
+ */
116
+ _isActive({ x, y }) {
117
+ const pointerOverContainers = containers
118
+ .filter((container) => {
119
+ const points = this._getObjectPoints(container);
120
+ return this._checkPointerOver({ x, y }, ...points);
121
+ })
122
+ .filter((container) => container._baseObject.worldVisible)
123
+ .filter((container) => !container._needBlock)
124
+ .filter((container) => {
125
+ let height = container.getAbsoluteSize().height;
126
+ return container.height - height < 0;
127
+ })
128
+ .sort((firstContainer, secondContainer) => secondContainer.dragIndex - firstContainer.dragIndex);
129
+
130
+ return pointerOverContainers[0] === this;
131
+ }
132
+
133
+ /**
134
+ * Hides attached slider if dragContainer cannot be scrolled
135
+ */
136
+ _changeSliderVisibility() {
137
+ if (!this._slider)
138
+ return;
139
+
140
+ this._slider.visible = this.height < this._baseObject.height;
141
+ }
142
+
143
+ /**
144
+ * Function takes pointer coords and coords of the two container's vertexes
145
+ * returns relative position of pointer between two points
146
+ * @param { Object } pointerCoords
147
+ * @param { Object } point1
148
+ * @param { Object } point2
149
+ * @returns { Number }
150
+ */
151
+ _getPointerRelativePosition(pointerCoords, point1, point2) {
152
+ const xDelta = point2.x - point1.x;
153
+ const yDelta = point2.y - point1.y;
154
+ const poiterDeltaY = pointerCoords.y - point1.y;
155
+ const poiterDeltaX = pointerCoords.x - point1.x;
156
+ return xDelta * poiterDeltaY - yDelta * poiterDeltaX;
157
+ }
158
+
159
+ /**
160
+ * Takes pointer coords and dragContainer vertexes coords.
161
+ * Checks if pointer is inside dragContainer rectangle.
162
+ * @param { Object } pointerCoords
163
+ * @param { Object } pointA
164
+ * @param { Object } pointB
165
+ * @param { Object } pointC
166
+ * @param { Object } pointD
167
+ * @returns { Boolean }
168
+ */
169
+ _checkPointerOver(pointerCoords, pointA, pointB, pointC, pointD) {
170
+ const point1 = this._getPointerRelativePosition(pointerCoords, pointA, pointB);
171
+ const point2 = this._getPointerRelativePosition(pointerCoords, pointB, pointC);
172
+ const point3 = this._getPointerRelativePosition(pointerCoords, pointC, pointD);
173
+ const point4 = this._getPointerRelativePosition(pointerCoords, pointD, pointA);
174
+ return (point1 < 0 && point2 < 0 && point3 < 0 && point4 < 0) || (point1 > 0 && point2 > 0 && point3 > 0 && point4 > 0);
175
+ }
176
+
177
+ /**
178
+ * Function takes container object and calculate it's vertexes coords.
179
+ * Returns array of coords.
180
+ * @param { Object } container
181
+ * @returns { Array }
182
+ */
183
+ _getObjectPoints(container) {
184
+ if (Urso.device.desktop) {
185
+ const { x, y } = this._getScaleAndPositionRecursive(this);
186
+ const { width, height } = container._mask;
187
+ const { scaleX, scaleY } = this._getScaleAndPositionRecursive(this);
188
+
189
+ return [
190
+ { x, y },
191
+ { x: x + width * scaleX, y },
192
+ { x: x + width * scaleX, y: y + height * scaleY },
193
+ { x, y: y + height * scaleY }
194
+ ];
195
+
196
+ } else {
197
+ const { x, y } = container._mask.toGlobal(new PIXI.Point(0, 0));
198
+ const { width, height } = container._mask;
199
+ const { scaleX, scaleY } = this._getScaleAndPositionRecursive(this);
200
+ return [
201
+ { x, y },
202
+ { x: x + width * scaleX, y },
203
+ { x: x + width * scaleX, y: y + height * scaleY },
204
+ { x, y: y + height * scaleY }
205
+ ];
206
+ }
207
+
208
+ }
209
+
210
+ /**
211
+ * Function takes dragContainer object and recurcievly calculates it's global scale and position
212
+ * @param { Object }
213
+ * @returns
214
+ */
215
+ _getScaleAndPositionRecursive({ scaleX, scaleY, parent, x, y }) {
216
+ if (!parent) {
217
+ return { scaleX, scaleY, x, y };
218
+ }
219
+
220
+ const { scaleX: parentScaleX, scaleY: parentScaleY, x: parentX, y: parentY } = this._getScaleAndPositionRecursive(parent);
221
+
222
+ return {
223
+ scaleX: scaleX * parentScaleX,
224
+ scaleY: scaleY * parentScaleY,
225
+ x: x + parentX,
226
+ y: y + parentY,
227
+ }
228
+ }
229
+
230
+ /**
231
+ * Callback on pointer move. Takes pointer event data.
232
+ * @param { Object } e
233
+ */
234
+ _documentPointerMove(e) {
235
+ if(!this._movePossible)
236
+ return;
237
+
238
+ this._moveInProgress = true;
239
+ let offset = e.offsetY || e.changedTouches[0].offsetY || e.changedTouches[0].clientY;
240
+
241
+ if (Math.abs(this._moveStartedY - offset) > this._minMoveDistance && !this._dragStarted) {
242
+ this._dragStarted = true;
243
+ this.emit(Urso.events.MODULES_OBJECTS_DRAGCONTAINER_DRAG_STARTED, { name: this.name, className: this.class, id: this.id });
244
+ }
245
+ }
246
+
247
+ /**
248
+ * Callback on move end. Unblock all dragContainers and if move was longer than requred minimum starts easing
249
+ */
250
+ _documentPointerEnd() {
251
+ this._movePossible = false;
252
+ const timeDelta = Date.now() - this._lastMoveTime;
253
+ this.emit(Urso.events.MODULES_OBJECTS_DRAGCONTAINER_SWITCHBLOCK, { names: ['*'], needBlock: false });
254
+
255
+ if (this._wasMoved && timeDelta < this._minMoveDurationForEasing)
256
+ this._startMoveEasing();
257
+ else
258
+ this._startPosition = null;
259
+
260
+ this._onMoveComplete();
261
+ this._wasMoved = false;
262
+ }
263
+
264
+ /**
265
+ * Starts easing animation in the end of move
266
+ */
267
+ _startMoveEasing() {
268
+ const targetY = this._getEasingTargetY();
269
+
270
+ if (!targetY) {
271
+ this._startPosition = null;
272
+ return
273
+ };
274
+
275
+ let obj = { y: this._baseObject.y };
276
+
277
+ this._easingTween = gsap.to(obj, this.easingTime, {
278
+ y: targetY, ease: 'power2',
279
+ onUpdate: () => {
280
+ this._move(obj.y, true);
281
+ this._isBorder && this._killTweens();
282
+ },
283
+ onComplete: () => {
284
+ this._startPosition = null;
285
+ }
286
+ })
287
+ }
288
+
289
+ /**
290
+ * Kills al animation tweens
291
+ */
292
+ _killTweens() {
293
+ if (this._easingTween) {
294
+ this._easingTween.pause();
295
+ this._easingTween.kill(true);
296
+ this._easingTween = null;
297
+ this._startPosition = null;
298
+ };
299
+ }
300
+
301
+ /**
302
+ * Calculates target move coordinate of easing
303
+ * @returns { Number }
304
+ */
305
+ _getEasingTargetY() {
306
+ const multipler = this._moveStartY > this._baseObject.y ? -1 : 1;
307
+
308
+ if (Math.abs(this._moveStartY - this._baseObject.y) < this._minMoveDistanceForEasing)
309
+ return false;
310
+
311
+ return this._baseObject.y + this.easingDistance * multipler;
312
+ }
313
+
314
+ /**
315
+ * Resets params on move callback
316
+ */
317
+ _onMoveComplete() {
318
+ this._moveInProgress = false;
319
+ this._dragStarted = false;
320
+ this._isWheelMove = false;
321
+ this.emit(Urso.events.MODULES_OBJECTS_DRAGCONTAINER_DRAG_FINISHED, { name: this.name, className: this.class, id: this.id });
322
+ this._isBorder = false;
323
+ }
324
+
325
+ /**
326
+ * Checks if next dragContainer Y coordinate is in possible range.
327
+ * If it's out of possible range returns nearest possible point.
328
+ * @param { Number } y
329
+ * @param { Number } lastPosY
330
+ * @param { Number } deltaY
331
+ * @returns { Number }
332
+ */
333
+ _getValidatedY(y, lastPosY, deltaY) {
334
+ if (y > 0) {
335
+ this._startY = -deltaY;
336
+ y = 0;
337
+ }
338
+
339
+ if (lastPosY > y) {
340
+ this._startY = lastPosY - deltaY;
341
+ this._isBorder = true;
342
+ y = lastPosY;
343
+ }
344
+
345
+ const possibleMinY = this.height - this._calcMaxY(this._baseObject);
346
+
347
+ if (y < possibleMinY) {
348
+ y = possibleMinY;
349
+ this._isBorder = true
350
+ }
351
+
352
+ return y;
353
+ }
354
+
355
+ /**
356
+ * Calculates max possible dragContainer Y
357
+ * @param { Object } pixiObject
358
+ * @returns { Number }
359
+ */
360
+ _calcMaxY(pixiObject) {
361
+ let maxY = 0;
362
+
363
+ pixiObject.children.forEach(element => {
364
+ if (element.isMask)
365
+ return;
366
+
367
+ const elementLimit = element.y + element.height;
368
+
369
+ if (elementLimit > maxY)
370
+ maxY = elementLimit;
371
+ });
372
+
373
+ return maxY;
374
+ }
375
+
376
+ /**
377
+ * Validates next dragContainer position.
378
+ * @param { Number } lastY
379
+ * @param { Boolean } isWheel
380
+ * @returns
381
+ */
382
+ _validateY(lastY, isWheel) {
383
+ const deltaY = isWheel ? lastY * this.speed : ((lastY - this._startPosition.y) * this.speed);
384
+ const lastPosY = this._mask.height - this._baseObject.height;
385
+ const targetY = isWheel ? lastY : this._startY + deltaY
386
+ return this._getValidatedY(targetY, lastPosY, deltaY);;
387
+ }
388
+
389
+ /**
390
+ * Moves dragContainer
391
+ * @param { Number } nextY
392
+ * @param { Boolean } isWheel
393
+ */
394
+ _move(nextY, isWheel) {
395
+ this._lastMoveTime = Date.now();
396
+ this._onMoveCallback();
397
+ const y = this._validateY(nextY, isWheel);
398
+ this._setNewPosition(y);
399
+ this._mask.y = -y;
400
+ this._interactiveLayer.y = -y;
401
+ this._needMoveSlider && this._setSliderPosition(y);
402
+ }
403
+
404
+ /**
405
+ * Calls given onMoveCallback if it's exists
406
+ */
407
+ _onMoveCallback() {
408
+ this.onMoveCallback && this.onMoveCallback();
409
+ }
410
+
411
+ /**
412
+ * Sets slider.
413
+ */
414
+ _setSlider() {
415
+ if (!this.sliderClass)
416
+ return
417
+
418
+ this._slider = Urso.findOne(`.${this.sliderClass}`);
419
+ }
420
+
421
+ /**
422
+ * Updates slider position alongside with dragged container.
423
+ * @param { Number } y
424
+ */
425
+ _setSliderPosition(y) {
426
+ if (!this._slider)
427
+ return;
428
+
429
+ const { height } = this.getAbsoluteSize();
430
+
431
+ const positionChange = y / (height - this.height);
432
+ const { _sliderHandle, _sliderSize } = this._slider;
433
+ _sliderHandle.y = -(_sliderSize * positionChange);
434
+ }
435
+
436
+ /**
437
+ * Callback on move start.
438
+ */
439
+ _documentPointerStart() {
440
+ this._startY = this._getCurrentY();
441
+ this._moveStartY = this._getCurrentY();
442
+ this._startTime = Date.now();
443
+ this._movePossible = true;
444
+ this._killTweens();
445
+ }
446
+
447
+ /**
448
+ * Sets dragContainer validated position.
449
+ * @param { Number } y
450
+ */
451
+ _setNewPosition(y) {
452
+ this._baseObject.y = y;
453
+ }
454
+
455
+ /**
456
+ * Returns current container position.
457
+ * @returns { Number }
458
+ */
459
+ _getCurrentY() {
460
+ return this._baseObject.y;
461
+ }
462
+
463
+ /**
464
+ * Moves container on wheel scroll.
465
+ * @param { Object }
466
+ */
467
+ _documentWheelScroll({ x, y, deltaY }) {
468
+ if (Urso.device.desktop) {
469
+ x = Urso.scenes.getMouseCoords().x;
470
+ y = Urso.scenes.getMouseCoords().y;
471
+ }
472
+
473
+ if (!this._isActive({ x, y }))
474
+ return;
475
+
476
+ this._isWheelMove = true;
477
+
478
+ this._killTweens();
479
+ const { x: startX, y: startY } = this._baseObject;
480
+ this._startPosition = { x: startX, y: startY };
481
+ this._moveStartY = this._getCurrentY();
482
+ const nextY = startY - deltaY;
483
+
484
+ this.emit(Urso.events.MODULES_OBJECTS_DRAGCONTAINER_SCROLL, { name: this.name, className: this.class, id: this.id });
485
+
486
+ this._move(nextY, true);
487
+ this._startMoveEasing();
488
+ }
489
+
490
+ /**
491
+ * Drags container on pointer move.
492
+ * @param { Object } event
493
+ */
494
+ _onPointerMove(event) {
495
+ let { data: { global: { x, y } } } = event;
496
+
497
+ if (Urso.device.desktop) {
498
+ x = Urso.scenes.getMouseCoords().x;
499
+ y = Urso.scenes.getMouseCoords().y;
500
+ }
501
+
502
+ if (!this._startPosition) {
503
+ this._startPosition = { x, y };
504
+ }
505
+
506
+
507
+ if (!this._isActive({ x, y })) {
508
+ this._moveInProgress = false;
509
+ return;
510
+ }
511
+
512
+ this._wasMoved = true;
513
+ this._move(y);
514
+ }
515
+
516
+ /**
517
+ * Resizes mask according dragContainer size.
518
+ */
519
+ _resizeMask() {
520
+ this._mask.width = this.width;
521
+ this._mask.height = this.height;
522
+ }
523
+
524
+ /**
525
+ * Resizes interactive layer according dragContainer size.
526
+ */
527
+ _resizeInteractiveLayer() {
528
+ this._interactiveLayer.width = this.width;
529
+ this._interactiveLayer.height = this.height;
530
+ }
531
+
532
+ /**
533
+ * Creates a PIXI.Graohics rectangle which represents area in which we can interact with dragContainer.
534
+ * @returns { Object }
535
+ */
536
+ _makeInteractiveLayer() {
537
+ let layer = new PIXI.Graphics();
538
+ layer.beginFill(0xffffff);
539
+ layer.drawRect(0, 0, 1, 1);
540
+ layer.endFill();
541
+ layer.zIndex = this.zIndex;
542
+ layer.alpha = 0;
543
+ layer.visible = false;
544
+ layer.interactive = true;
545
+ return layer;
546
+ }
547
+
548
+ /**
549
+ * Create PIXI.Graohics object that used as mask of dragContainer.
550
+ * @returns { Object }
551
+ */
552
+ _makeMask() {
553
+ let mask = new PIXI.Graphics();
554
+ mask.lineStyle(0);
555
+ mask.beginFill(0xffffff);
556
+ mask.drawRect(0, 0, 1, 1);
557
+ mask.endFill();
558
+ return mask;
559
+ }
560
+
561
+ /**
562
+ * Moves dragContainer via attached slider.
563
+ * @param { Object }
564
+ */
565
+ _onScrollSliderMove({ position, class: className }) {
566
+ if (className !== this.sliderClass)
567
+ return
568
+
569
+ if (this.height >= this._baseObject.height) {
570
+ this._slider._moveSlider({ x: 0, y: 0 }, true, true);
571
+ return;
572
+ }
573
+
574
+ const { _sliderSize } = this._slider;
575
+ const containerHeight = this._mask.height - this._baseObject.height;
576
+ const diffY = position > 0 ? position / _sliderSize * containerHeight : 0;
577
+
578
+ this._needMoveSlider = false;
579
+ this._move(diffY, true)
580
+ }
581
+
582
+ /**
583
+ * Callback on slider move end.
584
+ * @param { Object }
585
+ */
586
+ _sliderHandleDrop({ class: className }) {
587
+ if (className === this.sliderClass)
588
+ this._needMoveSlider = true;
589
+ }
590
+
591
+ /**
592
+ * function recieves object that contains an array of dragcontainer's names or ['*'] if we need block all dragContainers
593
+ * @param { Object } blockParams
594
+ */
595
+ _switchBlock(blockParams) {
596
+ if (!blockParams)
597
+ return;
598
+
599
+ const { names, needBlock } = blockParams;
600
+
601
+ if (names.includes(this.name) || names.includes('*')) {
602
+ this._needBlock = needBlock;
603
+ }
604
+ }
605
+
606
+ /**
607
+ * Checks if need to set slider. If no dragContainerName - slider will be set for all dragContainers.
608
+ * @param {String} dragContainerName
609
+ * @returns
610
+ */
611
+ _setSliderHandler(dragContainerName) {
612
+ if (dragContainerName && dragContainerName !== this.name)
613
+ return;
614
+
615
+ this._setSlider();
616
+ }
617
+
618
+ /**
619
+ * Sets callbacks on pointer events
620
+ */
621
+ _pointerEventsHandler(event) {
622
+ switch (event.type) {
623
+ case 'mousedown':
624
+ this._moveStartedY = event.offsetY;
625
+ this._documentPointerStart(event);
626
+ break;
627
+ case 'touchstart':
628
+ this._offsetStartY = event.changedTouches[0].offsetY;
629
+ this._moveStartedY = event.changedTouches[0].offsetY || event.changedTouches[0].clientY;
630
+ this._documentPointerStart(event);
631
+ break;
632
+ case 'touchmove':
633
+ this._documentPointerMove(event);
634
+ break;
635
+ case 'touchend':
636
+ case 'mouseup':
637
+ this._documentPointerEnd(event);
638
+ break;
639
+ case 'wheel':
640
+ this._documentWheelScroll(event);
641
+ break;
642
+ case 'pointermove':
643
+ this._onPointerMove(event);
644
+ break;
645
+ default:
646
+ break;
647
+ }
648
+ }
649
+
650
+ /**
651
+ * Unsubscribes methods on object destroy.
652
+ */
653
+ _customDestroy() {
654
+ this.removeListener(Urso.events.EXTRA_BROWSEREVENTS_POINTER_EVENT, this._pointerEventsHandler);
655
+ this.removeListener(Urso.events.MODULES_OBJECTS_SLIDER_HANDLE_MOVE, this._onScrollSliderMove);
656
+ this.removeListener(Urso.events.MODULES_OBJECTS_SLIDER_HANDLE_DROP, this._sliderHandleDrop);
657
+ this.removeListener(Urso.events.MODULES_SCENES_DISPLAY_FINISHED, this._setSliderHandler);
658
+ this.removeListener(Urso.events.MODULES_OBJECTS_DRAGCONTAINER_SETSLIDER, this._setSliderHandler);
659
+ this.removeListener(Urso.events.MODULES_OBJECTS_DRAGCONTAINER_SWITCHBLOCK, this._switchBlock);
660
+ }
661
+
662
+ /**
663
+ * Subscribes methods.
664
+ */
665
+ _subscribeOnce() {
666
+ this.addListener(Urso.events.EXTRA_BROWSEREVENTS_POINTER_EVENT, this._pointerEventsHandler);
667
+ this.addListener(Urso.events.MODULES_OBJECTS_SLIDER_HANDLE_MOVE, this._onScrollSliderMove);
668
+ this.addListener(Urso.events.MODULES_OBJECTS_SLIDER_HANDLE_DROP, this._sliderHandleDrop);
669
+ this.addListener(Urso.events.MODULES_SCENES_DISPLAY_FINISHED, this._setSliderHandler);
670
+ this.addListener(Urso.events.MODULES_OBJECTS_DRAGCONTAINER_SETSLIDER, this._setSliderHandler);
671
+ this.addListener(Urso.events.MODULES_OBJECTS_DRAGCONTAINER_SWITCHBLOCK, this._switchBlock);
672
+ }
673
+ }
674
+
675
+ module.exports = ModulesObjectsModelsDragContainer;