js-cloudimage-360-view 2.7.1 → 2.7.2-beta.4

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,187 @@ 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
+ return;
714
647
  }
715
- }
716
- }, {
717
- key: 'requestNewImages',
718
- value: function requestNewImages(src, amount, orientation) {
719
- var _this = this;
720
648
 
721
- if (orientation === _ci2.ORIENTATIONS.Y) {
722
- this.resizedImagesY = [];
723
- this.loadedImagesY = 0;
724
- } else {
725
- this.resizedImagesX = [];
726
- this.loadedImagesX = 0;
649
+ if (this.containerWidth && this.containerHeight) {
650
+ this.container.style.width = containerWidth + 'px';
651
+ this.container.style.height = containerHeight / imageAspectRatio + 'px';
652
+ return;
727
653
  }
728
654
 
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);
655
+ if (!this.containerWidth && !this.containerHeight) {
656
+ this.container.style.height = containerHeight / imageAspectRatio + 'px';
657
+ return;
658
+ }
732
659
 
733
- _this.addUpdatedSizeImage(resultSrc, orientation, _this.lazyload, _this.lazySelector, index);
734
- });
660
+ if ((isProvidedHeightLessThanWidth || !this.containerWidth) && this.containerHeight) {
661
+ this.container.style.maxWidth = containerHeight * imageAspectRatio + 'px';
662
+ this.container.style.height = containerHeight + 'px';
663
+ } else {
664
+ this.container.style.maxWidth = containerWidth + 'px';
665
+ this.container.style.height = containerWidth / imageAspectRatio + 'px';
666
+ }
735
667
  }
736
668
  }, {
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
- }
669
+ key: "onResizedImageLoad",
670
+ value: function onResizedImageLoad(orientation, image, index) {
671
+ if (orientation === _ci2.ORIENTATIONS.Y) {
672
+ this.resizedImagesY[index] = image;
752
673
  } else {
753
- image.src = resultSrc;
674
+ this.resizedImagesX[index] = image;
754
675
  }
755
676
 
756
- image.onload = this.onLoadResizedImages.bind(this, orientation);
757
- image.onerror = this.onLoadResizedImages.bind(this, orientation);
677
+ var loadedResizedXImages = this.resizedImagesX.filter(function (image) {
678
+ return !!image;
679
+ });
680
+ var loadedResizedYImages = this.resizedImagesY.filter(function (image) {
681
+ return !!image;
682
+ });
683
+ var isAllImagesLoaded = loadedResizedXImages.length + loadedResizedYImages.length === this.amountX + this.amountY;
758
684
 
759
- if (orientation === _ci2.ORIENTATIONS.Y) {
760
- this.resizedImagesY.push(image);
761
- } else {
762
- this.resizedImagesX.push(image);
685
+ if (isAllImagesLoaded) {
686
+ this.imagesX = this.resizedImagesX;
687
+ this.imagesY = this.resizedImagesY;
688
+ this.update();
763
689
  }
764
690
  }
765
691
  }, {
766
- key: 'requestResizedImages',
692
+ key: "requestResizedImages",
767
693
  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);
694
+ var responsive = this.ciParams.ciToken;
695
+ var firstImage = this.imagesX[0];
696
+ this.updateContainerSize(firstImage);
697
+ this.update();
698
+ this.speedFactor = (0, _jsCloudimage360ViewUtils.getSpeedFactor)(this.dragSpeed, this.amountX, this.container.offsetWidth);
699
+ var srcX = (0, _jsCloudimage360ViewUtils.generateImagesPath)(this.srcXConfig);
700
+ if (!responsive || this.container.offsetWidth < firstImage.width * 1.5) return;
701
+ (0, _jsCloudimage360ViewUtils.preloadImages)(this.srcXConfig, srcX, this.onResizedImageLoad.bind(this, _ci2.ORIENTATIONS.X), true);
771
702
 
772
703
  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);
704
+ var srcY = (0, _jsCloudimage360ViewUtils.generateImagesPath)(this.srcYConfig);
705
+ (0, _jsCloudimage360ViewUtils.preloadImages)(this.srcYConfig, srcY, this.onResizedImageLoad.bind(this, _ci2.ORIENTATIONS.Y), true);
776
706
  }
777
707
  }
