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