js-cloudimage-360-view 2.7.2-beta.0 → 2.7.2-beta.5

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.
@@ -1,29 +1,38 @@
1
- 'use strict';
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
2
4
 
3
5
  Object.defineProperty(exports, "__esModule", {
4
6
  value: true
5
7
  });
8
+ exports.default = void 0;
9
+
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
6
11
 
7
- var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
12
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
8
13
 
9
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
14
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
10
15
 
11
- var _ci = require('./ci360.utils');
16
+ var _ci = require("./ci360.utils");
12
17
 
13
- var _ci2 = require('./ci360.constants');
18
+ var _ci2 = require("./ci360.constants");
14
19
 
15
- require('./static/css/style.css');
20
+ require("./static/css/style.css");
16
21
 
17
- function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
22
+ var _jsCloudimage360ViewUtils = require("js-cloudimage-360-view-utils");
18
23
 
19
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
24
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
20
25
 
21
- var CI360Viewer = function () {
22
- function CI360Viewer(container, fullscreen, ratio) {
23
- _classCallCheck(this, CI360Viewer);
26
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
24
27
 
28
+ var CI360Viewer = /*#__PURE__*/function () {
29
+ function CI360Viewer(container, fullscreen) {
30
+ (0, _classCallCheck2.default)(this, CI360Viewer);
25
31
  this.container = container;
26
- this.movementStart = { x: 0, y: 0 };
32
+ this.movementStart = {
33
+ x: 0,
34
+ y: 0
35
+ };
27
36
  this.isStartSpin = false;
28
37
  this.movingDirection = _ci2.ORIENTATIONS.CENTER;
29
38
  this.isClicked = false;
@@ -32,151 +41,234 @@ var CI360Viewer = function () {
32
41
  this.imagesLoaded = false;
33
42
  this.reversed = false;
34
43
  this.fullscreenView = !!fullscreen;
35
- this.ratio = ratio;
36
44
  this.imagesX = [];
37
45
  this.imagesY = [];
38
- this.resizedImagesX = [];
39
- this.resizedImagesY = [];
40
46
  this.originalImagesX = [];
41
47
  this.originalImagesY = [];
48
+ this.resizedImagesX = [];
49
+ this.resizedImagesY = [];
42
50
  this.devicePixelRatio = Math.round(window.devicePixelRatio || 1);
43
51
  this.isMobile = !!('ontouchstart' in window || navigator.msMaxTouchPoints);
44
52
  this.id = container.id;
45
53
  this.init(container);
46
- this.clickedToZoom = false;
47
54
  this.isMagnifyOpen = false;
48
55
  this.isDragged = false;
49
56
  this.startPointerZoom = false;
50
57
  this.zoomIntensity = 0;
51
58
  this.mouseTracked = false;
52
- this.intialPositions = { x: 0, y: 0 };
53
- this.pointerCurrentPosition = { x: 0, y: 0 };
54
- this.startPinchZoom = false;
55
- this.prevDistanceBetweenFingers = 0;
59
+ this.intialPositions = {
60
+ x: 0,
61
+ y: 0
62
+ };
63
+ this.pointerCurrentPosition = {
64
+ x: 0,
65
+ y: 0
66
+ };
67
+ this.isStartedLoadOriginalImages = false;
56
68
  }
57
69
 
58
- _createClass(CI360Viewer, [{
59
- key: 'mouseDown',
70
+ (0, _createClass2.default)(CI360Viewer, [{
71
+ key: "mouseDown",
60
72
  value: function mouseDown(event) {
73
+ if (!this.imagesLoaded) return;
61
74
  event.preventDefault();
62
-
63
75
  var pageX = event.pageX,
64
76
  pageY = event.pageY;
65
-
66
-
67
- if (!this.imagesLoaded) return;
68
-
69
77
  this.hideInitialIcons();
70
78
 
71
79
  if (this.autoplay || this.loopTimeoutId) {
72
80
  this.stop();
73
81
  this.autoplay = false;
82
+ this.isZoomReady = true;
74
83
  }
75
84
 
76
- this.intialPositions = { x: pageX, y: pageY };
77
- this.movementStart = { x: pageX, y: pageY };
85
+ this.intialPositions = {
86
+ x: pageX,
87
+ y: pageY
88
+ };
89
+ this.movementStart = {
90
+ x: pageX,
91
+ y: pageY
92
+ };
78
93
  this.isClicked = true;
79
94
  this.isDragged = false;
80
95
  }
81
96
  }, {
82
- key: 'mouseUp',
97
+ key: "mouseUp",
83
98
  value: function mouseUp() {
99
+ var _this = this;
100
+
84
101
  if (!this.imagesLoaded || !this.isClicked) return;
85
- this.movementStart = { x: 0, y: 0 };
102
+ this.movementStart = {
103
+ x: 0,
104
+ y: 0
105
+ };
86
106
  this.isStartSpin = false;
87
107
  this.isClicked = false;
88
108
 
89
- if (!this.clickedToZoom) {
90
- this.container.style.cursor = 'grab';
109
+ if (this.bottomCircle && !this.mouseTracked) {
110
+ this.show360ViewCircleIcon();
111
+ }
112
+
113
+ if (this.pointerZoom && !this.fullscreenView) {
114
+ setTimeout(function () {
115
+ _this.isZoomReady = true;
116
+ }, 50);
117
+
118
+ if (this.mouseTracked) {
119
+ this.container.style.cursor = 'zoom-out';
120
+ } else {
121
+ this.container.style.cursor = 'zoom-in';
122
+ }
91
123
  } else {
92
- this.container.style.cursor = 'nesw-resize';
124
+ this.container.style.cursor = 'grab';
93
125
  }
126
+ }
127
+ }, {
128
+ key: "mouseClick",
129
+ value: function mouseClick(event) {
130
+ if (!this.pointerZoom || this.fullscreenView) return;
131
+ this.setCursorPosition(event);
132
+ this.hideInitialIcons();
94
133
 
95
- if (this.bottomCircle && !this.zoomIntensity) {
96
- this.show360ViewCircleIcon();
134
+ if (!this.isStartedLoadOriginalImages && !this.isDragged && this.isZoomReady) {
135
+ this.prepareOriginalImages(event);
136
+ }
137
+
138
+ if (this.isAllOriginalImagesLoaded && !this.isDragged && this.isZoomReady) {
139
+ this.togglePointerZoom(event);
97
140
  }
141
+
142
+ ;
98
143
  }
99
144
  }, {
100
- key: 'mouseMove',
145
+ key: "mouseMove",
101
146
  value: function mouseMove(event) {
102
147
  if (!this.imagesLoaded) return;
103
-
104
148
  var pageX = event.pageX,
105
149
  pageY = event.pageY;
106
150
 
107
-
108
151
  if (this.mouseTracked) {
109
152
  this.setCursorPosition(event);
153
+
154
+ if (!this.isClicked) {
155
+ this.update();
156
+ }
110
157
  }
111
158
 
112
159
  if (this.isClicked) {
113
- var nextPositions = { x: pageX, y: pageY };
114
-
160
+ var nextPositions = {
161
+ x: pageX,
162
+ y: pageY
163
+ };
115
164
  this.container.style.cursor = 'grabbing';
116
-
117
- this.updateMovingDirection(this.intialPositions, nextPositions);
165
+ this.isDragged = true;
166
+ this.movingDirection = (0, _jsCloudimage360ViewUtils.getMovingDirection)(this.isStartSpin, this.allowSpinY, this.intialPositions, nextPositions, this.movingDirection);
118
167
  this.onMoveHandler(event);
168
+ }
169
+ }
170
+ }, {
171
+ key: "mouseLeave",
172
+ value: function mouseLeave() {
173
+ if (!this.imagesLoaded) return;
119
174
 
120
- this.isDragged = true;
121
- } else if (this.zoomIntensity) {
122
- this.update();
175
+ if (this.pointerZoom && this.mouseTracked) {
176
+ this.togglePointerZoom();
123
177
  }
124
178
  }
125
179
  }, {
126
- key: 'updateMovingDirection',
127
- value: function updateMovingDirection(prevPosition, nextPositions) {
128
- if (this.isStartSpin) return;
180
+ key: "togglePointerZoom",
181
+ value: function togglePointerZoom() {
182
+ var _this2 = this;
129
183
 
130
- var differenceInPositionX = Math.abs(prevPosition.x - nextPositions.x);
131
- var differenceInPositionY = Math.abs(prevPosition.y - nextPositions.y);
132
- var sensitivity = 10;
184
+ if (this.autoplay || this.loopTimeoutId) {
185
+ this.stop();
186
+ this.autoplay = false;
187
+ }
133
188
 
134
- if (differenceInPositionX > sensitivity) this.movingDirection = _ci2.ORIENTATIONS.X;
189
+ if (this.mouseTracked) {
190
+ var zoomSteps = (0, _jsCloudimage360ViewUtils.generateZoomOutSteps)(this.pointerZoom);
191
+ this.container.style.cursor = 'zoom-in';
192
+ zoomSteps.forEach(function (step, index) {
193
+ setTimeout(function () {
194
+ _this2.zoomIntensity = step;
135
195
 
136
- if (differenceInPositionY > sensitivity && this.allowSpinY) this.movingDirection = _ci2.ORIENTATIONS.Y;
137
- }
138
- }, {
139
- key: 'mouseClick',
140
- value: function mouseClick(event) {
141
- if (!this.isDragged && this.clickedToZoom) {
142
- this.resetZoom();
143
- } else if (!this.isDragged) {
144
- this.clickedToZoom = true;
145
- this.container.style.cursor = 'nesw-resize';
196
+ _this2.update();
197
+
198
+ var isReachedIntialScale = index === zoomSteps.length - 1;
199
+
200
+ if (isReachedIntialScale) {
201
+ _this2.mouseTracked = false;
202
+
203
+ _this2.update();
204
+ }
205
+
206
+ ;
207
+ }, (_this2.pointerZoom - step) * 200);
208
+ });
209
+ } else {
210
+ if (this.bottomCircle) this.hide360ViewCircleIcon();
211
+
212
+ var _zoomSteps = (0, _jsCloudimage360ViewUtils.generateZoomInSteps)(this.pointerZoom);
213
+
214
+ _zoomSteps.forEach(function (step) {
215
+ setTimeout(function () {
216
+ _this2.zoomIntensity = step;
217
+
218
+ _this2.update();
219
+ }, step * 200);
220
+ });
221
+
222
+ this.mouseTracked = true;
223
+ this.container.style.cursor = 'zoom-out';
146
224
  }
147
225
  }
148
226
  }, {
149
- key: 'mouseScroll',
150
- value: function mouseScroll(event) {
151
- if (this.disablePointerZoom || this.isMagnifyOpen) return;
152
-
153
- var isClickedToZoom = this.toStartPointerZoom === _ci2.TO_START_POINTER_ZOOM.CLICK_TO_START && this.clickedToZoom;
154
- var isScrolledToZoom = this.toStartPointerZoom === _ci2.TO_START_POINTER_ZOOM.SCROLL_TO_START;
227
+ key: "onOriginalImageLoad",
228
+ value: function onOriginalImageLoad(orientation, event, image, index) {
229
+ if (orientation === _ci2.ORIENTATIONS.Y) {
230
+ this.originalImagesY[index] = image;
231
+ } else {
232
+ this.originalImagesX[index] = image;
233
+ }
155
234
 
156
- if (isClickedToZoom || isScrolledToZoom) {
157
- this.container.style.cursor = 'nesw-resize';
235
+ var loadedOriginalXImages = this.originalImagesX.filter(function (image) {
236
+ return !!image;
237
+ });
238
+ var loadedOriginalYImages = this.originalImagesY.filter(function (image) {
239
+ return !!image;
240
+ });
241
+ var totalAmount = this.amountX + this.amountY;
242
+ var totalLoadedImages = loadedOriginalXImages.length + loadedOriginalYImages.length;
243
+ var isAllImagesLoaded = loadedOriginalXImages.length + loadedOriginalYImages.length === this.amountX + this.amountY;
244
+ var percentage = Math.round(totalLoadedImages / totalAmount * 100);
245
+ this.updatePercentageInLoader(percentage);
158
246
 
159
- this.initMouseScrollZoom(event);
247
+ if (isAllImagesLoaded) {
248
+ this.removeLoader();
249
+ this.togglePointerZoom(event);
250
+ this.mouseTracked = true;
251
+ this.isAllOriginalImagesLoaded = true;
160
252
  }
161
253
  }
162
254
  }, {
163
- key: 'closeZoomHandler',
164
- value: function closeZoomHandler() {
165
- this.container.style.cursor = 'grab';
166
- this.clickedToZoom = false;
167
- this.resetZoom();
255
+ key: "prepareOriginalImages",
256
+ value: function prepareOriginalImages(event) {
257
+ var srcX = (0, _jsCloudimage360ViewUtils.generateImagesPath)(this.srcXConfig);
258
+ this.isStartedLoadOriginalImages = true;
259
+ this.loader = (0, _jsCloudimage360ViewUtils.createLoader)(this.innerBox);
260
+ this.container.style.cursor = 'wait';
261
+ (0, _jsCloudimage360ViewUtils.preloadOriginalImages)(this.srcXConfig, srcX, this.onOriginalImageLoad.bind(this, _ci2.ORIENTATIONS.X, event));
262
+
263
+ if (this.allowSpinY) {
264
+ var srcY = (0, _jsCloudimage360ViewUtils.generateImagesPath)(this.srcYConfig);
265
+ (0, _jsCloudimage360ViewUtils.preloadOriginalImages)(this.srcXConfig, srcY, this.onOriginalImageLoad.bind(this, _ci2.ORIENTATIONS.Y, event));
266
+ }
168
267
  }
169
268
  }, {
170
- key: 'touchStart',
269
+ key: "touchStart",
171
270
  value: function touchStart(event) {
172
271
  if (!this.imagesLoaded) return;
173
-
174
- var isPinchZoom = !this.disablePinchZoom && (0, _ci.isTwoFingers)(event) && !this.isMagnifyOpen;
175
-
176
- if (isPinchZoom) {
177
- this.initAndSetPinchZoom(event);
178
- };
179
-
180
272
  this.hideInitialIcons();
181
273
 
182
274
  if (this.autoplay || this.loopTimeoutId) {
@@ -184,39 +276,41 @@ var CI360Viewer = function () {
184
276
  this.autoplay = false;
185
277
  }
186
278
 
187
- this.intialPositions = { x: event.touches[0].clientX, y: event.touches[0].clientY };
188
- this.movementStart = { x: event.touches[0].clientX, y: event.touches[0].clientY };
279
+ this.intialPositions = {
280
+ x: event.touches[0].clientX,
281
+ y: event.touches[0].clientY
282
+ };
283
+ this.movementStart = {
284
+ x: event.touches[0].clientX,
285
+ y: event.touches[0].clientY
286
+ };
189
287
  this.isClicked = true;
190
288
  }
191
289
  }, {
192
- key: 'touchEnd',
290
+ key: "touchEnd",
193
291
  value: function touchEnd() {
194
292
  if (!this.imagesLoaded) return;
195
-
196
- if (this.zoomIntensity) this.resetZoom();
197
-
198
- this.movementStart = { x: 0, y: 0 };
293
+ if (this.bottomCircle) this.show360ViewCircleIcon();
294
+ this.movementStart = {
295
+ x: 0,
296
+ y: 0
297
+ };
199
298
  this.isStartSpin = false;
200
299
  this.isClicked = false;
201
-
202
- if (this.bottomCircle) this.show360ViewCircleIcon();
203
300
  }
204
301
  }, {
205
- key: 'touchMove',
302
+ key: "touchMove",
206
303
  value: function touchMove(event) {
207
304
  if (!this.isClicked || !this.imagesLoaded) return;
208
-
209
- if (!this.disablePinchZoom && (0, _ci.isTwoFingers)(event)) {
210
- this.fingersPinchZoom(event);
211
- } else {
212
- var nextPositions = { x: event.touches[0].clientX, y: event.touches[0].clientY };
213
-
214
- this.updateMovingDirection(this.intialPositions, nextPositions);
215
- this.onMoveHandler(event);
216
- }
305
+ var nextPositions = {
306
+ x: event.touches[0].clientX,
307
+ y: event.touches[0].clientY
308
+ };
309
+ this.movingDirection = (0, _jsCloudimage360ViewUtils.getMovingDirection)(this.isStartSpin, this.allowSpinY, this.intialPositions, nextPositions);
310
+ this.onMoveHandler(event);
217
311
  }
218
312
  }, {
219
- key: 'keyDownGeneral',
313
+ key: "keyDownGeneral",
220
314
  value: function keyDownGeneral(event) {
221
315
  if (!this.imagesLoaded) return;
222
316
 
@@ -226,13 +320,13 @@ var CI360Viewer = function () {
226
320
 
227
321
  if (event.keyCode === 27) {
228
322
  //ESC
229
- if (this.clickedToZoom) {
230
- this.closeZoomHandler();
323
+ if (this.mouseTracked) {
324
+ this.togglePointerZoom();
231
325
  }
232
326
  }
233
327
  }
234
328
  }, {
235
- key: 'hideInitialIcons',
329
+ key: "hideInitialIcons",
236
330
  value: function hideInitialIcons() {
237
331
  if (this.glass) {
238
332
  this.closeMagnifier();
@@ -243,17 +337,7 @@ var CI360Viewer = function () {
243
337
  }
244
338
  }
245
339
  }, {
246
- key: 'initMouseScrollZoom',
247
- value: function initMouseScrollZoom(event) {
248
- if (this.bottomCircle) this.hide360ViewCircleIcon();
249
-
250
- this.hideInitialIcons();
251
- this.mouseTracked = true;
252
- this.setCursorPosition(event);
253
- this.mouseScrollZoom(event);
254
- }
255
- }, {
256
- key: 'setCursorPosition',
340
+ key: "setCursorPosition",
257
341
  value: function setCursorPosition(event) {
258
342
  this.mousePositions = {
259
343
  x: event.clientX,
@@ -261,155 +345,54 @@ var CI360Viewer = function () {
261
345
  };
262
346
  }
263
347
  }, {
264
- key: 'getCursorPositionInCanvas',
348
+ key: "getCursorPositionInCanvas",
265
349
  value: function getCursorPositionInCanvas() {
266
350
  var canvasRect = this.canvas.getBoundingClientRect();
267
-
268
351
  this.pointerCurrentPosition = {
269
352
  x: this.mousePositions.x - canvasRect.left,
270
353
  y: this.mousePositions.y - canvasRect.top
271
354
  };
272
-
273
355
  return this.pointerCurrentPosition;
274
356
  }
275
357
  }, {
276
- key: 'mouseScrollZoom',
277
- value: function mouseScrollZoom(event) {
278
- event.preventDefault();
279
-
280
- if (this.autoplay || this.loopTimeoutId) {
281
- this.stop();
282
- this.autoplay = false;
283
- }
284
-
285
- var zoomFactor = (0, _ci.normalizeZoomFactor)(event, this.pointerZoomFactor);
286
- var maxIntensity = (0, _ci.getMaxZoomIntensity)(this.canvas.width, this.maxScale);
287
- this.startPointerZoom = true;
288
- this.zoomIntensity += event.deltaY * zoomFactor;
289
- this.zoomIntensity = Math.min(Math.max(0, this.zoomIntensity), maxIntensity);
290
-
291
- if (this.zoomIntensity) {
292
- if (this.resetZoomIcon) this.showResetZoomIcon();
293
- } else {
294
- if (this.resetZoomIcon) this.hideResetZoomIcon();
295
-
296
- if (this.bottomCircle) this.show360ViewCircleIcon();
358
+ key: "keyDown",
359
+ value: function keyDown(event) {
360
+ if (!this.imagesLoaded) return;
297
361
 
298
- this.startPointerZoom = false;
299
- this.mouseTracked = false;
362
+ if (this.glass) {
363
+ this.closeMagnifier();
300
364
  }
301
365
 
302
- this.update();
303
- }
304
- }, {
305
- key: 'initAndSetPinchZoom',
306
- value: function initAndSetPinchZoom(event) {
307
- if (this.bottomCircle) this.hide360ViewCircleIcon();
308
-
309
- var _getFingersPosition = this.getFingersPosition(event),
310
- _getFingersPosition2 = _slicedToArray(_getFingersPosition, 2),
311
- fingerOnePosition = _getFingersPosition2[0],
312
- fingerTwoPosition = _getFingersPosition2[1];
313
-
314
- this.prevDistanceBetweenFingers = this.getDistanceBetweenFingers(fingerOnePosition, fingerTwoPosition);
315
- }
316
- }, {
317
- key: 'getDistanceBetweenFingers',
318
- value: function getDistanceBetweenFingers(fingerOne, fingerTwo) {
319
- var xPosition = fingerTwo.x - fingerOne.x;
320
- var yPosition = fingerTwo.y - fingerOne.y;
321
-
322
- return Math.sqrt(Math.pow(xPosition, 2) + Math.pow(yPosition, 2));
323
- }
324
- }, {
325
- key: 'updateAveragePositionBetweenFingers',
326
- value: function updateAveragePositionBetweenFingers(fingerOne, fingerTwo) {
327
- var containerRect = this.canvas.getBoundingClientRect();
328
- var offSetX = containerRect.left;
329
- var offSetY = containerRect.top;
330
-
331
- this.pointerCurrentPosition.x = (fingerOne.x + fingerTwo.x) / 2 - offSetX;
332
-
333
- this.pointerCurrentPosition.y = (fingerOne.y + fingerTwo.y) / 2 - offSetY;
334
- }
335
- }, {
336
- key: 'getFingersPosition',
337
- value: function getFingersPosition(event) {
338
- var p1 = event.targetTouches[0];
339
- var p2 = event.targetTouches[1];
340
-
341
- var fingerOnePosition = { x: p1.clientX, y: p1.clientY };
342
- var fingerTwoPosition = { x: p2.clientX, y: p2.clientY };
343
-
344
- return [fingerOnePosition, fingerTwoPosition];
345
- }
346
- }, {
347
- key: 'fingersPinchZoom',
348
- value: function fingersPinchZoom(event) {
349
- var _getFingersPosition3 = this.getFingersPosition(event),
350
- _getFingersPosition4 = _slicedToArray(_getFingersPosition3, 2),
351
- fingerOnePosition = _getFingersPosition4[0],
352
- fingerTwoPosition = _getFingersPosition4[1];
353
-
354
- var currentDistanceBetweenFingers = this.getDistanceBetweenFingers(fingerOnePosition, fingerTwoPosition);
355
- var zoomFactor = this.pinchZoomFactor * 30;
356
-
357
- var zoomSensitivity = 1.5;
358
- var isZoomIn = currentDistanceBetweenFingers > this.prevDistanceBetweenFingers + zoomSensitivity;
359
- var isZoomOut = currentDistanceBetweenFingers + zoomSensitivity < this.prevDistanceBetweenFingers;
360
- var maxIntensity = (0, _ci.getMaxZoomIntensity)(this.canvas.width, this.maxScale);
361
-
362
- this.startPinchZoom = true;
363
-
364
- this.updateAveragePositionBetweenFingers(fingerOnePosition, fingerTwoPosition);
365
-
366
- if (isZoomIn && this.zoomIntensity <= maxIntensity) {
367
- this.zoomIntensity += zoomFactor;
368
- } else if (isZoomOut && this.zoomIntensity >= zoomFactor) {
369
- this.zoomIntensity -= zoomFactor;
366
+ if (event.keyCode === 37) {
367
+ // left
368
+ this.keysReverse ? this.left() : this.right();
369
+ this.onSpin();
370
370
  }
371
371
 
372
- this.update();
373
- this.prevDistanceBetweenFingers = currentDistanceBetweenFingers;
374
- }
375
- }, {
376
- key: 'resetZoom',
377
- value: function resetZoom() {
378
- this.startPointerZoom = false;
379
- this.startPinchZoom = false;
380
- this.mouseTracked = false;
381
- this.clickedToZoom = false;
382
-
383
- this.container.style.cursor = 'grab';
384
-
385
- if (this.resetZoomIcon) this.hideResetZoomIcon();
386
-
387
- if (this.zoomIntensity) {
388
- this.zoomIntensity = 0;
389
- this.update();
372
+ if (event.keyCode === 39) {
373
+ // right
374
+ this.keysReverse ? this.right() : this.left();
375
+ this.onSpin();
390
376
  }
391
- }
392
- }, {
393
- key: 'keyDown',
394
- value: function keyDown(event) {
395
- if (!this.imagesLoaded) return;
396
377
 
397
- if (this.glass) {
398
- this.closeMagnifier();
399
- }
378
+ if (this.allowSpinY) {
379
+ event.preventDefault();
400
380
 
401
- if ([37, 39].indexOf(event.keyCode) !== -1) {
402
- if (37 === event.keyCode) {
403
- if (this.reversed) this.left();else this.right();
404
- } else if (39 === event.keyCode) {
405
- if (this.reversed) this.right();else this.left();
381
+ if (event.keyCode === 38) {
382
+ // up
383
+ this.keysReverse ? this.top() : this.bottom();
384
+ this.onSpin();
406
385
  }
407
386
 
408
- this.onSpin();
387
+ if (event.keyCode === 40) {
388
+ // down
389
+ this.keysReverse ? this.bottom() : this.top();
390
+ this.onSpin();
391
+ }
409
392
  }
410
393
  }
411
394
  }, {
412
- key: 'onSpin',
395
+ key: "onSpin",
413
396
  value: function onSpin() {
414
397
  if (this.bottomCircle) {
415
398
  this.hide360ViewCircleIcon();
@@ -425,7 +408,7 @@ var CI360Viewer = function () {
425
408
  }
426
409
  }
427
410
  }, {
428
- key: 'keyUp',
411
+ key: "keyUp",
429
412
  value: function keyUp(event) {
430
413
  if (!this.imagesLoaded) return;
431
414
 
@@ -434,87 +417,12 @@ var CI360Viewer = function () {
434
417
  }
435
418
  }
436
419
  }, {
437
- key: 'onFinishSpin',
420
+ key: "onFinishSpin",
438
421
  value: function onFinishSpin() {
439
422
  if (this.bottomCircle) this.show360ViewCircleIcon();
440
423
  }
441
424
  }, {
442
- key: 'onMoveHandler',
443
- value: function onMoveHandler(event) {
444
- var currentPositionX = this.isMobile ? event.touches[0].clientX : event.pageX;
445
- var currentPositionY = this.isMobile ? event.touches[0].clientY : event.pageY;
446
-
447
- var isMoveRight = currentPositionX - this.movementStart.x >= this.speedFactor;
448
- var isMoveLeft = this.movementStart.x - currentPositionX >= this.speedFactor;
449
- var isMoveTop = this.movementStart.y - currentPositionY >= this.speedFactor;
450
- var isMoveBottom = currentPositionY - this.movementStart.y >= this.speedFactor;
451
-
452
- if (this.bottomCircle) this.hide360ViewCircleIcon();
453
-
454
- if (isMoveRight && this.movingDirection === _ci2.ORIENTATIONS.X) {
455
- this.moveRight(currentPositionX);
456
-
457
- this.isStartSpin = true;
458
- } else if (isMoveLeft && this.movingDirection === _ci2.ORIENTATIONS.X) {
459
- this.moveLeft(currentPositionX);
460
-
461
- this.isStartSpin = true;
462
- } else if (isMoveTop && this.movingDirection === _ci2.ORIENTATIONS.Y) {
463
- this.moveTop(currentPositionY);
464
-
465
- this.isStartSpin = true;
466
- } else if (isMoveBottom && this.movingDirection === _ci2.ORIENTATIONS.Y) {
467
- this.moveBottom(currentPositionY);
468
-
469
- this.isStartSpin = true;
470
- }
471
- }
472
- }, {
473
- key: 'moveRight',
474
- value: function moveRight(currentPositionX) {
475
- var itemsSkippedRight = Math.floor((currentPositionX - this.movementStart.x) / this.speedFactor) || 1;
476
-
477
- this.spinReverse ? this.moveActiveIndexDown(itemsSkippedRight) : this.moveActiveIndexUp(itemsSkippedRight);
478
-
479
- this.movementStart.x = currentPositionX;
480
- this.activeImageY = 1;
481
- this.update();
482
- }
483
- }, {
484
- key: 'moveLeft',
485
- value: function moveLeft(currentPositionX) {
486
- var itemsSkippedLeft = Math.floor((this.movementStart.x - currentPositionX) / this.speedFactor) || 1;
487
-
488
- this.spinReverse ? this.moveActiveIndexUp(itemsSkippedLeft) : this.moveActiveIndexDown(itemsSkippedLeft);
489
-
490
- this.activeImageY = 1;
491
- this.movementStart.x = currentPositionX;
492
- this.update();
493
- }
494
- }, {
495
- key: 'moveTop',
496
- value: function moveTop(currentPositionY) {
497
- var itemsSkippedTop = Math.floor((this.movementStart.y - currentPositionY) / this.speedFactor) || 1;
498
-
499
- this.spinReverse ? this.moveActiveYIndexUp(itemsSkippedTop) : this.moveActiveYIndexDown(itemsSkippedTop);
500
-
501
- this.activeImageX = 1;
502
- this.movementStart.y = currentPositionY;
503
- this.update();
504
- }
505
- }, {
506
- key: 'moveBottom',
507
- value: function moveBottom(currentPositionY) {
508
- var itemsSkippedBottom = Math.floor((currentPositionY - this.movementStart.y) / this.speedFactor) || 1;
509
-
510
- this.spinReverse ? this.moveActiveYIndexDown(itemsSkippedBottom) : this.moveActiveYIndexUp(itemsSkippedBottom);
511
-
512
- this.activeImageX = 1;
513
- this.movementStart.y = currentPositionY;
514
- this.update();
515
- }
516
- }, {
517
- key: 'moveActiveIndexUp',
425
+ key: "moveActiveIndexUp",
518
426
  value: function moveActiveIndexUp(itemsSkipped) {
519
427
  var isReverse = this.controlReverse ? !this.spinReverse : this.spinReverse;
520
428
 
@@ -524,24 +432,21 @@ var CI360Viewer = function () {
524
432
  if (isReachedTheEdge) {
525
433
  this.activeImageX = this.amountX;
526
434
 
527
- if (isReverse ? this.prevElem : this.rightElem) {
528
- (0, _ci.addClass)(isReverse ? this.leftElem : this.leftElem, 'not-active');
435
+ if (isReverse ? this.leftElem : this.rightElem) {
436
+ (0, _jsCloudimage360ViewUtils.addClass)(isReverse ? this.leftElem : this.rightElem, 'not-active');
529
437
  }
530
438
  } else {
531
439
  this.activeImageX += itemsSkipped;
532
-
533
- if (this.rightElem) (0, _ci.removeClass)(this.rightElem, 'not-active');
534
-
535
- if (this.leftElem) (0, _ci.removeClass)(this.leftElem, 'not-active');
440
+ if (this.rightElem) (0, _jsCloudimage360ViewUtils.removeClass)(this.rightElem, 'not-active');
441
+ if (this.leftElem) (0, _jsCloudimage360ViewUtils.removeClass)(this.leftElem, 'not-active');
536
442
  }
537
443
  } else {
538
444
  this.activeImageX = (this.activeImageX + itemsSkipped) % this.amountX || this.amountX;
539
-
540
445
  if (this.activeImageX === this.amountX && this.allowSpinY) this.spinY = true;
541
446
  }
542
447
  }
543
448
  }, {
544
- key: 'moveActiveIndexDown',
449
+ key: "moveActiveIndexDown",
545
450
  value: function moveActiveIndexDown(itemsSkipped) {
546
451
  var isReverse = this.controlReverse ? !this.spinReverse : this.spinReverse;
547
452
 
@@ -552,14 +457,12 @@ var CI360Viewer = function () {
552
457
  this.activeImageX = 1;
553
458
 
554
459
  if (isReverse ? this.rightElem : this.leftElem) {
555
- (0, _ci.addClass)(isReverse ? this.rightElem : this.leftElem, 'not-active');
460
+ (0, _jsCloudimage360ViewUtils.addClass)(isReverse ? this.rightElem : this.leftElem, 'not-active');
556
461
  }
557
462
  } else {
558
463
  this.activeImageX -= itemsSkipped;
559
-
560
- if (this.leftElem) (0, _ci.removeClass)(this.leftElem, 'not-active');
561
-
562
- if (this.rightElem) (0, _ci.removeClass)(this.rightElem, 'not-active');
464
+ if (this.leftElem) (0, _jsCloudimage360ViewUtils.removeClass)(this.leftElem, 'not-active');
465
+ if (this.rightElem) (0, _jsCloudimage360ViewUtils.removeClass)(this.rightElem, 'not-active');
563
466
  }
564
467
  } else {
565
468
  if (this.activeImageX - itemsSkipped < 1) {
@@ -571,7 +474,7 @@ var CI360Viewer = function () {
571
474
  }
572
475
  }
573
476
  }, {
574
- key: 'moveActiveYIndexUp',
477
+ key: "moveActiveYIndexUp",
575
478
  value: function moveActiveYIndexUp(itemsSkipped) {
576
479
  var isReverse = this.controlReverse ? !this.spinReverse : this.spinReverse;
577
480
 
@@ -582,23 +485,20 @@ var CI360Viewer = function () {
582
485
  this.activeImageY = this.amountY;
583
486
 
584
487
  if (isReverse ? this.bottomElem : this.topElem) {
585
- (0, _ci.addClass)(isReverse ? this.bottomElem : this.topElem, 'not-active');
488
+ (0, _jsCloudimage360ViewUtils.addClass)(isReverse ? this.bottomElem : this.topElem, 'not-active');
586
489
  }
587
490
  } else {
588
491
  this.activeImageY += itemsSkipped;
589
-
590
- if (this.topElem) (0, _ci.removeClass)(this.topElem, 'not-active');
591
-
592
- if (this.bottomElem) (0, _ci.removeClass)(this.bottomElem, 'not-active');
492
+ if (this.topElem) (0, _jsCloudimage360ViewUtils.removeClass)(this.topElem, 'not-active');
493
+ if (this.bottomElem) (0, _jsCloudimage360ViewUtils.removeClass)(this.bottomElem, 'not-active');
593
494
  }
594
495
  } else {
595
496
  this.activeImageY = (this.activeImageY + itemsSkipped) % this.amountY || this.amountY;
596
-
597
497
  if (this.activeImageY === this.amountY) this.spinY = false;
598
498
  }
599
499
  }
600
500
  }, {
601
- key: 'moveActiveYIndexDown',
501
+ key: "moveActiveYIndexDown",
602
502
  value: function moveActiveYIndexDown(itemsSkipped) {
603
503
  var isReverse = this.controlReverse ? !this.spinReverse : this.spinReverse;
604
504
 
@@ -609,13 +509,12 @@ var CI360Viewer = function () {
609
509
  this.activeImageY = 1;
610
510
 
611
511
  if (isReverse ? this.topElem : this.bottomElem) {
612
- (0, _ci.addClass)(isReverse ? this.topElem : this.bottomElem, 'not-active');
512
+ (0, _jsCloudimage360ViewUtils.addClass)(isReverse ? this.topElem : this.bottomElem, 'not-active');
613
513
  }
614
514
  } else {
615
515
  this.activeImageY -= itemsSkipped;
616
-
617
- if (this.bottomElem) (0, _ci.removeClass)(this.bottomElem, 'not-active');
618
- if (this.topElem) (0, _ci.removeClass)(this.topElem, 'not-active');
516
+ if (this.bottomElem) (0, _jsCloudimage360ViewUtils.removeClass)(this.bottomElem, 'not-active');
517
+ if (this.topElem) (0, _jsCloudimage360ViewUtils.removeClass)(this.topElem, 'not-active');
619
518
  }
620
519
  } else {
621
520
  if (this.activeImageY - itemsSkipped < 1) {
@@ -627,156 +526,188 @@ var CI360Viewer = function () {
627
526
  }
628
527
  }
629
528
  }, {
630
- key: 'loop',
631
- value: function loop(reversed) {
632
- switch (this.autoplayBehavior) {
633
- case _ci2.AUTOPLAY_BEHAVIOR.SPIN_Y:
634
- reversed ? this.bottom() : this.top();
635
- break;
636
-
637
- case _ci2.AUTOPLAY_BEHAVIOR.SPIN_XY:
638
- if (this.spinY) {
639
- reversed ? this.bottom() : this.top();
640
- } else {
641
- reversed ? this.left() : this.right();
642
- }
643
- break;
644
-
645
- case _ci2.AUTOPLAY_BEHAVIOR.SPIN_YX:
646
- if (this.spinY) {
647
- reversed ? this.bottom() : this.top();
648
- } else {
649
- reversed ? this.left() : this.right();
650
- }
651
- break;
652
-
653
- case _ci2.AUTOPLAY_BEHAVIOR.SPIN_X:
654
- default:
655
- reversed ? this.left() : this.right();
656
- }
657
- }
658
- }, {
659
- key: 'right',
660
- value: function right() {
661
- this.movingDirection = _ci2.ORIENTATIONS.X;
662
- this.activeImageY = this.reversed ? this.amountY : 1;
663
-
664
- this.moveActiveIndexUp(1);
529
+ key: "moveRight",
530
+ value: function moveRight(currentPositionX) {
531
+ var itemsSkippedRight = (0, _jsCloudimage360ViewUtils.getItemSkipped)(currentPositionX, this.movementStart.x, this.speedFactor);
532
+ this.spinReverse ? this.moveActiveIndexDown(itemsSkippedRight) : this.moveActiveIndexUp(itemsSkippedRight);
533
+ this.movementStart.x = currentPositionX;
534
+ this.activeImageY = 1;
665
535
  this.update();
666
536
  }
667
537
  }, {
668
- key: 'left',
538
+ key: "moveLeft",
539
+ value: function moveLeft(currentPositionX) {
540
+ var itemsSkippedLeft = (0, _jsCloudimage360ViewUtils.getItemSkipped)(this.movementStart.x, currentPositionX, this.speedFactor);
541
+ this.spinReverse ? this.moveActiveIndexUp(itemsSkippedLeft) : this.moveActiveIndexDown(itemsSkippedLeft);
542
+ this.activeImageY = 1;
543
+ this.movementStart.x = currentPositionX;
544
+ this.update();
545
+ }
546
+ }, {
547
+ key: "moveTop",
548
+ value: function moveTop(currentPositionY) {
549
+ var itemsSkippedTop = (0, _jsCloudimage360ViewUtils.getItemSkipped)(this.movementStart.y, currentPositionY, this.speedFactor);
550
+ this.spinReverse ? this.moveActiveYIndexUp(itemsSkippedTop) : this.moveActiveYIndexDown(itemsSkippedTop);
551
+ this.activeImageX = 1;
552
+ this.movementStart.y = currentPositionY;
553
+ this.update();
554
+ }
555
+ }, {
556
+ key: "moveBottom",
557
+ value: function moveBottom(currentPositionY) {
558
+ var itemsSkippedBottom = (0, _jsCloudimage360ViewUtils.getItemSkipped)(currentPositionY, this.movementStart.y, this.speedFactor);
559
+ this.spinReverse ? this.moveActiveYIndexDown(itemsSkippedBottom) : this.moveActiveYIndexUp(itemsSkippedBottom);
560
+ this.activeImageX = 1;
561
+ this.movementStart.y = currentPositionY;
562
+ this.update();
563
+ }
564
+ }, {
565
+ key: "onMoveHandler",
566
+ value: function onMoveHandler(event) {
567
+ var currentPositionX = this.isMobile ? event.touches[0].clientX : event.pageX;
568
+ var currentPositionY = this.isMobile ? event.touches[0].clientY : event.pageY;
569
+ var isMoveRight = currentPositionX - this.movementStart.x >= this.speedFactor;
570
+ var isMoveLeft = this.movementStart.x - currentPositionX >= this.speedFactor;
571
+ var isMoveTop = this.movementStart.y - currentPositionY >= this.speedFactor;
572
+ var isMoveBottom = currentPositionY - this.movementStart.y >= this.speedFactor;
573
+ if (this.bottomCircle) this.hide360ViewCircleIcon();
574
+
575
+ if (isMoveRight && this.movingDirection === _ci2.ORIENTATIONS.X) {
576
+ this.moveRight(currentPositionX);
577
+ this.isStartSpin = true;
578
+ } else if (isMoveLeft && this.movingDirection === _ci2.ORIENTATIONS.X) {
579
+ this.moveLeft(currentPositionX);
580
+ this.isStartSpin = true;
581
+ } else if (isMoveTop && this.movingDirection === _ci2.ORIENTATIONS.Y) {
582
+ this.moveTop(currentPositionY);
583
+ this.isStartSpin = true;
584
+ } else if (isMoveBottom && this.movingDirection === _ci2.ORIENTATIONS.Y) {
585
+ this.moveBottom(currentPositionY);
586
+ this.isStartSpin = true;
587
+ }
588
+ }
589
+ }, {
590
+ key: "left",
669
591
  value: function left() {
670
592
  this.movingDirection = _ci2.ORIENTATIONS.X;
671
593
  this.activeImageY = this.reversed ? this.amountY : 1;
672
-
673
594
  this.moveActiveIndexDown(1);
674
595
  this.update();
675
596
  }
676
597
  }, {
677
- key: 'top',
598
+ key: "right",
599
+ value: function right() {
600
+ this.movingDirection = _ci2.ORIENTATIONS.X;
601
+ this.activeImageY = this.reversed ? this.amountY : 1;
602
+ this.moveActiveIndexUp(1);
603
+ this.update();
604
+ }
605
+ }, {
606
+ key: "top",
678
607
  value: function top() {
679
608
  this.movingDirection = _ci2.ORIENTATIONS.Y;
680
609
  this.activeImageX = this.reversed ? this.amountX : 1;
681
-
682
610
  this.moveActiveYIndexUp(1);
683
611
  this.update();
684
612
  }
685
613
  }, {
686
- key: 'bottom',
614
+ key: "bottom",
687
615
  value: function bottom() {
688
616
  this.movingDirection = _ci2.ORIENTATIONS.Y;
689
617
  this.activeImageX = this.reversed ? this.amountX : 1;
690
-
691
618
  this.moveActiveYIndexDown(1);
692
619
  this.update();
693
620
  }
694
621
  }, {
695
- key: 'onLoadResizedImages',
696
- value: function onLoadResizedImages(orientation, event) {
697
- this.incrementLoadedImages(orientation);
698
-
699
- var totalAmount = this.amountX + this.amountY;
700
- var totalLoadedImages = this.loadedImagesX + this.loadedImagesY;
701
-
702
- if (totalLoadedImages === totalAmount) {
703
- this.replaceImages(orientation);
704
- this.update();
705
- }
622
+ key: "loop",
623
+ value: function loop(reversed) {
624
+ var loopTriggers = {
625
+ left: this.left.bind(this),
626
+ right: this.right.bind(this),
627
+ top: this.top.bind(this),
628
+ bottom: this.bottom.bind(this)
629
+ };
630
+ (0, _jsCloudimage360ViewUtils.loop)(this.autoplayBehavior, this.spinY, reversed, loopTriggers);
706
631
  }
707
632
  }, {
708
- key: 'replaceImages',
709
- value: function replaceImages(orientation) {
710
- if (orientation === _ci2.ORIENTATIONS.Y) {
711
- this.imagesY = this.resizedImagesY;
712
- } else {
713
- this.imagesX = this.resizedImagesX;
633
+ key: "updateContainerSize",
634
+ value: function updateContainerSize(image) {
635
+ var parentEl = this.container.parentNode || {};
636
+ var imageAspectRatio = image.width / image.height;
637
+ var isProvidedHeightLessThanWidth = this.containerHeight < this.containerWidth;
638
+ var containerWidth = (0, _jsCloudimage360ViewUtils.getContainerResponsiveWidth)(parentEl, this.containerWidth);
639
+ var containerHeight = (0, _jsCloudimage360ViewUtils.getContainerResponsiveHeight)(this.container, containerWidth, this.containerHeight);
640
+
641
+ if (this.fullscreenView) {
642
+ this.container.width = window.innerWidth * this.devicePixelRatio;
643
+ this.container.style.width = window.innerWidth + 'px';
644
+ this.container.height = window.innerHeight * this.devicePixelRatio;
645
+ this.container.style.height = window.innerHeight + 'px';
646
+ this.container.style.maxWidth = 'unset';
647
+ return;
714
648
  }
715
- }
716
- }, {
717
- key: 'requestNewImages',
718
- value: function requestNewImages(src, amount, orientation) {
719
- var _this = this;
720
649
 
721
- if (orientation === _ci2.ORIENTATIONS.Y) {
722
- this.resizedImagesY = [];
723
- this.loadedImagesY = 0;
724
- } else {
725
- this.resizedImagesX = [];
726
- this.loadedImagesX = 0;
650
+ if (this.containerWidth && this.containerHeight) {
651
+ this.container.style.width = containerWidth + 'px';
652
+ this.container.style.height = containerHeight / imageAspectRatio + 'px';
653
+ return;
727
654
  }
728
655
 
729
- [].concat(_toConsumableArray(new Array(amount))).map(function (_item, index) {
730
- var nextZeroFilledIndex = (0, _ci.pad)(index + 1, _this.indexZeroBase);
731
- var resultSrc = src.replace('{index}', nextZeroFilledIndex);
656
+ if (!this.containerWidth && !this.containerHeight) {
657
+ this.container.style.height = containerHeight / imageAspectRatio + 'px';
658
+ return;
659
+ }
732
660
 
733
- _this.addUpdatedSizeImage(resultSrc, orientation, _this.lazyload, _this.lazySelector, index);
734
- });
661
+ if ((isProvidedHeightLessThanWidth || !this.containerWidth) && this.containerHeight) {
662
+ this.container.style.maxWidth = containerHeight * imageAspectRatio + 'px';
663
+ this.container.style.height = containerHeight + 'px';
664
+ } else {
665
+ this.container.style.maxWidth = containerWidth + 'px';
666
+ this.container.style.height = containerWidth / imageAspectRatio + 'px';
667
+ }
735
668
  }
736
669
  }, {
737
- key: 'addUpdatedSizeImage',
738
- value: function addUpdatedSizeImage(resultSrc, orientation, lazyload, lazySelector, index) {
739
- var image = new Image();
740
-
741
- if (lazyload && !this.fullscreenView) {
742
- image.setAttribute('data-src', resultSrc);
743
- image.className = image.className.length ? image.className + (' ' + lazySelector) : lazySelector;
744
-
745
- if (index === 0) {
746
- this.lazyloadInitImage = image;
747
- image.style.position = 'absolute';
748
- image.style.top = '0';
749
- image.style.left = '0';
750
- this.innerBox.appendChild(image);
751
- }
670
+ key: "onResizedImageLoad",
671
+ value: function onResizedImageLoad(orientation, image, index) {
672
+ if (orientation === _ci2.ORIENTATIONS.Y) {
673
+ this.resizedImagesY[index] = image;
752
674
  } else {
753
- image.src = resultSrc;
675
+ this.resizedImagesX[index] = image;
754
676
  }
755
677
 
756
- image.onload = this.onLoadResizedImages.bind(this, orientation);
757
- image.onerror = this.onLoadResizedImages.bind(this, orientation);
678
+ var loadedResizedXImages = this.resizedImagesX.filter(function (image) {
679
+ return !!image;
680
+ });
681
+ var loadedResizedYImages = this.resizedImagesY.filter(function (image) {
682
+ return !!image;
683
+ });
684
+ var isAllImagesLoaded = loadedResizedXImages.length + loadedResizedYImages.length === this.amountX + this.amountY;
758
685
 
759
- if (orientation === _ci2.ORIENTATIONS.Y) {
760
- this.resizedImagesY.push(image);
761
- } else {
762
- this.resizedImagesX.push(image);
686
+ if (isAllImagesLoaded) {
687
+ this.imagesX = this.resizedImagesX;
688
+ this.imagesY = this.resizedImagesY;
689
+ this.update();
763
690
  }
764
691
  }
765
692
  }, {
766
- key: 'requestResizedImages',
693
+ key: "requestResizedImages",
767
694
  value: function requestResizedImages() {
768
- var srcX = this.getSrc(this.responsive, this.container, this.folder, this.filenameX, this.ciParams);
769
-
770
- this.requestNewImages(srcX, this.amountX, _ci2.ORIENTATIONS.X);
695
+ var responsive = this.ciParams.ciToken;
696
+ var firstImage = this.imagesX[0];
697
+ this.updateContainerSize(firstImage);
698
+ this.update();
699
+ this.speedFactor = (0, _jsCloudimage360ViewUtils.getSpeedFactor)(this.dragSpeed, this.amountX, this.container.offsetWidth);
700
+ var srcX = (0, _jsCloudimage360ViewUtils.generateImagesPath)(this.srcXConfig);
701
+ if (!responsive || this.container.offsetWidth < firstImage.width * 1.5) return;
702
+ (0, _jsCloudimage360ViewUtils.preloadImages)(this.srcXConfig, srcX, this.onResizedImageLoad.bind(this, _ci2.ORIENTATIONS.X), true);
771
703
 
772
704
  if (this.allowSpinY) {
773
- var srcY = this.getSrc(this.responsive, this.container, this.folder, this.filenameY, this.ciParams);
774
-
775
- this.requestNewImages(srcY, this.amountY, _ci2.ORIENTATIONS.Y);
705
+ var srcY = (0, _jsCloudimage360ViewUtils.generateImagesPath)(this.srcYConfig);
706
+ (0, _jsCloudimage360ViewUtils.preloadImages)(this.srcYConfig, srcY, this.onResizedImageLoad.bind(this, _ci2.ORIENTATIONS.Y), true);
776
707
  }
777
708
  }
778
709
  }, {
779
- key: 'update',
710
+ key: "update",
780
711
  value: function update() {
781
712
  var image = this.imagesX[this.activeImageX - 1];
782
713
 
@@ -785,29 +716,22 @@ var CI360Viewer = function () {
785
716
  }
786
717
 
787
718
  var ctx = this.canvas.getContext("2d");
788
-
789
719
  ctx.scale(this.devicePixelRatio, this.devicePixelRatio);
720
+ this.canvas.width = this.container.offsetWidth * this.devicePixelRatio;
721
+ this.canvas.style.width = this.container.offsetWidth + 'px';
722
+ this.canvas.height = this.container.offsetHeight * this.devicePixelRatio;
723
+ this.canvas.style.height = this.container.offsetHeight + 'px';
790
724
 
791
725
  if (this.fullscreenView) {
792
- this.canvas.width = window.innerWidth * this.devicePixelRatio;
793
- this.canvas.style.width = window.innerWidth + 'px';
794
- this.canvas.height = window.innerHeight * this.devicePixelRatio;
795
- this.canvas.style.height = window.innerHeight + 'px';
796
-
797
- var _contain = (0, _ci.contain)(this.canvas.width, this.canvas.height, image.width, image.height),
798
- offsetX = _contain.offsetX,
799
- offsetY = _contain.offsetY,
726
+ var _contain = (0, _jsCloudimage360ViewUtils.contain)(this.canvas.width, this.canvas.height, image.width, image.height),
800
727
  width = _contain.width,
801
- height = _contain.height;
728
+ height = _contain.height,
729
+ offsetX = _contain.offsetX,
730
+ offsetY = _contain.offsetY;
802
731
 
803
732
  ctx.drawImage(image, offsetX, offsetY, width, height);
804
733
  } else {
805
- this.canvas.width = this.container.offsetWidth * this.devicePixelRatio;
806
- this.canvas.style.width = this.container.offsetWidth + 'px';
807
- this.canvas.height = this.container.offsetWidth * this.devicePixelRatio / image.width * image.height;
808
- this.canvas.style.height = this.container.offsetWidth / image.width * image.height + 'px';
809
-
810
- if (this.startPointerZoom || this.startPinchZoom) {
734
+ if (this.mouseTracked) {
811
735
  this.updateImageScale(ctx);
812
736
  } else {
813
737
  ctx.drawImage(image, 0, 0, this.canvas.width, this.canvas.height);
@@ -815,7 +739,7 @@ var CI360Viewer = function () {
815
739
  }
816
740
  }
817
741
  }, {
818
- key: 'updateImageScale',
742
+ key: "updateImageScale",
819
743
  value: function updateImageScale(ctx) {
820
744
  var image = this.originalImagesX[this.activeImageX - 1];
821
745
 
@@ -823,23 +747,17 @@ var CI360Viewer = function () {
823
747
  image = this.originalImagesY[this.activeImageY - 1];
824
748
  }
825
749
 
826
- var position = this.pointerCurrentPosition;
827
-
828
- if (this.startPointerZoom) position = this.getCursorPositionInCanvas();
829
-
830
- var imageWidth = this.canvas.width / this.devicePixelRatio;
831
- var imageHeight = this.canvas.height / this.devicePixelRatio;
832
-
833
- var width = this.canvas.width + this.zoomIntensity * (this.canvas.width / this.canvas.height);
834
- var height = this.canvas.height + this.zoomIntensity;
835
-
750
+ var position = this.getCursorPositionInCanvas();
751
+ var imageWidth = this.canvas.width;
752
+ var imageHeight = this.canvas.height;
753
+ var width = this.canvas.width * this.zoomIntensity;
754
+ var height = this.canvas.height * this.zoomIntensity;
836
755
  var pointX = 0 - position.x / imageWidth * (width - this.canvas.width);
837
756
  var pointY = 0 - position.y / imageHeight * (height - this.canvas.height);
838
-
839
757
  ctx.drawImage(image, pointX, pointY, width, height);
840
758
  }
841
759
  }, {
842
- key: 'updatePercentageInLoader',
760
+ key: "updatePercentageInLoader",
843
761
  value: function updatePercentageInLoader(percentage) {
844
762
  if (this.loader) {
845
763
  this.loader.style.width = percentage + '%';
@@ -850,51 +768,10 @@ var CI360Viewer = function () {
850
768
  }
851
769
  }
852
770
  }, {
853
- key: 'onAllImagesLoaded',
854
- value: function onAllImagesLoaded() {
855
- this.imagesLoaded = true;
856
-
857
- this.container.style.cursor = 'grab';
858
- if (this.disableDrag) this.container.style.cursor = 'default';
859
-
860
- this.removeLoader();
861
-
862
- if (!this.fullscreenView) {
863
- this.speedFactor = Math.floor(this.dragSpeed / 150 * 36 / this.amountX * 25 * this.container.offsetWidth / 1500) || 1;
864
- } else {
865
- var containerRatio = this.container.offsetHeight / this.container.offsetWidth;
866
- var imageOffsetWidth = this.container.offsetWidth;
867
-
868
- if (this.ratio > containerRatio) {
869
- imageOffsetWidth = this.container.offsetHeight / this.ratio;
870
- }
871
-
872
- this.speedFactor = Math.floor(this.dragSpeed / 150 * 36 / this.amountX * 25 * imageOffsetWidth / 1500) || 1;
873
- }
874
-
875
- if (this.imageOffset) {
876
- this.activeImageX = this.imageOffset;
877
- };
878
-
879
- if (this.autoplay) {
880
- this.play();
881
- }
882
-
883
- if (this.view360Icon) {
884
- this.view360Icon.innerText = '';
885
- (0, _ci.setView360Icon)(this.view360Icon, this.logoSrc);
886
- }
887
-
888
- this.initControls();
889
- }
890
- }, {
891
- key: 'onFirstImageLoaded',
892
- value: function onFirstImageLoaded(event) {
893
- var _this2 = this;
894
-
895
- if (!this.hide360Logo) {
896
- this.add360ViewIcon();
897
- }
771
+ key: "onFirstImageLoaded",
772
+ value: function onFirstImageLoaded(image) {
773
+ if (!this.hide360Logo && !this.lazyload) this.add360ViewIcon();
774
+ var ctx = this.canvas.getContext("2d");
898
775
 
899
776
  if (this.fullscreenView) {
900
777
  this.canvas.width = window.innerWidth * this.devicePixelRatio;
@@ -902,75 +779,35 @@ var CI360Viewer = function () {
902
779
  this.canvas.height = window.innerHeight * this.devicePixelRatio;
903
780
  this.canvas.style.height = window.innerHeight + 'px';
904
781
 
905
- var ctx = this.canvas.getContext("2d");
906
-
907
- var _contain2 = (0, _ci.contain)(this.canvas.width, this.canvas.height, event.target.width, event.target.height),
782
+ var _contain2 = (0, _jsCloudimage360ViewUtils.contain)(this.canvas.width, this.canvas.height, image.width, image.height),
908
783
  offsetX = _contain2.offsetX,
909
784
  offsetY = _contain2.offsetY,
910
785
  width = _contain2.width,
911
786
  height = _contain2.height;
912
787
 
913
- this.offset = { x: offsetX, y: offsetY };
914
-
915
- ctx.drawImage(event.target, offsetX, offsetY, width, height);
788
+ this.offset = {
789
+ x: offsetX,
790
+ y: offsetY
791
+ };
792
+ ctx.drawImage(image, offsetX, offsetY, width, height);
916
793
  } else {
917
- var _ctx = this.canvas.getContext("2d");
918
- var imagePreview = event.target;
919
-
920
- if (this.imageOffset) {
921
- imagePreview = this.imagesX[this.imageOffset];
922
- }
923
-
924
- if (this.container.offsetWidth === 0) {
925
- var modalRef = this.container.parentElement;
926
-
927
- this.canvas.width = parseInt(modalRef.style.width) * this.devicePixelRatio;
928
- this.canvas.style.width = modalRef.style.width;
929
-
930
- this.canvas.height = parseInt(modalRef.style.height) * this.devicePixelRatio / event.target.width * event.target.height;
931
- this.canvas.style.height = parseInt(modalRef.style.width) / event.target.width * event.target.height + 'px';
932
- }
933
-
934
- if (this.container.offsetWidth > 0) {
935
- this.canvas.width = this.container.offsetWidth * this.devicePixelRatio;
936
- this.canvas.style.width = this.container.offsetWidth + 'px';
937
-
938
- this.canvas.height = this.container.offsetWidth * this.devicePixelRatio / event.target.width * event.target.height;
939
- this.canvas.style.height = this.container.offsetWidth / event.target.width * event.target.height + 'px';
940
- }
941
-
942
- _ctx.drawImage(imagePreview, 0, 0, this.canvas.width, this.canvas.height);
943
- }
944
-
945
- if (this.lazyload && !this.fullscreenView) {
946
- this.imagesX.forEach(function (image, index) {
947
- if (index === 0) {
948
- _this2.innerBox.removeChild(_this2.lazyloadInitImage);
949
- return;
950
- }
951
-
952
- var dataSrc = image.getAttribute('data-src');
953
-
954
- if (dataSrc) {
955
- image.src = image.getAttribute('data-src');
956
- }
957
- });
958
- }
959
-
960
- if (this.ratio) {
961
- this.container.style.minHeight = 'auto';
794
+ this.canvas.width = this.container.offsetWidth * this.devicePixelRatio;
795
+ this.canvas.style.width = this.container.offsetWidth + 'px';
796
+ this.canvas.height = this.container.offsetHeight * this.devicePixelRatio;
797
+ this.canvas.style.height = this.container.offsetHeight + 'px';
798
+ ctx.drawImage(image, 0, 0, this.canvas.width, this.canvas.height);
962
799
  }
963
800
 
964
801
  if (this.fullscreenView) {
965
802
  this.addCloseFullscreenView();
966
803
  }
967
804
 
968
- if (this.magnifier && !this.fullscreenView || this.magnifyInFullscreen) {
805
+ if (this.magnifier) {
969
806
  this.addMagnifier();
970
807
  }
971
808
 
972
809
  if (this.boxShadow && !this.fullscreenView) {
973
- this.addBoxShadow();
810
+ (0, _jsCloudimage360ViewUtils.createBoxShadow)(this.boxShadow, this.innerBox);
974
811
  }
975
812
 
976
813
  if (this.bottomCircle && !this.fullscreenView) {
@@ -980,339 +817,98 @@ var CI360Viewer = function () {
980
817
  if (this.fullscreen && !this.fullscreenView) {
981
818
  this.addFullscreenIcon();
982
819
  }
983
-
984
- if (!this.isMobile && !this.fullscreenView && !this.disablePointerZoom) {
985
- this.addResetZoomIcon();
986
- }
987
820
  }
988
821
  }, {
989
- key: 'incrementLoadedImages',
990
- value: function incrementLoadedImages(orientation) {
991
- if (orientation === _ci2.ORIENTATIONS.Y) {
992
- this.loadedImagesY += 1;
822
+ key: "onAllImagesLoaded",
823
+ value: function onAllImagesLoaded() {
824
+ this.removeLoader();
825
+ this.imagesLoaded = true;
826
+
827
+ if (this.autoplay && this.pointerZoom) {
828
+ this.container.style.cursor = 'zoom-in';
993
829
  } else {
994
- this.loadedImagesX += 1;
830
+ this.container.style.cursor = 'grab';
995
831
  }
996
- }
997
- }, {
998
- key: 'onImageLoad',
999
- value: function onImageLoad(index, orientation, event) {
1000
- this.incrementLoadedImages(orientation);
1001
832
 
1002
- var totalAmount = this.amountX + this.amountY;
1003
- var totalLoadedImages = this.loadedImagesX + this.loadedImagesY;
1004
-
1005
- var percentage = Math.round(totalLoadedImages / totalAmount * 100);
833
+ this.speedFactor = (0, _jsCloudimage360ViewUtils.getSpeedFactor)(this.dragSpeed, this.amountX, this.container.offsetWidth);
1006
834
 
1007
- this.updatePercentageInLoader(percentage);
1008
-
1009
- if (index === 0 && orientation !== _ci2.ORIENTATIONS.Y) {
1010
- this.onFirstImageLoaded(event);
1011
- }
1012
-
1013
- if (totalLoadedImages === totalAmount) {
1014
- this.onAllImagesLoaded(event);
835
+ if (this.autoplay) {
836
+ this.play();
1015
837
  }
1016
- }
1017
- }, {
1018
- key: 'addCloseFullscreenView',
1019
- value: function addCloseFullscreenView(event) {
1020
- var closeFullscreenIcon = document.createElement('div');
1021
- closeFullscreenIcon.className = 'cloudimage-360-close-fullscreen-icon';
1022
- closeFullscreenIcon.onclick = this.setFullscreenEvents.bind(this, event);
1023
-
1024
- window.onkeyup = this.setFullscreenEvents.bind(this, event);
1025
-
1026
- this.iconsContainer.appendChild(closeFullscreenIcon);
1027
- }
1028
- }, {
1029
- key: 'add360ViewIcon',
1030
- value: function add360ViewIcon() {
1031
- var view360Icon = document.createElement('div');
1032
-
1033
- view360Icon.className = 'cloudimage-360-view-360-icon';
1034
- view360Icon.innerText = '0%';
1035
-
1036
- this.view360Icon = view360Icon;
1037
- this.innerBox.appendChild(view360Icon);
1038
- }
1039
- }, {
1040
- key: 'addFullscreenIcon',
1041
- value: function addFullscreenIcon() {
1042
- var fullscreenIcon = document.createElement('div');
1043
-
1044
- fullscreenIcon.className = 'cloudimage-360-fullscreen-icon';
1045
- fullscreenIcon.onclick = this.openFullscreenModal.bind(this);
1046
-
1047
- this.fullscreenIcon = fullscreenIcon;
1048
-
1049
- this.iconsContainer.appendChild(fullscreenIcon);
1050
- }
1051
- }, {
1052
- key: 'hideFullscreenIcon',
1053
- value: function hideFullscreenIcon() {
1054
- if (!this.fullscreenIcon) return;
1055
-
1056
- this.fullscreenIcon.style.display = 'none';
1057
- this.fullscreenIcon.style.pointerEvents = 'none';
1058
- }
1059
- }, {
1060
- key: 'showFullscreenIcon',
1061
- value: function showFullscreenIcon() {
1062
- if (!this.fullscreenIcon) return;
1063
-
1064
- this.fullscreenIcon.style.display = 'block';
1065
- this.fullscreenIcon.style.pointerEvents = 'auto';
1066
- }
1067
- }, {
1068
- key: 'addMagnifier',
1069
- value: function addMagnifier() {
1070
- var magnifyIcon = document.createElement('div');
1071
-
1072
- magnifyIcon.className = 'cloudimage-360-magnifier-icon';
1073
- magnifyIcon.onclick = this.magnify.bind(this);
1074
-
1075
- this.magnifierIcon = magnifyIcon;
1076
-
1077
- this.iconsContainer.appendChild(magnifyIcon);
1078
- }
1079
- }, {
1080
- key: 'disableMagnifierIcon',
1081
- value: function disableMagnifierIcon() {
1082
- if (!this.magnifierIcon) return;
1083
-
1084
- this.magnifierIcon.style.display = 'none';
1085
- this.magnifierIcon.style.pointerEvents = 'none';
1086
- }
1087
- }, {
1088
- key: 'enableMagnifierIcon',
1089
- value: function enableMagnifierIcon() {
1090
- if (!this.magnifierIcon) return;
1091
-
1092
- this.magnifierIcon.style.display = 'block';
1093
- this.magnifierIcon.style.pointerEvents = 'auto';
1094
- }
1095
- }, {
1096
- key: 'getOriginalSrc',
1097
- value: function getOriginalSrc() {
1098
- var currentImage = this.originalImagesX[this.activeImageX - 1];
1099
-
1100
- if (this.movingDirection === _ci2.ORIENTATIONS.Y) {
1101
- currentImage = this.originalImagesY[this.activeImageY - 1];
1102
- };
1103
-
1104
- return currentImage.src;
1105
- }
1106
- }, {
1107
- key: 'magnify',
1108
- value: function magnify() {
1109
- var _this3 = this;
1110
-
1111
- var image = new Image();
1112
- var src = this.getOriginalSrc();
1113
- this.isMagnifyOpen = true;
1114
-
1115
- image.src = src;
1116
- image.onload = function () {
1117
- if (_this3.glass) {
1118
- _this3.glass.style.cursor = 'none';
1119
- }
1120
- };
1121
-
1122
- this.glass = document.createElement('div');
1123
- this.container.style.overflow = 'hidden';
1124
-
1125
- (0, _ci.magnify)(this.container, this.offset, src, this.glass, this.magnifier || 3);
1126
- }
1127
- }, {
1128
- key: 'closeMagnifier',
1129
- value: function closeMagnifier() {
1130
- if (!this.glass) return;
1131
-
1132
- this.container.style.overflow = 'visible';
1133
- this.container.removeChild(this.glass);
1134
- this.glass = null;
1135
- this.isMagnifyOpen = false;
1136
- }
1137
- }, {
1138
- key: 'openFullscreenModal',
1139
- value: function openFullscreenModal() {
1140
- var fullscreenModal = document.createElement('div');
1141
-
1142
- fullscreenModal.className = 'cloudimage-360-fullscreen-modal';
1143
-
1144
- var fullscreenContainer = this.container.cloneNode();
1145
- var image = this.imagesX[0];
1146
- var ratio = image.height / image.width;
1147
-
1148
- fullscreenContainer.style.height = '100%';
1149
- fullscreenContainer.style.maxHeight = '100%';
1150
-
1151
- fullscreenModal.appendChild(fullscreenContainer);
1152
-
1153
- window.document.body.style.overflow = 'hidden';
1154
- window.document.body.appendChild(fullscreenModal);
1155
-
1156
- new CI360Viewer(fullscreenContainer, true, ratio);
1157
- }
1158
- }, {
1159
- key: 'setFullscreenEvents',
1160
- value: function setFullscreenEvents(_, event) {
1161
- if (event.type === 'click') return this.closeFullscreenModal();
1162
- if (event.key === 'Escape') return this.closeFullscreenModalOnEsc();
1163
- }
1164
- }, {
1165
- key: 'closeFullscreenModalOnEsc',
1166
- value: function closeFullscreenModalOnEsc() {
1167
-
1168
- if (this.container.parentNode.parentNode === document.body) {
1169
- this.closeFullscreenModal();
1170
- };
1171
- }
1172
- }, {
1173
- key: 'closeFullscreenModal',
1174
- value: function closeFullscreenModal() {
1175
- document.body.removeChild(this.container.parentNode);
1176
- window.document.body.style.overflow = 'visible';
1177
- }
1178
- }, {
1179
- key: 'add360ViewCircleIcon',
1180
- value: function add360ViewCircleIcon() {
1181
- var view360CircleIcon = new Image();
1182
-
1183
- view360CircleIcon.src = 'https://scaleflex.ultrafast.io/https://scaleflex.api.airstore.io/v1/get/_/2236d56f-914a-5a8b-a3ae-f7bde1c50000/360.svg';
1184
-
1185
- view360CircleIcon.style.bottom = this.bottomCircleOffset + '%';
1186
- view360CircleIcon.className = 'cloudimage-360-view-360-circle';
1187
-
1188
- this.view360CircleIcon = view360CircleIcon;
1189
- this.innerBox.appendChild(view360CircleIcon);
1190
- }
1191
- }, {
1192
- key: 'hide360ViewCircleIcon',
1193
- value: function hide360ViewCircleIcon() {
1194
- if (!this.view360CircleIcon) return;
1195
-
1196
- this.view360CircleIcon.style.opacity = '0';
1197
- }
1198
- }, {
1199
- key: 'show360ViewCircleIcon',
1200
- value: function show360ViewCircleIcon() {
1201
- if (!this.view360CircleIcon) return;
1202
-
1203
- this.view360CircleIcon.style.opacity = '1';
1204
- }
1205
- }, {
1206
- key: 'remove360ViewCircleIcon',
1207
- value: function remove360ViewCircleIcon() {
1208
- if (!this.view360CircleIcon) return;
1209
-
1210
- this.innerBox.removeChild(this.view360CircleIcon);
1211
- this.view360CircleIcon = null;
1212
- }
1213
- }, {
1214
- key: 'addResetZoomIcon',
1215
- value: function addResetZoomIcon() {
1216
- var resetZoomIcon = document.createElement('div');
1217
838
 
1218
- resetZoomIcon.className = 'cloudimage-360-reset-zoom-icon';
1219
- this.resetZoomIcon = resetZoomIcon;
839
+ if (this.disableDrag) {
840
+ this.container.style.cursor = 'default';
841
+ }
1220
842
 
1221
- resetZoomIcon.onmouseenter = this.resetZoom.bind(this);
843
+ if (this.view360Icon) {
844
+ this.view360Icon.innerText = '';
845
+ (0, _ci.setView360Icon)(this.view360Icon, this.logoSrc);
846
+ }
1222
847
 
1223
- this.iconsContainer.appendChild(resetZoomIcon);
848
+ this.initControls();
1224
849
  }
1225
850
  }, {
1226
- key: 'hideResetZoomIcon',
1227
- value: function hideResetZoomIcon() {
1228
- if (!this.resetZoomIcon) return;
1229
- if (this.magnifierIcon) this.enableMagnifierIcon();
1230
- if (this.fullscreenIcon) this.showFullscreenIcon();
851
+ key: "magnify",
852
+ value: function magnify(event) {
853
+ var _this3 = this;
1231
854
 
1232
- this.resetZoomIcon.style.display = 'none';
1233
- }
1234
- }, {
1235
- key: 'showResetZoomIcon',
1236
- value: function showResetZoomIcon() {
1237
- if (!this.resetZoomIcon) return;
1238
- if (this.magnifierIcon) this.disableMagnifierIcon();
1239
- if (this.fullscreenIcon) this.hideFullscreenIcon();
855
+ event.stopPropagation();
856
+ if (this.mouseTracked) this.togglePointerZoom();
857
+ var currentOriginalImage = (0, _jsCloudimage360ViewUtils.getCurrentOriginalImage)(this.movingDirection, this.imagesX, this.imagesY, this.activeImageX, this.activeImageY);
858
+ this.isMagnifyOpen = true;
1240
859
 
1241
- this.resetZoomIcon.style.display = 'block';
1242
- }
1243
- }, {
1244
- key: 'addLoader',
1245
- value: function addLoader() {
1246
- var loader = document.createElement('div');
1247
- loader.className = 'cloudimage-360-loader';
860
+ currentOriginalImage.onload = function () {
861
+ if (_this3.glass) {
862
+ _this3.glass.style.cursor = 'none';
863
+ }
864
+ };
1248
865
 
1249
- this.loader = loader;
1250
- this.innerBox.appendChild(loader);
866
+ this.glass = document.createElement('div');
867
+ this.container.style.overflow = 'hidden';
868
+ (0, _jsCloudimage360ViewUtils.magnify)(this.container, this.offset, currentOriginalImage, this.glass, this.magnifier || 3);
1251
869
  }
1252
870
  }, {
1253
- key: 'addBoxShadow',
1254
- value: function addBoxShadow() {
1255
- var boxShadow = document.createElement('div');
1256
-
1257
- boxShadow.className = 'cloudimage-360-box-shadow';
1258
- boxShadow.style.boxShadow = this.boxShadow;
1259
-
1260
- this.innerBox.appendChild(boxShadow);
871
+ key: "closeMagnifier",
872
+ value: function closeMagnifier() {
873
+ if (!this.glass) return;
874
+ this.container.style.overflow = 'visible';
875
+ this.container.removeChild(this.glass);
876
+ this.glass = null;
877
+ this.isMagnifyOpen = false;
1261
878
  }
1262
879
  }, {
1263
- key: 'removeLoader',
1264
- value: function removeLoader() {
1265
- if (!this.loader) return;
1266
-
1267
- this.innerBox.removeChild(this.loader);
1268
- this.loader = null;
880
+ key: "openFullscreenModal",
881
+ value: function openFullscreenModal(event) {
882
+ event.stopPropagation();
883
+ if (this.mouseTracked) this.togglePointerZoom();
884
+ var fullscreenContainer = (0, _jsCloudimage360ViewUtils.createFullscreenModal)(this.container);
885
+ new CI360Viewer(fullscreenContainer, true);
1269
886
  }
1270
887
  }, {
1271
- key: 'remove360ViewIcon',
1272
- value: function remove360ViewIcon() {
1273
- if (!this.view360Icon) return;
888
+ key: "setFullscreenEvents",
889
+ value: function setFullscreenEvents(_, event) {
890
+ if (event.type === 'click') return this.closeFullscreenModal(event);
1274
891
 
1275
- this.innerBox.removeChild(this.view360Icon);
1276
- this.view360Icon = null;
892
+ if (event.key === 'Escape' && this.container.parentNode.parentNode === document.body) {
893
+ this.closeFullscreenModalOnEsc(event);
894
+ }
1277
895
  }
1278
896
  }, {
1279
- key: 'isCompletedCyle',
1280
- value: function isCompletedCyle() {
1281
- switch (this.autoplayBehavior) {
1282
- case _ci2.AUTOPLAY_BEHAVIOR.SPIN_XY:
1283
- case _ci2.AUTOPLAY_BEHAVIOR.SPIN_Y:
1284
- {
1285
- var isReachedTheEdge = this.reversed ? this.activeImageY === 1 : this.activeImageY === this.amountY;
1286
-
1287
- if (isReachedTheEdge) return true;
1288
-
1289
- return false;
1290
- }
1291
-
1292
- case _ci2.AUTOPLAY_BEHAVIOR.SPIN_X:
1293
- case _ci2.AUTOPLAY_BEHAVIOR.SPIN_YX:
1294
- default:
1295
- {
1296
- var _isReachedTheEdge = this.reversed ? this.activeImageX === 1 : this.activeImageX === this.amountX;
1297
-
1298
- if (_isReachedTheEdge) return true;
1299
-
1300
- return false;
1301
- }
1302
- }
897
+ key: "closeFullscreenModalOnEsc",
898
+ value: function closeFullscreenModalOnEsc(event) {
899
+ this.closeFullscreenModal(event);
1303
900
  }
1304
901
  }, {
1305
- key: 'play',
902
+ key: "play",
1306
903
  value: function play() {
1307
904
  var _this4 = this;
1308
905
 
1309
906
  if (this.bottomCircle) this.hide360ViewCircleIcon();
1310
907
  this.remove360ViewIcon();
1311
-
1312
908
  this.loopTimeoutId = window.setInterval(function () {
1313
909
  _this4.loop(_this4.reversed);
1314
910
 
1315
- var isPlayedOnce = _this4.isCompletedCyle();
911
+ var isPlayedOnce = (0, _jsCloudimage360ViewUtils.isCompletedOneCycle)(_this4.autoplayBehavior, _this4.activeImageX, _this4.activeImageY, _this4.amountX, _this4.amountY, _this4.reversed);
1316
912
 
1317
913
  if (_this4.playOnce && isPlayedOnce) {
1318
914
  window.clearTimeout(_this4.loopTimeoutId);
@@ -1325,119 +921,18 @@ var CI360Viewer = function () {
1325
921
  }, this.autoplaySpeed);
1326
922
  }
1327
923
  }, {
1328
- key: 'stop',
924
+ key: "stop",
1329
925
  value: function stop() {
1330
- if (this.bottomCircle && !this.zoomIntensity) this.show360ViewCircleIcon();
926
+ if (this.bottomCircle) this.show360ViewCircleIcon();
1331
927
  window.clearTimeout(this.loopTimeoutId);
1332
928
  }
1333
929
  }, {
1334
- key: 'getSrc',
1335
- value: function getSrc(responsive, container, folder, filename, _ref) {
1336
- var ciToken = _ref.ciToken,
1337
- ciFilters = _ref.ciFilters,
1338
- ciTransformation = _ref.ciTransformation;
1339
-
1340
- var src = '' + folder + filename;
1341
-
1342
- if (responsive) {
1343
- var imageOffsetWidth = container.offsetWidth;
1344
-
1345
- if (this.fullscreenView) {
1346
- var containerRatio = container.offsetHeight / container.offsetWidth;
1347
-
1348
- if (this.ratio > containerRatio) {
1349
- imageOffsetWidth = container.offsetHeight / this.ratio;
1350
- }
1351
- }
1352
-
1353
- var ciSizeNext = (0, _ci.getSizeAccordingToPixelRatio)((0, _ci.getResponsiveWidthOfContainer)(imageOffsetWidth));
1354
-
1355
- src = 'https://' + ciToken + '.cloudimg.io/v7/' + src + '?' + (ciTransformation ? ciTransformation : 'width=' + ciSizeNext) + (ciFilters ? '&f=' + ciFilters : '');
1356
- }
1357
-
1358
- return src;
1359
- }
1360
- }, {
1361
- key: 'preloadImages',
1362
- value: function preloadImages(amount, src) {
1363
- var orientation = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _ci2.ORIENTATIONS.X;
1364
- var lazyload = arguments[3];
1365
- var lazySelector = arguments[4];
1366
- var container = arguments[5];
1367
-
1368
- var _this5 = this;
1369
-
1370
- var responsive = arguments[6];
1371
- var ciParams = arguments[7];
1372
-
1373
- if (this.imageList) {
1374
- try {
1375
- var images = JSON.parse(this.imageList);
1376
-
1377
- this.amountX = images.length;
1378
- images.forEach(function (src, index) {
1379
- var folder = /(http(s?)):\/\//gi.test(src) ? '' : _this5.folder;
1380
- var resultSrc = _this5.getSrc(responsive, container, folder, src, ciParams);
1381
- var lastIndex = resultSrc.lastIndexOf('//');
1382
- var originalSrc = resultSrc.slice(lastIndex);
1383
-
1384
- _this5.addImage(resultSrc, originalSrc, orientation, lazyload, lazySelector, index);
1385
- });
1386
- } catch (error) {
1387
- console.error('Wrong format in image-list attribute: ' + error.message);
1388
- }
1389
- } else {
1390
- [].concat(_toConsumableArray(new Array(amount))).map(function (_item, index) {
1391
- var nextZeroFilledIndex = (0, _ci.pad)(index + 1, _this5.indexZeroBase);
1392
- var resultSrc = src.replace('{index}', nextZeroFilledIndex);
1393
- var originalSrc = resultSrc.replace(_ci2.ORGINAL_SIZE_REGEX, '').replace(_ci2.AND_SYMBOL_REGEX, '?');
1394
-
1395
- _this5.addImage(resultSrc, originalSrc, orientation, lazyload, lazySelector, index);
1396
- });
1397
- }
1398
- }
1399
- }, {
1400
- key: 'addImage',
1401
- value: function addImage(resultSrc, originalSrc, orientation, lazyload, lazySelector, index) {
1402
- var image = new Image();
1403
- var originalImage = new Image();
1404
-
1405
- if (lazyload && !this.fullscreenView) {
1406
- image.setAttribute('data-src', resultSrc);
1407
- image.className = image.className.length ? image.className + (' ' + lazySelector) : lazySelector;
1408
-
1409
- if (index === 0) {
1410
- this.lazyloadInitImage = image;
1411
- image.style.position = 'absolute';
1412
- image.style.top = '0';
1413
- image.style.left = '0';
1414
- this.innerBox.appendChild(image);
1415
- }
1416
- } else {
1417
- image.src = resultSrc;
1418
- originalImage.src = originalSrc;
1419
- }
1420
-
1421
- image.onload = this.onImageLoad.bind(this, index, orientation);
1422
- image.onerror = this.onImageLoad.bind(this, index, orientation);
1423
-
1424
- if (orientation === _ci2.ORIENTATIONS.Y) {
1425
- this.imagesY.push(image);
1426
- this.originalImagesY.push(originalImage);
1427
- } else {
1428
- this.imagesX.push(image);
1429
- this.originalImagesX.push(originalImage);
1430
- }
1431
- }
1432
- }, {
1433
- key: 'destroy',
930
+ key: "destroy",
1434
931
  value: function destroy() {
1435
932
  stop();
1436
-
1437
933
  var oldElement = this.container;
1438
934
  var newElement = oldElement.cloneNode(true);
1439
935
  var innerBox = newElement.querySelector('.cloudimage-360-inner-box');
1440
-
1441
936
  newElement.className = newElement.className.replace(' initialized', '');
1442
937
  newElement.style.position = 'relative';
1443
938
  newElement.style.width = '100%';
@@ -1448,245 +943,241 @@ var CI360Viewer = function () {
1448
943
  oldElement.parentNode.replaceChild(newElement, oldElement);
1449
944
  }
1450
945
  }, {
1451
- key: 'initControls',
946
+ key: "addCloseFullscreenView",
947
+ value: function addCloseFullscreenView(event) {
948
+ var closeFullscreenIcon = (0, _jsCloudimage360ViewUtils.createCloseFullscreenIcon)();
949
+ closeFullscreenIcon.onclick = this.setFullscreenEvents.bind(this, event);
950
+ window.onkeyup = this.setFullscreenEvents.bind(this, event);
951
+ this.iconsContainer.appendChild(closeFullscreenIcon);
952
+ }
953
+ }, {
954
+ key: "add360ViewIcon",
955
+ value: function add360ViewIcon() {
956
+ this.view360Icon = (0, _jsCloudimage360ViewUtils.create360ViewIcon)();
957
+ this.innerBox.appendChild(this.view360Icon);
958
+ }
959
+ }, {
960
+ key: "addFullscreenIcon",
961
+ value: function addFullscreenIcon() {
962
+ this.fullscreenIcon = (0, _jsCloudimage360ViewUtils.createFullscreenIcon)();
963
+ this.fullscreenIcon.onclick = this.openFullscreenModal.bind(this);
964
+ this.iconsContainer.appendChild(this.fullscreenIcon);
965
+ }
966
+ }, {
967
+ key: "showFullscreenIcon",
968
+ value: function showFullscreenIcon() {
969
+ if (!this.fullscreenIcon) return;
970
+ this.fullscreenIcon.style.display = 'block';
971
+ this.fullscreenIcon.style.pointerEvents = 'auto';
972
+ }
973
+ }, {
974
+ key: "hideFullscreenIcon",
975
+ value: function hideFullscreenIcon() {
976
+ if (!this.fullscreenIcon) return;
977
+ this.fullscreenIcon.style.display = 'none';
978
+ this.fullscreenIcon.style.pointerEvents = 'none';
979
+ }
980
+ }, {
981
+ key: "addMagnifier",
982
+ value: function addMagnifier() {
983
+ this.magnifierIcon = (0, _jsCloudimage360ViewUtils.createMagnifierIcon)();
984
+ this.magnifierIcon.onclick = this.magnify.bind(this);
985
+ this.iconsContainer.appendChild(this.magnifierIcon);
986
+ }
987
+ }, {
988
+ key: "enableMagnifierIcon",
989
+ value: function enableMagnifierIcon() {
990
+ if (!this.magnifierIcon) return;
991
+ this.magnifierIcon.style.display = 'block';
992
+ this.magnifierIcon.style.pointerEvents = 'auto';
993
+ }
994
+ }, {
995
+ key: "disableMagnifierIcon",
996
+ value: function disableMagnifierIcon() {
997
+ if (!this.magnifierIcon) return;
998
+ this.magnifierIcon.style.display = 'none';
999
+ this.magnifierIcon.style.pointerEvents = 'none';
1000
+ }
1001
+ }, {
1002
+ key: "closeFullscreenModal",
1003
+ value: function closeFullscreenModal(event) {
1004
+ event.stopPropagation();
1005
+ document.body.removeChild(this.container.parentNode);
1006
+ window.document.body.style.overflow = 'visible';
1007
+ }
1008
+ }, {
1009
+ key: "add360ViewCircleIcon",
1010
+ value: function add360ViewCircleIcon() {
1011
+ this.view360CircleIcon = (0, _jsCloudimage360ViewUtils.create360ViewCircleIcon)(this.bottomCircleOffset);
1012
+ this.innerBox.appendChild(this.view360CircleIcon);
1013
+ }
1014
+ }, {
1015
+ key: "show360ViewCircleIcon",
1016
+ value: function show360ViewCircleIcon() {
1017
+ if (!this.view360CircleIcon) return;
1018
+ this.view360CircleIcon.style.opacity = '1';
1019
+ }
1020
+ }, {
1021
+ key: "hide360ViewCircleIcon",
1022
+ value: function hide360ViewCircleIcon() {
1023
+ if (!this.view360CircleIcon) return;
1024
+ this.view360CircleIcon.style.opacity = '0';
1025
+ }
1026
+ }, {
1027
+ key: "remove360ViewCircleIcon",
1028
+ value: function remove360ViewCircleIcon() {
1029
+ if (!this.view360CircleIcon) return;
1030
+ this.innerBox.removeChild(this.view360CircleIcon);
1031
+ this.view360CircleIcon = null;
1032
+ }
1033
+ }, {
1034
+ key: "removeLoader",
1035
+ value: function removeLoader() {
1036
+ if (!this.loader) return;
1037
+ this.innerBox.removeChild(this.loader);
1038
+ this.loader = null;
1039
+ }
1040
+ }, {
1041
+ key: "remove360ViewIcon",
1042
+ value: function remove360ViewIcon() {
1043
+ if (!this.view360Icon) return;
1044
+ this.innerBox.removeChild(this.view360Icon);
1045
+ this.view360Icon = null;
1046
+ }
1047
+ }, {
1048
+ key: "initControls",
1452
1049
  value: function initControls() {
1453
- var _this6 = this;
1454
-
1455
- var isReverse = this.controlReverse ? !this.spinReverse : this.spinReverse;
1456
- // TODO [deprecated]: remove .cloud-360-left, .cloud-360-right in the upcoming versions
1457
- var left = this.container.querySelector('.cloudimage-360-left') || this.container.querySelector('.cloudimage-360-prev');
1458
- var right = this.container.querySelector('.cloudimage-360-right') || this.container.querySelector('.cloudimage-360-next');
1459
-
1460
- var top = this.container.querySelector('.cloudimage-360-top');
1461
- var bottom = this.container.querySelector('.cloudimage-360-bottom');
1462
-
1463
- if (!left && !right && !top && !bottom) return;
1050
+ var _this5 = this;
1464
1051
 
1465
1052
  var onLeftStart = function onLeftStart(event) {
1466
1053
  event.stopPropagation();
1467
- _this6.onSpin();
1468
- _this6.left();
1469
- _this6.loopTimeoutId = window.setInterval(_this6.left.bind(_this6), _this6.autoplaySpeed);
1470
- };
1471
- var onRightStart = function onRightStart(event) {
1472
- event.stopPropagation();
1473
- _this6.onSpin();
1474
- _this6.right();
1475
- _this6.loopTimeoutId = window.setInterval(_this6.right.bind(_this6), _this6.autoplaySpeed);
1476
- };
1477
1054
 
1478
- var onTopStart = function onTopStart(event) {
1479
- event.stopPropagation();
1480
- _this6.onSpin();
1481
- _this6.top();
1482
- _this6.loopTimeoutId = window.setInterval(_this6.top.bind(_this6), _this6.autoplaySpeed);
1483
- };
1055
+ _this5.onSpin();
1484
1056
 
1485
- var onBottomStart = function onBottomStart(event) {
1486
- event.stopPropagation();
1487
- _this6.onSpin();
1488
- _this6.bottom();
1489
- _this6.loopTimeoutId = window.setInterval(_this6.bottom.bind(_this6), _this6.autoplaySpeed);
1490
- };
1057
+ _this5.left();
1491
1058
 
1492
- var onLeftEnd = function onLeftEnd() {
1493
- _this6.onFinishSpin();
1494
- window.clearTimeout(_this6.loopTimeoutId);
1059
+ _this5.loopTimeoutId = window.setInterval(_this5.left.bind(_this5), _this5.autoplaySpeed);
1495
1060
  };
1496
1061
 
1497
- var onRightEnd = function onRightEnd() {
1498
- _this6.onFinishSpin();
1499
- window.clearTimeout(_this6.loopTimeoutId);
1500
- };
1062
+ var onRightStart = function onRightStart(event) {
1063
+ event.stopPropagation();
1501
1064
 
1502
- var onTopEnd = function onTopEnd() {
1503
- _this6.onFinishSpin();
1504
- window.clearTimeout(_this6.loopTimeoutId);
1505
- };
1065
+ _this5.onSpin();
1506
1066
 
1507
- var onBottomEnd = function onBottomEnd() {
1508
- _this6.onFinishSpin();
1509
- window.clearTimeout(_this6.loopTimeoutId);
1510
- };
1067
+ _this5.right();
1511
1068
 
1512
- if (left) {
1513
- left.style.display = 'block';
1514
- left.addEventListener('mousedown', isReverse ? onRightStart : onLeftStart);
1515
- left.addEventListener('touchstart', isReverse ? onRightStart : onLeftStart, { passive: true });
1516
- left.addEventListener('mouseup', isReverse ? onRightEnd : onLeftEnd);
1517
- left.addEventListener('touchend', isReverse ? onRightEnd : onLeftEnd);
1069
+ _this5.loopTimeoutId = window.setInterval(_this5.right.bind(_this5), _this5.autoplaySpeed);
1070
+ };
1518
1071
 
1519
- this.leftElem = left;
1520
- }
1072
+ var onTopStart = function onTopStart(event) {
1073
+ event.stopPropagation();
1521
1074
 
1522
- if (right) {
1523
- right.style.display = 'block';
1524
- right.addEventListener('mousedown', isReverse ? onLeftStart : onRightStart);
1525
- right.addEventListener('touchstart', isReverse ? onLeftStart : onRightStart, { passive: true });
1526
- right.addEventListener('mouseup', isReverse ? onLeftEnd : onRightEnd);
1527
- right.addEventListener('touchend', isReverse ? onLeftEnd : onRightEnd);
1075
+ _this5.onSpin();
1528
1076
 
1529
- this.rightElem = right;
1530
- }
1077
+ _this5.top();
1531
1078
 
1532
- if (top) {
1533
- top.style.display = 'block';
1534
- top.addEventListener('mousedown', isReverse ? onBottomStart : onTopStart);
1535
- top.addEventListener('touchstart', isReverse ? onBottomStart : onTopStart);
1536
- top.addEventListener('mouseup', isReverse ? onBottomEnd : onTopEnd);
1537
- top.addEventListener('touchend', isReverse ? onBottomEnd : onTopEnd);
1079
+ _this5.loopTimeoutId = window.setInterval(_this5.top.bind(_this5), _this5.autoplaySpeed);
1080
+ };
1538
1081
 
1539
- this.topElem = top;
1540
- }
1082
+ var onBottomStart = function onBottomStart(event) {
1083
+ event.stopPropagation();
1541
1084
 
1542
- if (bottom) {
1543
- bottom.style.display = 'block';
1544
- bottom.addEventListener('mousedown', isReverse ? onTopStart : onBottomStart);
1545
- bottom.addEventListener('touchstart', isReverse ? onTopStart : onBottomStart);
1546
- bottom.addEventListener('mouseup', isReverse ? onTopEnd : onBottomEnd);
1547
- bottom.addEventListener('touchend', isReverse ? onTopEnd : onBottomEnd);
1085
+ _this5.onSpin();
1548
1086
 
1549
- this.bottomElem = bottom;
1550
- }
1087
+ _this5.bottom();
1551
1088
 
1552
- if (isReverse ? right : left) {
1553
- if (this.stopAtEdges) {
1554
- (0, _ci.addClass)(isReverse ? right : left, 'not-active');
1555
- }
1556
- }
1557
- }
1558
- }, {
1559
- key: 'addInnerBox',
1560
- value: function addInnerBox() {
1561
- this.innerBox = document.createElement('div');
1562
- this.innerBox.className = 'cloudimage-360-inner-box';
1563
- this.container.appendChild(this.innerBox);
1564
- }
1565
- }, {
1566
- key: 'addIconsContainer',
1567
- value: function addIconsContainer() {
1568
- this.iconsContainer = document.createElement('div');
1569
- this.iconsContainer.className = 'cloudimage-360-icons-container';
1089
+ _this5.loopTimeoutId = window.setInterval(_this5.bottom.bind(_this5), _this5.autoplaySpeed);
1090
+ };
1570
1091
 
1571
- this.innerBox.appendChild(this.iconsContainer);
1572
- }
1573
- }, {
1574
- key: 'addCanvas',
1575
- value: function addCanvas() {
1576
- this.canvas = document.createElement('canvas');
1577
- this.canvas.style.width = '100%';
1578
- this.canvas.style.fontSize = '0';
1092
+ var onEventEnd = function onEventEnd() {
1093
+ _this5.onFinishSpin();
1579
1094
 
1580
- if (this.ratio) {
1581
- this.container.style.minHeight = this.container.offsetWidth * this.ratio + 'px';
1582
- this.canvas.height = parseInt(this.container.style.minHeight);
1583
- }
1095
+ window.clearTimeout(_this5.loopTimeoutId);
1096
+ };
1584
1097
 
1585
- this.innerBox.appendChild(this.canvas);
1098
+ var controlsConfig = {
1099
+ container: this.container,
1100
+ controlReverse: this.controlReverse,
1101
+ spinReverse: this.spinReverse,
1102
+ stopAtEdges: this.stopAtEdges
1103
+ };
1104
+ var controlsTriggers = {
1105
+ onLeftStart: onLeftStart,
1106
+ onRightStart: onRightStart,
1107
+ onTopStart: onTopStart,
1108
+ onBottomStart: onBottomStart,
1109
+ onEventEnd: onEventEnd
1110
+ };
1111
+ var controlsElements = (0, _jsCloudimage360ViewUtils.initControls)(controlsConfig, controlsTriggers);
1112
+ this.topElem = controlsElements.top || {};
1113
+ this.bottomElem = controlsElements.bottom || {};
1114
+ this.leftElem = controlsElements.left || {};
1115
+ this.rightElem = controlsElements.right || {};
1586
1116
  }
1587
1117
  }, {
1588
- key: 'attachEvents',
1118
+ key: "attachEvents",
1589
1119
  value: function attachEvents(draggable, swipeable, keys) {
1590
- var _this7 = this;
1591
-
1592
- window.addEventListener('resize', (0, _ci.debounce)(function () {
1593
- _this7.requestResizedImages();
1594
- }, 300));
1120
+ window.addEventListener('resize', this.requestResizedImages.bind(this));
1595
1121
 
1596
1122
  if (draggable && !this.disableDrag) {
1123
+ this.container.addEventListener('click', this.mouseClick.bind(this));
1597
1124
  this.container.addEventListener('mousedown', this.mouseDown.bind(this));
1598
1125
  this.container.addEventListener('mousemove', this.mouseMove.bind(this));
1126
+ this.container.addEventListener('mouseleave', this.mouseLeave.bind(this));
1599
1127
  document.addEventListener('mouseup', this.mouseUp.bind(this));
1600
1128
  }
1601
1129
 
1602
1130
  if (swipeable && !this.disableDrag) {
1603
- this.container.addEventListener('touchstart', this.touchStart.bind(this), { passive: true });
1131
+ this.container.addEventListener('touchstart', this.touchStart.bind(this), {
1132
+ passive: true
1133
+ });
1604
1134
  this.container.addEventListener('touchend', this.touchEnd.bind(this));
1605
- this.container.addEventListener('touchmove', this.touchMove.bind(this), { passive: true });
1606
- }
1607
-
1608
- if (!this.disablePointerZoom && !this.fullscreenView) {
1609
- this.container.addEventListener('click', this.mouseClick.bind(this));
1610
- this.container.addEventListener('wheel', this.mouseScroll.bind(this));
1135
+ this.container.addEventListener('touchmove', this.touchMove.bind(this), {
1136
+ passive: true
1137
+ });
1611
1138
  }
1612
1139
 
1613
1140
  if (keys) {
1614
1141
  document.addEventListener('keydown', this.keyDown.bind(this));
1615
1142
  document.addEventListener('keyup', this.keyUp.bind(this));
1616
- } else {
1617
- document.addEventListener('keydown', this.keyDownGeneral.bind(this));
1618
1143
  }
1619
- }
1620
- }, {
1621
- key: 'applyStylesToContainer',
1622
- value: function applyStylesToContainer() {
1623
- this.container.style.position = 'relative';
1624
- this.container.style.width = '100%';
1625
- this.container.style.cursor = 'wait';
1626
- this.container.setAttribute('draggable', 'false');
1627
- this.container.className = this.container.className + ' initialized';
1628
- }
1629
- }, {
1630
- key: 'setMouseLeaveActions',
1631
- value: function setMouseLeaveActions(actions) {
1632
- var _this8 = this;
1633
-
1634
- var mouseLeaveActions = actions.split(',');
1635
1144
 
1636
- mouseLeaveActions.forEach(function (action) {
1637
- return _this8.applyMouseLeaveAction(action);
1638
- });
1639
- }
1640
- }, {
1641
- key: 'applyMouseLeaveAction',
1642
- value: function applyMouseLeaveAction(action) {
1643
- switch (action) {
1644
- case _ci2.MOUSE_LEAVE_ACTIONS.RESET_ZOOM:
1645
- this.container.addEventListener('mouseleave', this.resetZoom.bind(this));
1646
- break;
1647
- }
1145
+ document.addEventListener('keydown', this.keyDownGeneral.bind(this));
1648
1146
  }
1649
1147
  }, {
1650
- key: 'init',
1148
+ key: "init",
1651
1149
  value: function init(container) {
1150
+ var _this6 = this;
1151
+
1652
1152
  var _get360ViewProps = (0, _ci.get360ViewProps)(container),
1653
1153
  folder = _get360ViewProps.folder,
1154
+ apiVersion = _get360ViewProps.apiVersion,
1654
1155
  filenameX = _get360ViewProps.filenameX,
1655
1156
  filenameY = _get360ViewProps.filenameY,
1656
- imageList = _get360ViewProps.imageList,
1157
+ imageListX = _get360ViewProps.imageListX,
1158
+ imageListY = _get360ViewProps.imageListY,
1657
1159
  indexZeroBase = _get360ViewProps.indexZeroBase,
1658
1160
  amountX = _get360ViewProps.amountX,
1659
1161
  amountY = _get360ViewProps.amountY,
1660
1162
  imageOffset = _get360ViewProps.imageOffset,
1661
1163
  _get360ViewProps$drag = _get360ViewProps.draggable,
1662
- draggable = _get360ViewProps$drag === undefined ? true : _get360ViewProps$drag,
1164
+ draggable = _get360ViewProps$drag === void 0 ? true : _get360ViewProps$drag,
1663
1165
  _get360ViewProps$swip = _get360ViewProps.swipeable,
1664
- swipeable = _get360ViewProps$swip === undefined ? true : _get360ViewProps$swip,
1166
+ swipeable = _get360ViewProps$swip === void 0 ? true : _get360ViewProps$swip,
1665
1167
  keys = _get360ViewProps.keys,
1168
+ keysReverse = _get360ViewProps.keysReverse,
1666
1169
  bottomCircle = _get360ViewProps.bottomCircle,
1667
1170
  bottomCircleOffset = _get360ViewProps.bottomCircleOffset,
1668
1171
  boxShadow = _get360ViewProps.boxShadow,
1669
1172
  autoplay = _get360ViewProps.autoplay,
1670
1173
  autoplayBehavior = _get360ViewProps.autoplayBehavior,
1671
1174
  playOnce = _get360ViewProps.playOnce,
1672
- pointerZoomFactor = _get360ViewProps.pointerZoomFactor,
1673
- pinchZoomFactor = _get360ViewProps.pinchZoomFactor,
1674
- maxScale = _get360ViewProps.maxScale,
1675
- toStartPointerZoom = _get360ViewProps.toStartPointerZoom,
1676
- onMouseLeave = _get360ViewProps.onMouseLeave,
1677
- _get360ViewProps$disa = _get360ViewProps.disablePointerZoom,
1678
- disablePointerZoom = _get360ViewProps$disa === undefined ? true : _get360ViewProps$disa,
1679
- _get360ViewProps$disa2 = _get360ViewProps.disablePinchZoom,
1680
- disablePinchZoom = _get360ViewProps$disa2 === undefined ? true : _get360ViewProps$disa2,
1681
1175
  speed = _get360ViewProps.speed,
1682
1176
  autoplayReverse = _get360ViewProps.autoplayReverse,
1683
- _get360ViewProps$disa3 = _get360ViewProps.disableDrag,
1684
- disableDrag = _get360ViewProps$disa3 === undefined ? true : _get360ViewProps$disa3,
1177
+ _get360ViewProps$disa = _get360ViewProps.disableDrag,
1178
+ disableDrag = _get360ViewProps$disa === void 0 ? true : _get360ViewProps$disa,
1685
1179
  fullscreen = _get360ViewProps.fullscreen,
1686
1180
  magnifier = _get360ViewProps.magnifier,
1687
- magnifyInFullscreen = _get360ViewProps.magnifyInFullscreen,
1688
- ratio = _get360ViewProps.ratio,
1689
- responsive = _get360ViewProps.responsive,
1690
1181
  ciToken = _get360ViewProps.ciToken,
1691
1182
  ciFilters = _get360ViewProps.ciFilters,
1692
1183
  ciTransformation = _get360ViewProps.ciTransformation,
@@ -1697,24 +1188,28 @@ var CI360Viewer = function () {
1697
1188
  stopAtEdges = _get360ViewProps.stopAtEdges,
1698
1189
  controlReverse = _get360ViewProps.controlReverse,
1699
1190
  hide360Logo = _get360ViewProps.hide360Logo,
1700
- logoSrc = _get360ViewProps.logoSrc;
1701
-
1702
- var ciParams = { ciToken: ciToken, ciFilters: ciFilters, ciTransformation: ciTransformation };
1703
-
1704
- this.addInnerBox();
1705
- this.addIconsContainer();
1706
- this.addLoader();
1707
-
1191
+ logoSrc = _get360ViewProps.logoSrc,
1192
+ containerWidth = _get360ViewProps.containerWidth,
1193
+ containerHeight = _get360ViewProps.containerHeight,
1194
+ pointerZoom = _get360ViewProps.pointerZoom;
1195
+
1196
+ var ciParams = {
1197
+ ciToken: ciToken,
1198
+ ciFilters: ciFilters,
1199
+ ciTransformation: ciTransformation
1200
+ };
1708
1201
  this.folder = folder;
1202
+ this.apiVersion = apiVersion;
1709
1203
  this.filenameX = filenameX;
1710
1204
  this.filenameY = filenameY;
1711
- this.imageList = imageList;
1205
+ this.imageListX = imageListX;
1206
+ this.imageListY = imageListY;
1712
1207
  this.indexZeroBase = indexZeroBase;
1713
- this.amountX = amountX;
1714
- this.amountY = amountY;
1715
- this.allowSpinY = !!amountY && !!filenameY;
1716
- this.activeImageX = autoplayReverse ? amountX : 1;
1717
- this.activeImageY = autoplayReverse ? amountY : 1;
1208
+ this.amountX = imageListX ? JSON.parse(imageListX).length : amountX;
1209
+ this.amountY = imageListY ? JSON.parse(imageListY).length : amountY;
1210
+ this.allowSpinY = !!this.amountY;
1211
+ this.activeImageX = autoplayReverse ? this.amountX : 1;
1212
+ this.activeImageY = autoplayReverse ? this.amountY : 1;
1718
1213
  this.spinY = autoplayBehavior === _ci2.AUTOPLAY_BEHAVIOR.SPIN_YX ? true : false;
1719
1214
  this.imageOffset = imageOffset;
1720
1215
  this.bottomCircle = bottomCircle;
@@ -1723,20 +1218,14 @@ var CI360Viewer = function () {
1723
1218
  this.autoplay = autoplay;
1724
1219
  this.autoplayBehavior = autoplayBehavior;
1725
1220
  this.playOnce = playOnce;
1726
- this.toStartPointerZoom = toStartPointerZoom, this.disablePointerZoom = disablePointerZoom;
1727
- this.disablePinchZoom = disablePinchZoom;
1728
- this.pointerZoomFactor = pointerZoomFactor;
1729
- this.pinchZoomFactor = pinchZoomFactor;
1730
- this.maxScale = maxScale;
1731
1221
  this.speed = speed;
1732
1222
  this.reversed = autoplayReverse;
1733
1223
  this.disableDrag = disableDrag;
1734
1224
  this.fullscreen = fullscreen;
1735
1225
  this.magnifier = !this.isMobile && magnifier ? magnifier : false;
1736
- this.magnifyInFullscreen = magnifyInFullscreen;
1737
- this.lazyload = lazyload;
1226
+ this.lazyloadX = lazyload;
1227
+ this.lazyloadY = lazyload;
1738
1228
  this.lazySelector = lazySelector;
1739
- this.ratio = ratio;
1740
1229
  this.spinReverse = spinReverse;
1741
1230
  this.controlReverse = controlReverse;
1742
1231
  this.dragSpeed = dragSpeed;
@@ -1744,29 +1233,110 @@ var CI360Viewer = function () {
1744
1233
  this.stopAtEdges = stopAtEdges;
1745
1234
  this.hide360Logo = hide360Logo;
1746
1235
  this.logoSrc = logoSrc;
1747
- this.responsive = responsive;
1748
1236
  this.ciParams = ciParams;
1237
+ this.apiVersion = apiVersion;
1238
+ this.containerWidth = containerWidth;
1239
+ this.containerHeight = containerHeight;
1240
+ this.pointerZoom = pointerZoom > 1 ? pointerZoom : 0;
1241
+ this.keysReverse = keysReverse;
1242
+ this.innerBox = (0, _jsCloudimage360ViewUtils.createInnerBox)(this.container);
1243
+ this.iconsContainer = (0, _jsCloudimage360ViewUtils.createIconsContainer)(this.innerBox);
1244
+ this.canvas = (0, _jsCloudimage360ViewUtils.createCanvas)(this.innerBox);
1245
+ this.loader = (0, _jsCloudimage360ViewUtils.createLoader)(this.innerBox);
1246
+ (0, _jsCloudimage360ViewUtils.applyStylesToContainer)(this.container);
1247
+ this.srcXConfig = {
1248
+ folder: folder,
1249
+ filename: filenameX,
1250
+ imageList: imageListX,
1251
+ container: container,
1252
+ innerBox: this.innerBox,
1253
+ apiVersion: apiVersion,
1254
+ ciParams: ciParams,
1255
+ lazyload: lazyload,
1256
+ lazySelector: lazySelector,
1257
+ amount: this.amountX,
1258
+ indexZeroBase: indexZeroBase,
1259
+ fullscreen: this.fullscreenView
1260
+ };
1261
+ this.srcYConfig = _objectSpread(_objectSpread({}, this.srcXConfig), {}, {
1262
+ filename: filenameY,
1263
+ orientation: _ci2.ORIENTATIONS.Y,
1264
+ imageList: imageListY,
1265
+ amount: this.amountY
1266
+ });
1267
+ var srcX = (0, _jsCloudimage360ViewUtils.generateImagesPath)(this.srcXConfig);
1268
+ var srcY = (0, _jsCloudimage360ViewUtils.generateImagesPath)(this.srcYConfig);
1269
+
1270
+ var initLazyload = function initLazyload(image, orientation) {
1271
+ var lazyloadXConfig = _objectSpread(_objectSpread({}, _this6.srcXConfig), {}, {
1272
+ lazyload: false
1273
+ });
1274
+
1275
+ var lazyloadYConfig = _objectSpread(_objectSpread({}, _this6.srcYConfig), {}, {
1276
+ lazyload: false
1277
+ });
1278
+
1279
+ if (orientation === _ci2.ORIENTATIONS.Y) {
1280
+ _this6.lazyloadY = false;
1281
+ (0, _jsCloudimage360ViewUtils.preloadImages)(lazyloadXConfig, srcX, onImageLoad.bind(_this6, _ci2.ORIENTATIONS.X));
1282
+ } else {
1283
+ _this6.lazyloadX = false;
1284
+ _this6.lazyloadInitImageX = image;
1285
+ (0, _jsCloudimage360ViewUtils.preloadImages)(lazyloadYConfig, srcY, onImageLoad.bind(_this6, _ci2.ORIENTATIONS.Y));
1286
+ }
1287
+ };
1288
+
1289
+ var onImageLoad = function onImageLoad(orientation, image, index) {
1290
+ if (orientation !== _ci2.ORIENTATIONS.Y) {
1291
+ _this6.imagesX[index] = image;
1292
+ } else {
1293
+ _this6.imagesY[index] = image;
1294
+ }
1295
+
1296
+ var loadedXImages = _this6.imagesX.filter(function (image) {
1297
+ return !!image;
1298
+ });
1299
+
1300
+ var loadedYImages = _this6.imagesY.filter(function (image) {
1301
+ return !!image;
1302
+ });
1303
+
1304
+ var totalAmount = _this6.amountX + _this6.amountY;
1305
+ var totalLoadedImages = _this6.imagesX.length + _this6.imagesY.length;
1306
+ var isFirstImageLoaded = index === 0 && orientation !== _ci2.ORIENTATIONS.Y;
1307
+ var isAllImagesLoaded = loadedXImages.length + loadedYImages.length === _this6.amountX + _this6.amountY;
1308
+ var percentage = Math.round(totalLoadedImages / totalAmount * 100);
1309
+
1310
+ _this6.updatePercentageInLoader(percentage);
1311
+
1312
+ if (_this6.lazyloadX || _this6.lazyloadY) return initLazyload(image, orientation);
1749
1313
 
1750
- this.applyStylesToContainer();
1314
+ if (isFirstImageLoaded) {
1315
+ _this6.updateContainerSize(image);
1751
1316
 
1752
- this.addCanvas();
1317
+ _this6.onFirstImageLoaded(image);
1318
+ }
1319
+
1320
+ if (isAllImagesLoaded) {
1321
+ _this6.onAllImagesLoaded();
1753
1322
 
1754
- var srcX = this.getSrc(responsive, container, folder, filenameX, ciParams);
1755
- var srcY = this.getSrc(responsive, container, folder, filenameY, ciParams);
1323
+ if (lazyload) {
1324
+ _this6.innerBox.removeChild(_this6.lazyloadInitImageX);
1325
+ }
1326
+ }
1327
+ };
1756
1328
 
1757
- this.preloadImages(amountX, srcX, _ci2.ORIENTATIONS.X, lazyload, lazySelector, container, responsive, ciParams);
1329
+ (0, _jsCloudimage360ViewUtils.preloadImages)(this.srcXConfig, srcX, onImageLoad.bind(this, _ci2.ORIENTATIONS.X));
1758
1330
 
1759
- if (amountY) {
1760
- this.preloadImages(amountY, srcY, _ci2.ORIENTATIONS.Y, lazyload, lazySelector, container, responsive, ciParams);
1331
+ if (this.allowSpinY) {
1332
+ (0, _jsCloudimage360ViewUtils.preloadImages)(this.srcYConfig, srcY, onImageLoad.bind(this, _ci2.ORIENTATIONS.Y));
1761
1333
  }
1762
1334
 
1763
1335
  this.attachEvents(draggable, swipeable, keys);
1764
-
1765
- if (onMouseLeave) this.setMouseLeaveActions(onMouseLeave);
1766
1336
  }
1767
1337
  }]);
1768
-
1769
1338
  return CI360Viewer;
1770
1339
  }();
1771
1340
 
1772
- exports.default = CI360Viewer;
1341
+ var _default = CI360Viewer;
1342
+ exports.default = _default;