778
708
  }, {
779
- key: 'update',
709
+ key: "update",
780
710
  value: function update() {
781
711
  var image = this.imagesX[this.activeImageX - 1];
782
712
 
@@ -785,29 +715,22 @@ var CI360Viewer = function () {
785
715
  }
786
716
 
787
717
  var ctx = this.canvas.getContext("2d");
788
-
789
718
  ctx.scale(this.devicePixelRatio, this.devicePixelRatio);
719
+ this.canvas.width = this.container.offsetWidth * this.devicePixelRatio;
720
+ this.canvas.style.width = this.container.offsetWidth + 'px';
721
+ this.canvas.height = this.container.offsetHeight * this.devicePixelRatio;
722
+ this.canvas.style.height = this.container.offsetHeight + 'px';
790
723
 
791
724
  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,
725
+ var _contain = (0, _jsCloudimage360ViewUtils.contain)(this.canvas.width, this.canvas.height, image.width, image.height),
800
726
  width = _contain.width,
801
- height = _contain.height;
727
+ height = _contain.height,
728
+ offsetX = _contain.offsetX,
729
+ offsetY = _contain.offsetY;
802
730
 
803
731
  ctx.drawImage(image, offsetX, offsetY, width, height);
804
732
  } 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) {
733
+ if (this.mouseTracked) {
811
734
  this.updateImageScale(ctx);
812
735
  } else {
813
736
  ctx.drawImage(image, 0, 0, this.canvas.width, this.canvas.height);
@@ -815,7 +738,7 @@ var CI360Viewer = function () {
815
738
  }
816
739
  }
817
740
  }, {
818
- key: 'updateImageScale',
741
+ key: "updateImageScale",
819
742
  value: function updateImageScale(ctx) {
820
743
  var image = this.originalImagesX[this.activeImageX - 1];
821
744
 
@@ -823,23 +746,17 @@ var CI360Viewer = function () {
823
746
  image = this.originalImagesY[this.activeImageY - 1];
824
747
  }
825
748
 
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
-
749
+ var position = this.getCursorPositionInCanvas();
750
+ var imageWidth = this.canvas.width;
751
+ var imageHeight = this.canvas.height;
752
+ var width = this.canvas.width * this.zoomIntensity;
753
+ var height = this.canvas.height * this.zoomIntensity;
836
754
  var pointX = 0 - position.x / imageWidth * (width - this.canvas.width);
837
755
  var pointY = 0 - position.y / imageHeight * (height - this.canvas.height);
838
-
839
756
  ctx.drawImage(image, pointX, pointY, width, height);
840
757
  }
841
758
  }, {
842
- key: 'updatePercentageInLoader',
759
+ key: "updatePercentageInLoader",
843
760
  value: function updatePercentageInLoader(percentage) {
844
761
  if (this.loader) {
845
762
  this.loader.style.width = percentage + '%';
@@ -850,51 +767,10 @@ var CI360Viewer = function () {
850
767
  }
851
768
  }
852
769
  }, {
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
- }
770
+ key: "onFirstImageLoaded",
771
+ value: function onFirstImageLoaded(image) {
772
+ if (!this.hide360Logo && !this.lazyload) this.add360ViewIcon();
773
+ var ctx = this.canvas.getContext("2d");
898
774
 
899
775
  if (this.fullscreenView) {
900
776
  this.canvas.width = window.innerWidth * this.devicePixelRatio;
@@ -902,75 +778,35 @@ var CI360Viewer = function () {
902
778
  this.canvas.height = window.innerHeight * this.devicePixelRatio;
903
779
  this.canvas.style.height = window.innerHeight + 'px';
904
780
 
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),
781
+ var _contain2 = (0, _jsCloudimage360ViewUtils.contain)(this.canvas.width, this.canvas.height, image.width, image.height),
908
782
  offsetX = _contain2.offsetX,
909
783
  offsetY = _contain2.offsetY,
910
784
  width = _contain2.width,
911
785
  height = _contain2.height;
912
786
 
913
- this.offset = { x: offsetX, y: offsetY };
914
-
915
- ctx.drawImage(event.target, offsetX, offsetY, width, height);
787
+ this.offset = {
788
+ x: offsetX,
789
+ y: offsetY
790
+ };
791
+ ctx.drawImage(image, offsetX, offsetY, width, height);
916
792
  } 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';
793
+ this.canvas.width = this.container.offsetWidth * this.devicePixelRatio;
794
+ this.canvas.style.width = this.container.offsetWidth + 'px';
795
+ this.canvas.height = this.container.offsetHeight * this.devicePixelRatio;
796
+ this.canvas.style.height = this.container.offsetHeight + 'px';
797
+ ctx.drawImage(image, 0, 0, this.canvas.width, this.canvas.height);
962
798
  }
963
799
 
964
800
  if (this.fullscreenView) {
965
801
  this.addCloseFullscreenView();
966
802
  }
967
803
 
968
- if (this.magnifier && !this.fullscreenView || this.magnifyInFullscreen) {
804
+ if (this.magnifier) {
969
805
  this.addMagnifier();
970
806
  }
971
807
 
972
808
  if (this.boxShadow && !this.fullscreenView) {
973
- this.addBoxShadow();
809
+ (0, _jsCloudimage360ViewUtils.createBoxShadow)(this.boxShadow, this.innerBox);
974
810
  }
975
811
 
976
812
  if (this.bottomCircle && !this.fullscreenView) {
@@ -980,339 +816,98 @@ var CI360Viewer = function () {
980
816
  if (this.fullscreen && !this.fullscreenView) {
981
817
  this.addFullscreenIcon();
982
818
  }
983
-
984
- if (!this.isMobile && !this.fullscreenView && !this.disablePointerZoom) {
985
- this.addResetZoomIcon();
986
- }
987
819
  }
988
820
  }, {
989
- key: 'incrementLoadedImages',
990
- value: function incrementLoadedImages(orientation) {
991
- if (orientation === _ci2.ORIENTATIONS.Y) {
992
- this.loadedImagesY += 1;
821
+ key: "onAllImagesLoaded",
822
+ value: function onAllImagesLoaded() {
823
+ this.removeLoader();
824
+ this.imagesLoaded = true;
825
+
826
+ if (this.autoplay && this.pointerZoom) {
827
+ this.container.style.cursor = 'zoom-in';
993
828
  } else {
994
- this.loadedImagesX += 1;
829
+ this.container.style.cursor = 'grab';
995
830
  }
996
- }
997
- }, {
998
- key: 'onImageLoad',
999
- value: function onImageLoad(index, orientation, event) {
1000
- this.incrementLoadedImages(orientation);
1001
831
 
1002
- var totalAmount = this.amountX + this.amountY;
1003
- var totalLoadedImages = this.loadedImagesX + this.loadedImagesY;
1004
-
1005
- var percentage = Math.round(totalLoadedImages / totalAmount * 100);
832
+ this.speedFactor = (0, _jsCloudimage360ViewUtils.getSpeedFactor)(this.dragSpeed, this.amountX, this.container.offsetWidth);
1006
833
 
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);
834
+ if (this.autoplay) {
835
+ this.play();
1015
836
  }
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
837
 
1218
- resetZoomIcon.className = 'cloudimage-360-reset-zoom-icon';
1219
- this.resetZoomIcon = resetZoomIcon;
838
+ if (this.disableDrag) {
839
+ this.container.style.cursor = 'default';
840
+ }
1220
841
 
1221
- resetZoomIcon.onmouseenter = this.resetZoom.bind(this);
842
+ if (this.view360Icon) {
843
+ this.view360Icon.innerText = '';
844
+ (0, _ci.setView360Icon)(this.view360Icon, this.logoSrc);
845
+ }
1222
846
 
1223
- this.iconsContainer.appendChild(resetZoomIcon);
847
+ this.initControls();
1224
848
  }
1225
849
  }, {
1226
- key: 'hideResetZoomIcon',
1227
- value: function hideResetZoomIcon() {
1228
- if (!this.resetZoomIcon) return;
1229
- if (this.magnifierIcon) this.enableMagnifierIcon();
1230
- if (this.fullscreenIcon) this.showFullscreenIcon();
850
+ key: "magnify",
851
+ value: function magnify(event) {
852
+ var _this3 = this;
1231
853
 
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();
854
+ event.stopPropagation();
855
+ if (this.mouseTracked) this.togglePointerZoom();
856
+ var currentOriginalImage = (0, _jsCloudimage360ViewUtils.getCurrentOriginalImage)(this.movingDirection, this.imagesX, this.imagesY, this.activeImageX, this.activeImageY);
857
+ this.isMagnifyOpen = true;
1240
858
 
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';
859
+ currentOriginalImage.onload = function () {
860
+ if (_this3.glass) {
861
+ _this3.glass.style.cursor = 'none';
862
+ }
863
+ };
1248
864
 
1249
- this.loader = loader;
1250
- this.innerBox.appendChild(loader);
865
+ this.glass = document.createElement('div');
866
+ this.container.style.overflow = 'hidden';
867
+ (0, _jsCloudimage360ViewUtils.magnify)(this.container, this.offset, currentOriginalImage, this.glass, this.magnifier || 3);
1251
868
  }
1252
869
  }, {
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);
870
+ key: "closeMagnifier",
871
+ value: function closeMagnifier() {
872
+ if (!this.glass) return;
873
+ this.container.style.overflow = 'visible';
874
+ this.container.removeChild(this.glass);
875
+ this.glass = null;
876
+ this.isMagnifyOpen = false;
1261
877
  }
1262
878
  }, {
1263
- key: 'removeLoader',
1264
- value: function removeLoader() {
1265
- if (!this.loader) return;
1266
-
1267
- this.innerBox.removeChild(this.loader);
1268
- this.loader = null;
879
+ key: "openFullscreenModal",
880
+ value: function openFullscreenModal(event) {
881
+ event.stopPropagation();
882
+ if (this.mouseTracked) this.togglePointerZoom();
883
+ var fullscreenContainer = (0, _jsCloudimage360ViewUtils.createFullscreenModal)(this.container);
884
+ new CI360Viewer(fullscreenContainer, true);
1269
885
  }
1270
886
  }, {
1271
- key: 'remove360ViewIcon',
1272
- value: function remove360ViewIcon() {
1273
- if (!this.view360Icon) return;
887
+ key: "setFullscreenEvents",
888
+ value: function setFullscreenEvents(_, event) {
889
+ if (event.type === 'click') return this.closeFullscreenModal(event);
1274
890
 
1275
- this.innerBox.removeChild(this.view360Icon);
1276
- this.view360Icon = null;
891
+ if (event.key === 'Escape' && this.container.parentNode.parentNode === document.body) {
892
+ this.closeFullscreenModalOnEsc(event);
893
+ }
1277
894
  }
1278
895
  }, {
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
- }
896
+ key: "closeFullscreenModalOnEsc",
897
+ value: function closeFullscreenModalOnEsc(event) {
898
+ this.closeFullscreenModal(event);
1303
899
  }
1304
900
  }, {
1305
- key: 'play',
901
+ key: "play",
1306
902
  value: function play() {
1307
903
  var _this4 = this;
1308
904
 
1309
905
  if (this.bottomCircle) this.hide360ViewCircleIcon();
1310
906
  this.remove360ViewIcon();
1311
-
1312
907
  this.loopTimeoutId = window.setInterval(function () {
1313
908
  _this4.loop(_this4.reversed);
1314
909
 
1315
- var isPlayedOnce = _this4.isCompletedCyle();
910
+ var isPlayedOnce = (0, _jsCloudimage360ViewUtils.isCompletedOneCycle)(_this4.autoplayBehavior, _this4.activeImageX, _this4.activeImageY, _this4.amountX, _this4.amountY, _this4.reversed);
1316
911
 
1317
912
  if (_this4.playOnce && isPlayedOnce) {
1318
913
  window.clearTimeout(_this4.loopTimeoutId);
@@ -1325,119 +920,18 @@ var CI360Viewer = function () {
1325
920
  }, this.autoplaySpeed);
1326
921
  }
1327
922
  }, {
1328
- key: 'stop',
923
+ key: "stop",
1329
924
  value: function stop() {
1330
- if (this.bottomCircle && !this.zoomIntensity) this.show360ViewCircleIcon();
925
+ if (this.bottomCircle) this.show360ViewCircleIcon();
1331
926
  window.clearTimeout(this.loopTimeoutId);
1332
927
  }
1333
928
  }, {
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',
929
+ key: "destroy",
1434
930
  value: function destroy() {
1435
931
  stop();
1436
-
1437
932
  var oldElement = this.container;
1438
933
  var newElement = oldElement.cloneNode(true);
1439
934
  var innerBox = newElement.querySelector('.cloudimage-360-inner-box');
1440
-
1441
935
  newElement.className = newElement.className.replace(' initialized', '');
1442
936
  newElement.style.position = 'relative';
1443
937
  newElement.style.width = '100%';
@@ -1448,245 +942,241 @@ var CI360Viewer = function () {
1448
942
  oldElement.parentNode.replaceChild(newElement, oldElement);
1449
943
  }
1450
944
  }, {
1451
- key: 'initControls',
945
+ key: "addCloseFullscreenView",
946
+ value: function addCloseFullscreenView(event) {
947
+ var closeFullscreenIcon = (0, _jsCloudimage360ViewUtils.createCloseFullscreenIcon)();
948
+ closeFullscreenIcon.onclick = this.setFullscreenEvents.bind(this, event);
949
+ window.onkeyup = this.setFullscreenEvents.bind(this, event);
950
+ this.iconsContainer.appendChild(closeFullscreenIcon);
951
+ }
952
+ }, {
953
+ key: "add360ViewIcon",
954
+ value: function add360ViewIcon() {
955
+ this.view360Icon = (0, _jsCloudimage360ViewUtils.create360ViewIcon)();
956
+ this.innerBox.appendChild(this.view360Icon);
957
+ }
958
+ }, {
959
+ key: "addFullscreenIcon",
960
+ value: function addFullscreenIcon() {
961
+ this.fullscreenIcon = (0, _jsCloudimage360ViewUtils.createFullscreenIcon)();
962
+ this.fullscreenIcon.onclick = this.openFullscreenModal.bind(this);
963
+ this.iconsContainer.appendChild(this.fullscreenIcon);
964
+ }
965
+ }, {
966
+ key: "showFullscreenIcon",
967
+ value: function showFullscreenIcon() {
968
+ if (!this.fullscreenIcon) return;
969
+ this.fullscreenIcon.style.display = 'block';
970
+ this.fullscreenIcon.style.pointerEvents = 'auto';
971
+ }
972
+ }, {
973
+ key: "hideFullscreenIcon",
974
+ value: function hideFullscreenIcon() {
975
+ if (!this.fullscreenIcon) return;
976
+ this.fullscreenIcon.style.display = 'none';
977
+ this.fullscreenIcon.style.pointerEvents = 'none';
978
+ }
979
+ }, {
980
+ key: "addMagnifier",
981
+ value: function addMagnifier() {
982
+ this.magnifierIcon = (0, _jsCloudimage360ViewUtils.createMagnifierIcon)();
983
+ this.magnifierIcon.onclick = this.magnify.bind(this);
984
+ this.iconsContainer.appendChild(this.magnifierIcon);
985
+ }
986
+ }, {
987
+ key: "enableMagnifierIcon",
988
+ value: function enableMagnifierIcon() {
989
+ if (!this.magnifierIcon) return;
990
+ this.magnifierIcon.style.display = 'block';
991
+ this.magnifierIcon.style.pointerEvents = 'auto';
992
+ }
993
+ }, {
994
+ key: "disableMagnifierIcon",
995
+ value: function disableMagnifierIcon() {
996
+ if (!this.magnifierIcon) return;
997
+ this.magnifierIcon.style.display = 'none';
998
+ this.magnifierIcon.style.pointerEvents = 'none';
999
+ }
1000
+ }, {
1001
+ key: "closeFullscreenModal",
1002
+ value: function closeFullscreenModal(event) {
1003
+ event.stopPropagation();
1004
+ document.body.removeChild(this.container.parentNode);
1005
+ window.document.body.style.overflow = 'visible';
1006
+ }
1007
+ }, {
1008
+ key: "add360ViewCircleIcon",
1009
+ value: function add360ViewCircleIcon() {
1010
+ this.view360CircleIcon = (0, _jsCloudimage360ViewUtils.create360ViewCircleIcon)(this.bottomCircleOffset);
1011
+ this.innerBox.appendChild(this.view360CircleIcon);
1012
+ }
1013
+ }, {
1014
+ key: "show360ViewCircleIcon",
1015
+ value: function show360ViewCircleIcon() {
1016
+ if (!this.view360CircleIcon) return;
1017
+ this.view360CircleIcon.style.opacity = '1';
1018
+ }
1019
+ }, {
1020
+ key: "hide360ViewCircleIcon",
1021
+ value: function hide360ViewCircleIcon() {
1022
+ if (!this.view360CircleIcon) return;
1023
+ this.view360CircleIcon.style.opacity = '0';
1024
+ }
1025
+ }, {
1026
+ key: "remove360ViewCircleIcon",
1027
+ value: function remove360ViewCircleIcon() {
1028
+ if (!this.view360CircleIcon) return;
1029
+ this.innerBox.removeChild(this.view360CircleIcon);
1030
+ this.view360CircleIcon = null;
1031
+ }
1032
+ }, {
1033
+ key: "removeLoader",
1034
+ value: function removeLoader() {
1035
+ if (!this.loader) return;
1036
+ this.innerBox.removeChild(this.loader);
1037
+ this.loader = null;
1038
+ }
1039
+ }, {
1040
+ key: "remove360ViewIcon",
1041
+ value: function remove360ViewIcon() {
1042
+ if (!this.view360Icon) return;
1043
+ this.innerBox.removeChild(this.view360Icon);
1044
+ this.view360Icon = null;
1045
+ }
1046
+ }, {
1047
+ key: "initControls",
1452
1048
  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;
1049
+ var _this5 = this;
1464
1050
 
1465
1051
  var onLeftStart = function onLeftStart(event) {
1466
1052
  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
1053
 
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
- };
1054
+ _this5.onSpin();
1484
1055
 
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
- };
1056
+ _this5.left();
1491
1057
 
1492
- var onLeftEnd = function onLeftEnd() {
1493
- _this6.onFinishSpin();
1494
- window.clearTimeout(_this6.loopTimeoutId);
1058
+ _this5.loopTimeoutId = window.setInterval(_this5.left.bind(_this5), _this5.autoplaySpeed);
1495
1059
  };
1496
1060
 
1497
- var onRightEnd = function onRightEnd() {
1498
- _this6.onFinishSpin();
1499
- window.clearTimeout(_this6.loopTimeoutId);
1500
- };
1061
+ var onRightStart = function onRightStart(event) {
1062
+ event.stopPropagation();
1501
1063
 
1502
- var onTopEnd = function onTopEnd() {
1503
- _this6.onFinishSpin();
1504
- window.clearTimeout(_this6.loopTimeoutId);
1505
- };
1064
+ _this5.onSpin();
1506
1065
 
1507
- var onBottomEnd = function onBottomEnd() {
1508
- _this6.onFinishSpin();
1509
- window.clearTimeout(_this6.loopTimeoutId);
1510
- };
1066
+ _this5.right();
1511
1067
 
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);
1068
+ _this5.loopTimeoutId = window.setInterval(_this5.right.bind(_this5), _this5.autoplaySpeed);
1069
+ };
1518
1070
 
1519
- this.leftElem = left;
1520
- }
1071
+ var onTopStart = function onTopStart(event) {
1072
+ event.stopPropagation();
1521
1073
 
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);
1074
+ _this5.onSpin();
1528
1075
 
1529
- this.rightElem = right;
1530
- }
1076
+ _this5.top();
1531
1077
 
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);
1078
+ _this5.loopTimeoutId = window.setInterval(_this5.top.bind(_this5), _this5.autoplaySpeed);
1079
+ };
1538
1080
 
1539
- this.topElem = top;
1540
- }
1081
+ var onBottomStart = function onBottomStart(event) {
1082
+ event.stopPropagation();
1541
1083
 
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);
1084
+ _this5.onSpin();
1548
1085
 
1549
- this.bottomElem = bottom;
1550
- }
1086
+ _this5.bottom();
1551
1087
 
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';
1088
+ _this5.loopTimeoutId = window.setInterval(_this5.bottom.bind(_this5), _this5.autoplaySpeed);
1089
+ };
1570
1090
 
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';
1091
+ var onEventEnd = function onEventEnd() {
1092
+ _this5.onFinishSpin();
1579
1093
 
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
- }
1094
+ window.clearTimeout(_this5.loopTimeoutId);
1095
+ };
1584
1096
 
