js-cloudimage-360-view 2.7.8 → 2.7.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -25,6 +25,10 @@ Types of changes:
25
25
  - ...
26
26
 
27
27
  -------------
28
+ ## 2.7.9 - 2022-02-27
29
+ ### Fixed
30
+ - typo in documentation
31
+
28
32
  ## 2.7.8 - 2022-02-27
29
33
  ### Added
30
34
  - possibility to add new view to CI360 views
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- [![Release](https://img.shields.io/badge/release-v2.7.8-blue.svg)](https://github.com/scaleflex/js-cloudimage-360-view/releases)
1
+ [![Release](https://img.shields.io/badge/release-v2.7.9-blue.svg)](https://github.com/scaleflex/js-cloudimage-360-view/releases)
2
2
  [![Contributions welcome](https://img.shields.io/badge/contributions-welcome-orange.svg)](#contributing)
3
3
  [![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)
4
4
  [![Scaleflex team](https://img.shields.io/badge/%3C%2F%3E%20with%20%E2%99%A5%20by-the%20Scaleflex%20team-6986fa.svg)](https://www.scaleflex.it/en/home)
@@ -795,13 +795,9 @@ var CI360Viewer = /*#__PURE__*/function () {
795
795
  value: function onFirstImageLoaded(image) {
796
796
  if (!this.hide360Logo && !this.lazyload) this.add360ViewIcon();
797
797
  var ctx = this.canvas.getContext("2d");
798
+ this.updateContainerAndCanvasSize(image);
798
799
 
799
800
  if (this.fullscreenView) {
800
- this.canvas.width = window.innerWidth * this.devicePixelRatio;
801
- this.canvas.style.width = window.innerWidth + 'px';
802
- this.canvas.height = window.innerHeight * this.devicePixelRatio;
803
- this.canvas.style.height = window.innerHeight + 'px';
804
-
805
801
  var _contain2 = (0, _utils.contain)(this.canvas.width, this.canvas.height, image.width, image.height),
806
802
  offsetX = _contain2.offsetX,
807
803
  offsetY = _contain2.offsetY,
@@ -815,10 +811,6 @@ var CI360Viewer = /*#__PURE__*/function () {
815
811
  this.addCloseFullscreenView();
816
812
  ctx.drawImage(image, offsetX, offsetY, width, height);
817
813
  } else {
818
- this.canvas.width = this.container.offsetWidth * this.devicePixelRatio;
819
- this.canvas.style.width = this.container.offsetWidth + 'px';
820
- this.canvas.height = this.container.offsetHeight * this.devicePixelRatio;
821
- this.canvas.style.height = this.container.offsetHeight + 'px';
822
814
  ctx.drawImage(image, 0, 0, this.canvas.width, this.canvas.height);
823
815
  }
824
816
 
@@ -956,19 +948,33 @@ var CI360Viewer = /*#__PURE__*/function () {
956
948
  window.clearTimeout(this.loopTimeoutId);
957
949
  }
958
950
  }, {
959
- key: "updatePlugin",
960
- value: function updatePlugin(forceUpdate) {
951
+ key: "updateView",
952
+ value: function updateView(forceUpdate, viewers) {
953
+ var _this5 = this;
954
+
961
955
  var container = this.container;
962
956
  var imageProps = (0, _ci.get360ViewProps)(container);
963
- var srcPropsChanged = (0, _utils.isSrcPropsChanged)(this, imageProps);
964
- var reloadPlugin = srcPropsChanged || forceUpdate;
957
+ var srcPropsChanged = (0, _utils.isPropsChangeRequireReload)(this, imageProps);
958
+ var reInitView = srcPropsChanged || forceUpdate;
959
+
960
+ if (reInitView) {
961
+ var oldElement = this.container;
962
+ var viewIndex = viewers.findIndex(function (view) {
963
+ return view.id === _this5.container.id;
964
+ });
965
+ container = container.cloneNode(true);
966
+ container.className = container.className.replace(' initialized', '');
967
+ container.innerHTML = '';
968
+ oldElement.parentNode.replaceChild(container, oldElement);
969
+ return viewers.splice(viewIndex, 1, new CI360Viewer(container));
970
+ }
971
+
965
972
  container.style.position = 'relative';
966
973
  container.style.width = '100%';
967
974
  container.style.cursor = 'default';
968
975
  container.setAttribute('draggable', 'false');
969
- if (reloadPlugin) container.innerHTML = '';
970
976
  this.stop();
971
- this.init(container, !reloadPlugin, reloadPlugin);
977
+ this.init(container, true);
972
978
  }
973
979
  }, {
974
980
  key: "destroy",
@@ -1091,52 +1097,52 @@ var CI360Viewer = /*#__PURE__*/function () {
1091
1097
  }, {
1092
1098
  key: "initControls",
1093
1099
  value: function initControls() {
1094
- var _this5 = this;
1100
+ var _this6 = this;
1095
1101
 
1096
1102
  var onLeftStart = function onLeftStart(event) {
1097
1103
  event.stopPropagation();
1098
1104
 
1099
- _this5.onSpin();
1105
+ _this6.onSpin();
1100
1106
 
1101
- _this5.left();
1107
+ _this6.left();
1102
1108
 
1103
- _this5.loopTimeoutId = window.setInterval(_this5.left.bind(_this5), _this5.autoplaySpeed);
1109
+ _this6.loopTimeoutId = window.setInterval(_this6.left.bind(_this6), _this6.autoplaySpeed);
1104
1110
  };
1105
1111
 
1106
1112
  var onRightStart = function onRightStart(event) {
1107
1113
  event.stopPropagation();
1108
1114
 
1109
- _this5.onSpin();
1115
+ _this6.onSpin();
1110
1116
 
1111
- _this5.right();
1117
+ _this6.right();
1112
1118
 
1113
- _this5.loopTimeoutId = window.setInterval(_this5.right.bind(_this5), _this5.autoplaySpeed);
1119
+ _this6.loopTimeoutId = window.setInterval(_this6.right.bind(_this6), _this6.autoplaySpeed);
1114
1120
  };
1115
1121
 
1116
1122
  var onTopStart = function onTopStart(event) {
1117
1123
  event.stopPropagation();
1118
1124
 
1119
- _this5.onSpin();
1125
+ _this6.onSpin();
1120
1126
 
1121
- _this5.top();
1127
+ _this6.top();
1122
1128
 
1123
- _this5.loopTimeoutId = window.setInterval(_this5.top.bind(_this5), _this5.autoplaySpeed);
1129
+ _this6.loopTimeoutId = window.setInterval(_this6.top.bind(_this6), _this6.autoplaySpeed);
1124
1130
  };
1125
1131
 
1126
1132
  var onBottomStart = function onBottomStart(event) {
1127
1133
  event.stopPropagation();
1128
1134
 
1129
- _this5.onSpin();
1135
+ _this6.onSpin();
1130
1136
 
1131
- _this5.bottom();
1137
+ _this6.bottom();
1132
1138
 
1133
- _this5.loopTimeoutId = window.setInterval(_this5.bottom.bind(_this5), _this5.autoplaySpeed);
1139
+ _this6.loopTimeoutId = window.setInterval(_this6.bottom.bind(_this6), _this6.autoplaySpeed);
1134
1140
  };
1135
1141
 
1136
1142
  var onEventEnd = function onEventEnd() {
1137
- _this5.onFinishSpin();
1143
+ _this6.onFinishSpin();
1138
1144
 
1139
- window.clearTimeout(_this5.loopTimeoutId);
1145
+ window.clearTimeout(_this6.loopTimeoutId);
1140
1146
  };
1141
1147
 
1142
1148
  var controlsConfig = {
@@ -1189,10 +1195,9 @@ var CI360Viewer = /*#__PURE__*/function () {
1189
1195
  }, {
1190
1196
  key: "init",
1191
1197
  value: function init(container) {
1192
- var _this6 = this;
1198
+ var _this7 = this;
1193
1199
 
1194
1200
  var update = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1195
- var reload = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
1196
1201
 
1197
1202
  var _get360ViewProps = (0, _ci.get360ViewProps)(container),
1198
1203
  folder = _get360ViewProps.folder,
@@ -1282,13 +1287,9 @@ var CI360Viewer = /*#__PURE__*/function () {
1282
1287
  this.pointerZoom = pointerZoom > 1 ? Math.min(pointerZoom, 3) : 0;
1283
1288
  this.keysReverse = keysReverse;
1284
1289
  this.info = imageInfo;
1290
+ this.keys = keys;
1285
1291
  this.ratio = ratio && JSON.parse(ratio);
1286
1292
 
1287
- if (reload) {
1288
- new CI360Viewer(this.container);
1289
- return;
1290
- }
1291
-
1292
1293
  if (update) {
1293
1294
  (0, _utils.removeChildFromParent)(this.innerBox, this.iconsContainer);
1294
1295
  (0, _utils.removeChildFromParent)(this.innerBox, this.boxShadowEl);
@@ -1321,8 +1322,7 @@ var CI360Viewer = /*#__PURE__*/function () {
1321
1322
  this.boxShadowEl = (0, _utils.createBoxShadow)(this.boxShadow, this.innerBox);
1322
1323
  }
1323
1324
 
1324
- this.onAllImagesLoaded();
1325
- return;
1325
+ return this.onAllImagesLoaded();
1326
1326
  }
1327
1327
 
1328
1328
  this.innerBox = (0, _utils.createInnerBox)(this.container);
@@ -1359,60 +1359,58 @@ var CI360Viewer = /*#__PURE__*/function () {
1359
1359
  var srcY = (0, _utils.generateImagesPath)(this.srcYConfig);
1360
1360
 
1361
1361
  var initLazyload = function initLazyload(image, orientation) {
1362
- var lazyloadXConfig = _objectSpread(_objectSpread({}, _this6.srcXConfig), {}, {
1362
+ var lazyloadXConfig = _objectSpread(_objectSpread({}, _this7.srcXConfig), {}, {
1363
1363
  lazyload: false
1364
1364
  });
1365
1365
 
1366
- var lazyloadYConfig = _objectSpread(_objectSpread({}, _this6.srcYConfig), {}, {
1366
+ var lazyloadYConfig = _objectSpread(_objectSpread({}, _this7.srcYConfig), {}, {
1367
1367
  lazyload: false
1368
1368
  });
1369
1369
 
1370
1370
  if (orientation === _constants.ORIENTATIONS.Y) {
1371
- _this6.lazyloadY = false;
1372
- (0, _utils.preloadImages)(lazyloadXConfig, srcX, onImageLoad.bind(_this6, _constants.ORIENTATIONS.X));
1371
+ _this7.lazyloadY = false;
1372
+ (0, _utils.preloadImages)(lazyloadXConfig, srcX, onImageLoad.bind(_this7, _constants.ORIENTATIONS.X));
1373
1373
  } else {
1374
- _this6.lazyloadX = false;
1375
- _this6.lazyloadInitImageX = image;
1376
- (0, _utils.preloadImages)(lazyloadYConfig, srcY, onImageLoad.bind(_this6, _constants.ORIENTATIONS.Y));
1374
+ _this7.lazyloadX = false;
1375
+ _this7.lazyloadInitImageX = image;
1376
+ (0, _utils.preloadImages)(lazyloadYConfig, srcY, onImageLoad.bind(_this7, _constants.ORIENTATIONS.Y));
1377
1377
  }
1378
1378
  };
1379
1379
 
1380
1380
  var onImageLoad = function onImageLoad(orientation, image, index) {
1381
1381
  if (orientation !== _constants.ORIENTATIONS.Y) {
1382
- _this6.imagesX[index] = image;
1382
+ _this7.imagesX[index] = image;
1383
1383
  } else {
1384
- _this6.imagesY[index] = image;
1384
+ _this7.imagesY[index] = image;
1385
1385
  }
1386
1386
 
1387
- var loadedXImages = _this6.imagesX.filter(function (image) {
1387
+ var loadedXImages = _this7.imagesX.filter(function (image) {
1388
1388
  return !!image;
1389
1389
  });
1390
1390
 
1391
- var loadedYImages = _this6.imagesY.filter(function (image) {
1391
+ var loadedYImages = _this7.imagesY.filter(function (image) {
1392
1392
  return !!image;
1393
1393
  });
1394
1394
 
1395
- var totalAmount = _this6.amountX + _this6.amountY;
1396
- var totalLoadedImages = _this6.imagesX.length + _this6.imagesY.length;
1395
+ var totalAmount = _this7.amountX + _this7.amountY;
1396
+ var totalLoadedImages = _this7.imagesX.length + _this7.imagesY.length;
1397
1397
  var isFirstImageLoaded = index === 0 && orientation !== _constants.ORIENTATIONS.Y;
1398
- var isAllImagesLoaded = loadedXImages.length + loadedYImages.length === _this6.amountX + _this6.amountY;
1398
+ var isAllImagesLoaded = loadedXImages.length + loadedYImages.length === _this7.amountX + _this7.amountY;
1399
1399
  var percentage = Math.round(totalLoadedImages / totalAmount * 100);
1400
1400
 
1401
- _this6.updatePercentageInLoader(percentage);
1401
+ _this7.updatePercentageInLoader(percentage);
1402
1402
 
1403
- if (_this6.lazyloadX || _this6.lazyloadY) return initLazyload(image, orientation);
1403
+ if (_this7.lazyloadX || _this7.lazyloadY) return initLazyload(image, orientation);
1404
1404
 
1405
1405
  if (isFirstImageLoaded) {
1406
- _this6.updateContainerAndCanvasSize(image);
1407
-
1408
- _this6.onFirstImageLoaded(image);
1406
+ _this7.onFirstImageLoaded(image);
1409
1407
  }
1410
1408
 
1411
1409
  if (isAllImagesLoaded) {
1412
- _this6.onAllImagesLoaded();
1410
+ _this7.onAllImagesLoaded();
1413
1411
 
1414
1412
  if (lazyload) {
1415
- _this6.innerBox.removeChild(_this6.lazyloadInitImageX);
1413
+ _this7.innerBox.removeChild(_this7.lazyloadInitImageX);
1416
1414
  }
1417
1415
  }
1418
1416
  };
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.PROPS_REQUIRE_RELOAD = void 0;
7
+ var PROPS_REQUIRE_RELOAD = ['folder', //images source
8
+ 'filenameX', //images source
9
+ 'filenameY', //images source
10
+ 'apiVersion', //images source
11
+ 'imageListX', //images source
12
+ 'imageListY', //images source
13
+ 'indexZeroBase', //images source
14
+ 'lazySelector', //images source
15
+ 'keys', // events
16
+ 'stopAtEdges', // events
17
+ 'disableDrag', // events
18
+ 'controlReverse', // events
19
+ 'disableDrag' // events
20
+ ];
21
+ exports.PROPS_REQUIRE_RELOAD = PROPS_REQUIRE_RELOAD;
package/dist/index.js CHANGED
@@ -12,14 +12,27 @@ var _ci = _interopRequireDefault(require("./ci360.service"));
12
12
 
13
13
  var _ci2 = require("./ci360.utils");
14
14
 
15
+ function setContainerId(container) {
16
+ var containerId = container.id;
17
+
18
+ if (!containerId) {
19
+ var uniqueId = Math.floor(Math.random() * 10000);
20
+ var generatedContainerId = "cloudimage-360-view-".concat(uniqueId);
21
+ container.id = generatedContainerId;
22
+ }
23
+
24
+ return container;
25
+ }
26
+
15
27
  function init() {
16
28
  var viewers = [];
17
29
  var view360Array = document.querySelectorAll('.cloudimage-360:not(.initialized)');
18
30
  var hotspotsConfigs = window.CI360.hotspots || {};
19
31
  [].slice.call(view360Array).forEach(function (container) {
20
- var hotspotInstanceName = (0, _ci2.attr)(container, 'hotspot-instance') || (0, _ci2.attr)(container, 'data-hotspot-instance');
21
- var hotspotConfig = hotspotsConfigs[hotspotInstanceName] ? hotspotsConfigs[hotspotInstanceName] : null;
22
- viewers.push(new _ci.default(container, false, hotspotConfig));
32
+ var containerWithId = setContainerId(container);
33
+ var hotspotInstanceName = (0, _ci2.attr)(containerWithId, 'hotspot-instance') || (0, _ci2.attr)(containerWithId, 'data-hotspot-instance');
34
+ var hotspotConfig = hotspotsConfigs === null || hotspotsConfigs === void 0 ? void 0 : hotspotsConfigs[hotspotInstanceName];
35
+ viewers.push(new _ci.default(containerWithId, false, hotspotConfig));
23
36
  });
24
37
  window.CI360._viewers = viewers;
25
38
  }
@@ -48,6 +61,17 @@ function getActiveIndexByID(id, oriantation) {
48
61
  return currentViewer && currentViewer.activeImageX - 1;
49
62
  }
50
63
 
64
+ function addView(id) {
65
+ var view360Array = Array.from(document.querySelectorAll('.cloudimage-360:not(.initialized)'));
66
+
67
+ if (view360Array.length && id) {
68
+ var newViewContainer = view360Array.filter(function (viewer) {
69
+ return viewer.id === id;
70
+ })[0];
71
+ newViewContainer && window.CI360._viewers.push(new _ci.default(newViewContainer));
72
+ }
73
+ }
74
+
51
75
  function update() {
52
76
  var id = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
53
77
  var forceUpdate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
@@ -58,15 +82,15 @@ function update() {
58
82
  return viewer.id === id;
59
83
  })[0];
60
84
 
61
- return view.updatePlugin(forceUpdate);
85
+ view.updateView(forceUpdate, window.CI360._viewers);
62
86
  } catch (_unused) {
63
- console.error("Cloudimage-360: there is no view with such id '".concat(id, "'"));
87
+ console.warn("Cloudimage-360: there is no view with such id '".concat(id, "', you may need to run window.addView('").concat(id, "') before run update'"));
64
88
  }
89
+ } else {
90
+ window.CI360._viewers.forEach(function (viewer) {
91
+ viewer.updateView(forceUpdate, window.CI360._viewers);
92
+ });
65
93
  }
66
-
67
- return window.CI360._viewers.forEach(function (viewer) {
68
- viewer.updatePlugin(forceUpdate);
69
- });
70
94
  }
71
95
 
72
96
  function isNoViewers() {
@@ -78,6 +102,7 @@ window.CI360.init = init;
78
102
  window.CI360.destroy = destroy;
79
103
  window.CI360.getActiveIndexByID = getActiveIndexByID;
80
104
  window.CI360.update = update;
105
+ window.CI360.addView = addView;
81
106
 
82
107
  if (!window.CI360.notInitOnLoad) {
83
108
  init();
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isPropsChangeRequireReload = void 0;
7
+
8
+ var _propsRequireReload = require("../../constants/props-require-reload");
9
+
10
+ var isPropsChangeRequireReload = function isPropsChangeRequireReload(currentProps, changedProps) {
11
+ return Object.keys(changedProps).reduce(function (acc, current) {
12
+ var isPropChanged = currentProps[current] !== changedProps[current];
13
+ var isSrcProp = _propsRequireReload.PROPS_REQUIRE_RELOAD.indexOf(current) !== -1;
14
+
15
+ if (isSrcProp && isPropChanged) {
16
+ acc = true;
17
+ }
18
+
19
+ return acc;
20
+ }, false);
21
+ };
22
+
23
+ exports.isPropsChangeRequireReload = isPropsChangeRequireReload;
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  var _exportNames = {
7
- isSrcPropsChanged: true,
7
+ isPropsChangeRequireReload: true,
8
8
  generateImagesPath: true,
9
9
  preloadImages: true,
10
10
  preloadOriginalImages: true,
@@ -124,10 +124,10 @@ Object.defineProperty(exports, "isMouseOnHotspot", {
124
124
  return _isMouseOnHotspot.isMouseOnHotspot;
125
125
  }
126
126
  });
127
- Object.defineProperty(exports, "isSrcPropsChanged", {
127
+ Object.defineProperty(exports, "isPropsChangeRequireReload", {
128
128
  enumerable: true,
129
129
  get: function get() {
130
- return _isSrcPropsChanged.isSrcPropsChanged;
130
+ return _isPropsChangeRequireReload.isPropsChangeRequireReload;
131
131
  }
132
132
  });
133
133
  Object.defineProperty(exports, "loop", {
@@ -167,7 +167,7 @@ Object.defineProperty(exports, "updateHotspots", {
167
167
  }
168
168
  });
169
169
 
170
- var _isSrcPropsChanged = require("./image-src/is-src-props-changed");
170
+ var _isPropsChangeRequireReload = require("./image-src/is-props-change-require-reload");
171
171
 
172
172
  var _generateImagesPath = require("./image-src/generate-images-path");
173
173
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js-cloudimage-360-view",
3
- "version": "2.7.8",
3
+ "version": "2.7.9",
4
4
  "main": "dist/index.js",
5
5
  "description": "",
6
6
  "author": "scaleflex",
@@ -1,8 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.IMAGE_SRC_PROPS = void 0;
7
- var IMAGE_SRC_PROPS = ['folder', 'filenameX', 'filenameY', 'apiVersion', 'imageListX', 'imageListY', 'indexZeroBase', 'amountX', 'amountY', 'lazySelector'];
8
- exports.IMAGE_SRC_PROPS = IMAGE_SRC_PROPS;
@@ -1,23 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.isSrcPropsChanged = void 0;
7
-
8
- var _imageSrcProps = require("../../constants/image-src-props");
9
-
10
- var isSrcPropsChanged = function isSrcPropsChanged(currentProps, changedProps) {
11
- return Object.keys(changedProps).reduce(function (acc, current) {
12
- var isPropChanged = currentProps[current] !== changedProps[current];
13
- var isSrcProp = _imageSrcProps.IMAGE_SRC_PROPS.indexOf(current) !== -1;
14
-
15
- if (isSrcProp && isPropChanged) {
16
- acc = true;
17
- }
18
-
19
- return acc;
20
- }, false);
21
- };
22
-
23
- exports.isSrcPropsChanged = isSrcPropsChanged;