1585
- this.innerBox.appendChild(this.canvas);
1097
+ var controlsConfig = {
1098
+ container: this.container,
1099
+ controlReverse: this.controlReverse,
1100
+ spinReverse: this.spinReverse,
1101
+ stopAtEdges: this.stopAtEdges
1102
+ };
1103
+ var controlsTriggers = {
1104
+ onLeftStart: onLeftStart,
1105
+ onRightStart: onRightStart,
1106
+ onTopStart: onTopStart,
1107
+ onBottomStart: onBottomStart,
1108
+ onEventEnd: onEventEnd
1109
+ };
1110
+ var controlsElements = (0, _jsCloudimage360ViewUtils.initControls)(controlsConfig, controlsTriggers);
1111
+ this.topElem = controlsElements.top || {};
1112
+ this.bottomElem = controlsElements.bottom || {};
1113
+ this.leftElem = controlsElements.left || {};
1114
+ this.rightElem = controlsElements.right || {};
1586
1115
  }
1587
1116
  }, {
1588
- key: 'attachEvents',
1117
+ key: "attachEvents",
1589
1118
  value: function attachEvents(draggable, swipeable, keys) {
1590
- var _this7 = this;
1591
-
1592
- window.addEventListener('resize', (0, _ci.debounce)(function () {
1593
- _this7.requestResizedImages();
1594
- }, 300));
1119
+ window.addEventListener('resize', this.requestResizedImages.bind(this));
1595
1120
 
1596
1121
  if (draggable && !this.disableDrag) {
1122
+ this.container.addEventListener('click', this.mouseClick.bind(this));
1597
1123
  this.container.addEventListener('mousedown', this.mouseDown.bind(this));
1598
1124
  this.container.addEventListener('mousemove', this.mouseMove.bind(this));
1125
+ this.container.addEventListener('mouseleave', this.mouseLeave.bind(this));
1599
1126
  document.addEventListener('mouseup', this.mouseUp.bind(this));
1600
1127
  }
1601
1128
 
1602
1129
  if (swipeable && !this.disableDrag) {
1603
- this.container.addEventListener('touchstart', this.touchStart.bind(this), { passive: true });
1130
+ this.container.addEventListener('touchstart', this.touchStart.bind(this), {
1131
+ passive: true
1132
+ });
1604
1133
  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));
1134
+ this.container.addEventListener('touchmove', this.touchMove.bind(this), {
1135
+ passive: true
1136
+ });
1611
1137
  }
1612
1138
 
1613
1139
  if (keys) {
1614
1140
  document.addEventListener('keydown', this.keyDown.bind(this));
1615
1141
  document.addEventListener('keyup', this.keyUp.bind(this));
1616
- } else {
1617
- document.addEventListener('keydown', this.keyDownGeneral.bind(this));
1618
1142
  }
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
1143
 
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
- }
1144
+ document.addEventListener('keydown', this.keyDownGeneral.bind(this));
1648
1145
  }
1649
1146
  }, {
1650
- key: 'init',
1147
+ key: "init",
1651
1148
  value: function init(container) {
1149
+ var _this6 = this;
1150
+
1652
1151
  var _get360ViewProps = (0, _ci.get360ViewProps)(container),
1653
1152
  folder = _get360ViewProps.folder,
1153
+ apiVersion = _get360ViewProps.apiVersion,
1654
1154
  filenameX = _get360ViewProps.filenameX,
1655
1155
  filenameY = _get360ViewProps.filenameY,
1656
- imageList = _get360ViewProps.imageList,
1156
+ imageListX = _get360ViewProps.imageListX,
1157
+ imageListY = _get360ViewProps.imageListY,
1657
1158
  indexZeroBase = _get360ViewProps.indexZeroBase,
1658
1159
  amountX = _get360ViewProps.amountX,
1659
1160
  amountY = _get360ViewProps.amountY,
1660
1161
  imageOffset = _get360ViewProps.imageOffset,
1661
1162
  _get360ViewProps$drag = _get360ViewProps.draggable,
1662
- draggable = _get360ViewProps$drag === undefined ? true : _get360ViewProps$drag,
1163
+ draggable = _get360ViewProps$drag === void 0 ? true : _get360ViewProps$drag,
1663
1164
  _get360ViewProps$swip = _get360ViewProps.swipeable,
1664
- swipeable = _get360ViewProps$swip === undefined ? true : _get360ViewProps$swip,
1165
+ swipeable = _get360ViewProps$swip === void 0 ? true : _get360ViewProps$swip,
1665
1166
  keys = _get360ViewProps.keys,
1167
+ keysReverse = _get360ViewProps.keysReverse,
1666
1168
  bottomCircle = _get360ViewProps.bottomCircle,
1667
1169
  bottomCircleOffset = _get360ViewProps.bottomCircleOffset,
1668
1170
  boxShadow = _get360ViewProps.boxShadow,
1669
1171
  autoplay = _get360ViewProps.autoplay,
1670
1172
  autoplayBehavior = _get360ViewProps.autoplayBehavior,
1671
1173
  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
1174
  speed = _get360ViewProps.speed,
1682
1175
  autoplayReverse = _get360ViewProps.autoplayReverse,
1683
- _get360ViewProps$disa3 = _get360ViewProps.disableDrag,
1684
- disableDrag = _get360ViewProps$disa3 === undefined ? true : _get360ViewProps$disa3,
1176
+ _get360ViewProps$disa = _get360ViewProps.disableDrag,
1177
+ disableDrag = _get360ViewProps$disa === void 0 ? true : _get360ViewProps$disa,
1685
1178
  fullscreen = _get360ViewProps.fullscreen,
1686
1179
  magnifier = _get360ViewProps.magnifier,
1687
- magnifyInFullscreen = _get360ViewProps.magnifyInFullscreen,
1688
- ratio = _get360ViewProps.ratio,
1689
- responsive = _get360ViewProps.responsive,
1690
1180
  ciToken = _get360ViewProps.ciToken,
1691
1181
  ciFilters = _get360ViewProps.ciFilters,
1692
1182
  ciTransformation = _get360ViewProps.ciTransformation,
@@ -1697,24 +1187,28 @@ var CI360Viewer = function () {
1697
1187
  stopAtEdges = _get360ViewProps.stopAtEdges,
1698
1188
  controlReverse = _get360ViewProps.controlReverse,
1699
1189
  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
-
1190
+ logoSrc = _get360ViewProps.logoSrc,
1191
+ containerWidth = _get360ViewProps.containerWidth,
1192
+ containerHeight = _get360ViewProps.containerHeight,
1193
+ pointerZoom = _get360ViewProps.pointerZoom;
1194
+
1195
+ var ciParams = {
1196
+ ciToken: ciToken,
1197
+ ciFilters: ciFilters,
1198
+ ciTransformation: ciTransformation
1199
+ };
1708
1200
  this.folder = folder;
1201
+ this.apiVersion = apiVersion;
1709
1202
  this.filenameX = filenameX;
1710
1203
  this.filenameY = filenameY;
1711
- this.imageList = imageList;
1204
+ this.imageListX = imageListX;
1205
+ this.imageListY = imageListY;
1712
1206
  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;
1207
+ this.amountX = imageListX ? JSON.parse(imageListX).length : amountX;
1208
+ this.amountY = imageListY ? JSON.parse(imageListY).length : amountY;
1209
+ this.allowSpinY = !!this.amountY;
1210
+ this.activeImageX = autoplayReverse ? this.amountX : 1;
1211
+ this.activeImageY = autoplayReverse ? this.amountY : 1;
1718
1212
  this.spinY = autoplayBehavior === _ci2.AUTOPLAY_BEHAVIOR.SPIN_YX ? true : false;
1719
1213
  this.imageOffset = imageOffset;
1720
1214
  this.bottomCircle = bottomCircle;
@@ -1723,20 +1217,14 @@ var CI360Viewer = function () {
1723
1217
  this.autoplay = autoplay;
1724
1218
  this.autoplayBehavior = autoplayBehavior;
1725
1219
  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
1220
  this.speed = speed;
1732
1221
  this.reversed = autoplayReverse;
1733
1222
  this.disableDrag = disableDrag;
1734
1223
  this.fullscreen = fullscreen;
1735
1224
  this.magnifier = !this.isMobile && magnifier ? magnifier : false;
1736
- this.magnifyInFullscreen = magnifyInFullscreen;
1737
- this.lazyload = lazyload;
1225
+ this.lazyloadX = lazyload;
1226
+ this.lazyloadY = lazyload;
1738
1227
  this.lazySelector = lazySelector;
1739
- this.ratio = ratio;
1740
1228
  this.spinReverse = spinReverse;
1741
1229
  this.controlReverse = controlReverse;
1742
1230
  this.dragSpeed = dragSpeed;
@@ -1744,29 +1232,110 @@ var CI360Viewer = function () {
1744
1232
  this.stopAtEdges = stopAtEdges;
1745
1233
  this.hide360Logo = hide360Logo;
1746
1234
  this.logoSrc = logoSrc;
1747
- this.responsive = responsive;
1748
1235
  this.ciParams = ciParams;
1236
+ this.apiVersion = apiVersion;
1237
+ this.containerWidth = containerWidth;
1238
+ this.containerHeight = containerHeight;
1239
+ this.pointerZoom = pointerZoom;
1240
+ this.keysReverse = keysReverse;
1241
+ this.innerBox = (0, _jsCloudimage360ViewUtils.createInnerBox)(this.container);
1242
+ this.iconsContainer = (0, _jsCloudimage360ViewUtils.createIconsContainer)(this.innerBox);
1243
+ this.canvas = (0, _jsCloudimage360ViewUtils.createCanvas)(this.innerBox);
1244
+ this.loader = (0, _jsCloudimage360ViewUtils.createLoader)(this.innerBox);
1245
+ (0, _jsCloudimage360ViewUtils.applyStylesToContainer)(this.container);
1246
+ this.srcXConfig = {
1247
+ folder: folder,
1248
+ filename: filenameX,
1249
+ imageList: imageListX,
1250
+ container: container,
1251
+ innerBox: this.innerBox,
1252
+ apiVersion: apiVersion,
1253
+ ciParams: ciParams,
1254
+ lazyload: lazyload,
1255
+ lazySelector: lazySelector,
1256
+ amount: this.amountX,
1257
+ indexZeroBase: indexZeroBase,
1258
+ fullscreen: this.fullscreenView
1259
+ };
1260
+ this.srcYConfig = _objectSpread(_objectSpread({}, this.srcXConfig), {}, {
1261
+ filename: filenameY,
1262
+ orientation: _ci2.ORIENTATIONS.Y,
1263
+ imageList: imageListY,
1264
+ amount: this.amountY
1265
+ });
1266
+ var srcX = (0, _jsCloudimage360ViewUtils.generateImagesPath)(this.srcXConfig);
1267
+ var srcY = (0, _jsCloudimage360ViewUtils.generateImagesPath)(this.srcYConfig);
1268
+
1269
+ var initLazyload = function initLazyload(image, orientation) {
1270
+ var lazyloadXConfig = _objectSpread(_objectSpread({}, _this6.srcXConfig), {}, {
1271
+ lazyload: false
1272
+ });
1273
+
1274
+ var lazyloadYConfig = _objectSpread(_objectSpread({}, _this6.srcYConfig), {}, {
1275
+ lazyload: false
1276
+ });
1277
+
1278
+ if (orientation === _ci2.ORIENTATIONS.Y) {
1279
+ _this6.lazyloadY = false;
1280
+ (0, _jsCloudimage360ViewUtils.preloadImages)(lazyloadXConfig, srcX, onImageLoad.bind(_this6, _ci2.ORIENTATIONS.X));
1281
+ } else {
1282
+ _this6.lazyloadX = false;
1283
+ _this6.lazyloadInitImageX = image;
1284
+ (0, _jsCloudimage360ViewUtils.preloadImages)(lazyloadYConfig, srcY, onImageLoad.bind(_this6, _ci2.ORIENTATIONS.Y));
1285
+ }
1286
+ };
1287
+
1288
+ var onImageLoad = function onImageLoad(orientation, image, index) {
1289
+ if (orientation !== _ci2.ORIENTATIONS.Y) {
1290
+ _this6.imagesX[index] = image;
1291
+ } else {
1292
+ _this6.imagesY[index] = image;
1293
+ }
1294
+
1295
+ var loadedXImages = _this6.imagesX.filter(function (image) {
1296
+ return !!image;
1297
+ });
1298
+
1299
+ var loadedYImages = _this6.imagesY.filter(function (image) {
1300
+ return !!image;
1301
+ });
1302
+
1303
+ var totalAmount = _this6.amountX + _this6.amountY;
1304
+ var totalLoadedImages = _this6.imagesX.length + _this6.imagesY.length;
1305
+ var isFirstImageLoaded = index === 0 && orientation !== _ci2.ORIENTATIONS.Y;
1306
+ var isAllImagesLoaded = loadedXImages.length + loadedYImages.length === _this6.amountX + _this6.amountY;
1307
+ var percentage = Math.round(totalLoadedImages / totalAmount * 100);
1308
+
1309
+ _this6.updatePercentageInLoader(percentage);
1310
+
1311
+ if (_this6.lazyloadX || _this6.lazyloadY) return initLazyload(image, orientation);
1749
1312
 
1750
- this.applyStylesToContainer();
1313
+ if (isFirstImageLoaded) {
1314
+ _this6.updateContainerSize(image);
1751
1315
 
1752
- this.addCanvas();
1316
+ _this6.onFirstImageLoaded(image);
1317
+ }
1318
+
1319
+ if (isAllImagesLoaded) {
1320
+ _this6.onAllImagesLoaded();
1753
1321
 
1754
- var srcX = this.getSrc(responsive, container, folder, filenameX, ciParams);
1755
- var srcY = this.getSrc(responsive, container, folder, filenameY, ciParams);
1322
+ if (lazyload) {
1323
+ _this6.innerBox.removeChild(_this6.lazyloadInitImageX);
1324
+ }
1325
+ }
1326
+ };
1756
1327
 
1757
- this.preloadImages(amountX, srcX, _ci2.ORIENTATIONS.X, lazyload, lazySelector, container, responsive, ciParams);
1328
+ (0, _jsCloudimage360ViewUtils.preloadImages)(this.srcXConfig, srcX, onImageLoad.bind(this, _ci2.ORIENTATIONS.X));
1758
1329
 
1759
- if (amountY) {
1760
- this.preloadImages(amountY, srcY, _ci2.ORIENTATIONS.Y, lazyload, lazySelector, container, responsive, ciParams);
1330
+ if (this.allowSpinY) {
1331
+ (0, _jsCloudimage360ViewUtils.preloadImages)(this.srcYConfig, srcY, onImageLoad.bind(this, _ci2.ORIENTATIONS.Y));
1761
1332
  }
1762
1333
 
1763
1334
  this.attachEvents(draggable, swipeable, keys);
1764
-
1765
- if (onMouseLeave) this.setMouseLeaveActions(onMouseLeave);
1766
1335
  }
1767
1336
  }]);
1768
-
1769
1337
  return CI360Viewer;
1770
1338
  }();
1771
1339
 
1772
- exports.default = CI360Viewer;
1340
+ var _default = CI360Viewer;
1341
+ exports.default = _default;