Skip to content

Commit e182633

Browse files
author
Amr Wagdy
committed
chore: build v2.7.6
1 parent 6c8c091 commit e182633

11 files changed

+105
-91
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ Types of changes:
2525
- ...
2626

2727
-------------
28+
## 2.7.6 - 2022-02-20
29+
### Fixed
30+
- drag speed
31+
- responsive canvas width and height
32+
2833
## 2.7.5 - 2022-02-08
2934
### Added
3035
- update method to re-render or re-init the plugin

README.md

+38-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[![Release](https://img.shields.io/badge/release-v2.7.5-blue.svg)](https://github.com/scaleflex/js-cloudimage-360-view/releases)
1+
[![Release](https://img.shields.io/badge/release-v2.7.6-blue.svg)](https://github.com/scaleflex/js-cloudimage-360-view/releases)
22
[![Contributions welcome](https://img.shields.io/badge/contributions-welcome-orange.svg)](#contributing)
33
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)
44
[![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)
@@ -308,25 +308,49 @@ Open 360 spin view in full screen modal.
308308

309309
Magnifier to zoom image.
310310

311-
### ~~data-ratio (or ratio)~~ [deprecated]
311+
### data-ratio (or ratio)
312312

313313

314-
###### ~~Type: **Number** (height / width) | Default: **none** | _optional_~~
314+
###### Type: **Number** (width / height) or JSON object | Default: **none** | _optional_
315+
#### `ratio`: string
315316

316-
~~Prevents page from jumping.~~
317-
### data-width (or width)
317+
Setting the height relative to the container width according to the provided ratio</br>
318+
In the following example, the height should be 0.3 the container width
318319

319-
###### Type: **Number** | Default: **none** | _optional_
320-
321-
Set a responsive width for the container.
322-
It will maintain the aspect ratio in respect to width
323-
### data-height (or height)
324-
325-
###### Type: **Number** | Default: **none** | _optional_
320+
```html
321+
<div
322+
id="cloudimage-360-car"
323+
class="cloudimage-360"
324+
data-folder="https://scaleflex.airstore.io/demo/360-car/"
325+
data-filename-x="iris-{index}.jpeg"
326+
data-amount-x="36"
327+
data-ratio="2"
328+
></div>
329+
```
330+
<a href="https://codesandbox.io/s/js-cloudimage-360-view-g4wyt1?file=/index.html"><img src="https://codesandbox.io/static/img/play-codesandbox.svg" alt="edit in codesandbox"/></a>
331+
#### `ratio`: JSON
332+
Setting the height relative to the container width at any window size.
326333

327-
Set a responsive height for the container.
328-
It will maintain the aspect ratio in respect to height
334+
In the following example, the height should be 1.3 the container width at window size less than or equal to 567px
335+
and 2.22 at window size less than or equal to 768px.
329336

337+
```html
338+
<div
339+
id="cloudimage-360-car"
340+
class="cloudimage-360"
341+
data-folder="https://scaleflex.airstore.io/demo/360-car/"
342+
data-filename-x="iris-{index}.jpeg"
343+
data-amount-x="36"
344+
data-ratio='{
345+
"576": "1.3",
346+
"768": "2.22",
347+
"992": "2.23",
348+
"1200": "3",
349+
"2400": "3.2"
350+
}'
351+
></div>
352+
```
353+
<a href="https://codesandbox.io/s/js-cloudimage-360-view-5tssb7?file=/index.html"><img src="https://codesandbox.io/static/img/play-codesandbox.svg" alt="edit in codesandbox"/></a>
330354
### data-autoplay-reverse (or autoplay-reverse)
331355

332356
###### Type: **Bool** | Default: **false** | _optional_

build/js-cloudimage-360-view.min.js

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/src/index.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ <h2>Engage your customers with a stunning <strong>360 view of your products</str
158158
data-autoplay
159159
data-magnifier="3"
160160
data-box-shadow="inset 0 0 100px #222"
161-
data-ratio="0.365"
161+
data-ratio="1.7"
162162
data-responsive="scaleflex"
163163
data-spin-reverse
164164
data-pointer-zoom="3"
@@ -489,7 +489,7 @@ <h2 class="text-center">Ready to get started?</h2>
489489
<p>Include the following script into your project after all content in body tag</p>
490490
<figure class="highlight">
491491
<pre><code class="javascript">
492-
&lt;script src="https://cdn.scaleflex.it/plugins/js-cloudimage-360-view/2.7.5/js-cloudimage-360-view.min.js"&gt;&lt;/script&gt;
492+
&lt;script src="https://cdn.scaleflex.it/plugins/js-cloudimage-360-view/2.7.6/js-cloudimage-360-view.min.js"&gt;&lt;/script&gt;
493493
</code></pre>
494494
</figure>
495495
</div>

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "js-cloudimage-360-view",
3-
"version": "2.7.5",
3+
"version": "2.7.6",
44
"main": "dist/index.js",
55
"description": "",
66
"author": "scaleflex",

src/ci360.service.js

+12-39
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ import {
2727
createBoxShadow,
2828
getSpeedFactor,
2929
isCompletedOneCycle,
30-
getContainerResponsiveWidth,
31-
getContainerResponsiveHeight,
3230
getMovingDirection,
3331
applyStylesToContainer,
3432
initControls,
@@ -39,6 +37,7 @@ import {
3937
generateZoomInSteps,
4038
generateZoomOutSteps,
4139
isSrcPropsChanged,
40+
getImageAspectRatio,
4241
} from './utils';
4342

4443
class CI360Viewer {
@@ -648,12 +647,8 @@ import {
648647
loop(this.autoplayBehavior, this.spinY, reversed, loopTriggers);
649648
}
650649

651-
updateContainerSize(image) {
652-
const parentEl = this.container.parentNode || {};
653-
const imageAspectRatio = image.width / image.height;
654-
const isProvidedHeightLessThanWidth = this.containerHeight < this.containerWidth;
655-
const containerWidth = getContainerResponsiveWidth(parentEl, this.containerWidth);
656-
const containerHeight = getContainerResponsiveHeight(this.container, containerWidth, this.containerHeight);
650+
updateContainerAndCanvasSize(image) {
651+
const imageAspectRatio = getImageAspectRatio(image, this.ratio);
657652

658653
if (this.fullscreenView) {
659654
this.container.width = window.innerWidth * this.devicePixelRatio;
@@ -665,26 +660,11 @@ import {
665660
return;
666661
}
667662

668-
if (this.containerWidth && this.containerHeight) {
669-
this.container.style.width = containerWidth + 'px';
670-
this.container.style.height = containerHeight / imageAspectRatio + 'px';
671-
672-
return;
673-
}
674-
675-
if (!this.containerWidth && !this.containerHeight) {
676-
this.container.style.height = containerHeight / imageAspectRatio + 'px';
677-
678-
return;
679-
}
663+
this.canvas.width = this.container.offsetWidth * this.devicePixelRatio;
664+
this.canvas.style.width = this.container.offsetWidth + 'px';
680665

681-
if ((isProvidedHeightLessThanWidth || !this.containerWidth) && this.containerHeight) {
682-
this.container.style.maxWidth = containerHeight * imageAspectRatio + 'px';
683-
this.container.style.height = containerHeight + 'px';
684-
} else {
685-
this.container.style.maxWidth = containerWidth + 'px';
686-
this.container.style.height = containerWidth / imageAspectRatio + 'px';
687-
}
666+
this.canvas.height = (this.container.offsetWidth / imageAspectRatio) * this.devicePixelRatio;
667+
this.canvas.style.height = (this.container.offsetWidth / imageAspectRatio) + 'px';
688668
}
689669

690670
onResizedImageLoad(orientation, image, index) {
@@ -715,7 +695,7 @@ import {
715695
const responsive = this.ciParams.ciToken;
716696
const firstImage = this.imagesX[0];
717697

718-
this.updateContainerSize(firstImage);
698+
this.updateContainerAndCanvasSize(firstImage);
719699
this.update();
720700

721701
this.speedFactor = getSpeedFactor(this.dragSpeed, this.amountX, this.container.offsetWidth);
@@ -752,12 +732,6 @@ import {
752732
const ctx = this.canvas.getContext("2d");
753733
ctx.scale(this.devicePixelRatio, this.devicePixelRatio);
754734

755-
this.canvas.width = this.container.offsetWidth * this.devicePixelRatio;
756-
this.canvas.style.width = this.container.offsetWidth + 'px';
757-
758-
this.canvas.height = this.container.offsetHeight * this.devicePixelRatio;
759-
this.canvas.style.height = this.container.offsetHeight + 'px';
760-
761735
if (this.fullscreenView) {
762736
const { width, height, offsetX, offsetY } =
763737
contain(this.canvas.width, this.canvas.height, image.width, image.height);
@@ -1206,7 +1180,7 @@ import {
12061180
init(container, update = false, reload = false) {
12071181
let {
12081182
folder, apiVersion,filenameX, filenameY, imageListX, imageListY, indexZeroBase, amountX, amountY, draggable = true, swipeable = true, keys, keysReverse, bottomCircle, bottomCircleOffset, boxShadow,
1209-
autoplay, autoplayBehavior, playOnce, speed, autoplayReverse, disableDrag = true, fullscreen, magnifier, ciToken, ciFilters, ciTransformation, lazyload, lazySelector, spinReverse, dragSpeed, stopAtEdges, controlReverse, hide360Logo, logoSrc, containerWidth, containerHeight, pointerZoom
1183+
autoplay, autoplayBehavior, playOnce, speed, autoplayReverse, disableDrag = true, fullscreen, magnifier, ciToken, ciFilters, ciTransformation, lazyload, lazySelector, spinReverse, dragSpeed, stopAtEdges, controlReverse, hide360Logo, logoSrc, pointerZoom, ratio
12101184
} = get360ViewProps(container);
12111185

12121186
const ciParams = { ciToken, ciFilters, ciTransformation };
@@ -1240,17 +1214,16 @@ import {
12401214
this.lazySelector = lazySelector;
12411215
this.spinReverse = spinReverse;
12421216
this.controlReverse = controlReverse;
1243-
this.dragSpeed = Math.max(magnifier, 50);
1217+
this.dragSpeed = Math.max(dragSpeed, 50);
12441218
this.autoplaySpeed = this.speed * 36 / this.amountX;
12451219
this.stopAtEdges = stopAtEdges;
12461220
this.hide360Logo = hide360Logo;
12471221
this.logoSrc = logoSrc;
12481222
this.ciParams = ciParams;
12491223
this.apiVersion = apiVersion;
1250-
this.containerWidth = containerWidth;
1251-
this.containerHeight = containerHeight;
12521224
this.pointerZoom = pointerZoom > 1 ? Math.min(pointerZoom, 3) : 0;
12531225
this.keysReverse = keysReverse;
1226+
this.ratio = ratio && JSON.parse(ratio);
12541227

12551228
if (reload) {
12561229
new CI360Viewer(this.container);
@@ -1342,7 +1315,7 @@ import {
13421315
if (this.lazyloadX || this.lazyloadY) return initLazyload(image, orientation);
13431316

13441317
if (isFirstImageLoaded) {
1345-
this.updateContainerSize(image);
1318+
this.updateContainerAndCanvasSize(image);
13461319
this.onFirstImageLoaded(image);
13471320
}
13481321

src/ci360.utils.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ const get360ViewProps = (image) => ({
4848
stopAtEdges: isTrue(image, 'stop-at-edges'),
4949
hide360Logo: isTrue(image, 'hide-360-logo'),
5050
logoSrc: attr(image, 'logo-src') || 'https://scaleflex.ultrafast.io/https://scaleflex.airstore.io/filerobot/js-cloudimage-360-view/360_view.svg',
51-
containerWidth: parseInt(attr(image, 'width') || attr(image, 'data-width'), 10) || 0,
52-
containerHeight: parseInt(attr(image, 'height') || attr(image, 'data-height'), 10) || 0,
51+
ratio: attr(image, 'ratio') || attr(image, 'data-ratio') || null,
5352
});
5453

5554
const isTrue = (image, type) => {

src/utils/index.js

+17-8
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,34 @@
1+
export { isSrcPropsChanged } from './image-src/is-src-props-changed';
2+
13
export { generateImagesPath } from './image-src/generate-images-path';
24
export { preloadImages } from './load-images/preload-images';
35
export { preloadOriginalImages } from './load-images/preload-original-images';
6+
47
export { contain } from './responsive/contain';
8+
export { getImageAspectRatio } from './responsive/get-image-aspect-ratio';
9+
510
export { getCurrentOriginalImage } from './magnify/get-current-original-image';
611
export { magnify } from './magnify/magnify';
12+
13+
export { generateZoomInSteps } from './zoom/generate-zoom-in-steps';
14+
export { generateZoomOutSteps } from './zoom/generate-zoom-out-steps';
15+
16+
export { loop } from './auto-play/loop';
717
export { getSpeedFactor } from './auto-play/get-speed-factor';
818
export { isCompletedOneCycle } from './auto-play/is-completed-one-cycle';
9-
export { getContainerResponsiveWidth } from './responsive/get-container-responsive-width';
10-
export { getContainerResponsiveHeight } from './responsive/get-container-responsive-height';
11-
export { getMovingDirection } from './spin-y/get-moving-direction';
12-
export { initControls } from './controls/init-controls';
19+
1320
export { addClass } from './common/add-class';
1421
export { removeClass } from './common/remove-class';
22+
23+
export { getMovingDirection } from './spin-y/get-moving-direction';
24+
1525
export { getItemSkipped } from './controls/get-item-skipped';
26+
export { initControls } from './controls/init-controls';
27+
1628
export * from './container-elements';
17-
export { loop } from './auto-play/loop';
18-
export { generateZoomInSteps } from './zoom/generate-zoom-in-steps';
19-
export { generateZoomOutSteps } from './zoom/generate-zoom-out-steps';
29+
2030
export { updateHotspots } from './hotspot/update-hotspots';
2131
export { createHotspots } from './hotspot/elements/create-hotspots';
2232
export { generateHotspotsConfigs } from './hotspot/generate-hotspots-configs';
2333
export { isMouseOnHotspot } from './hotspot/is-mouse-on-hotspot';
2434
export { hideHotspotsIcons } from './hotspot/hide-hotspots-icons';
25-
export { isSrcPropsChanged } from './image-src/is-src-props-changed';

src/utils/responsive/get-container-responsive-height.js

-11
This file was deleted.

src/utils/responsive/get-container-responsive-width.js

-11
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
export const getImageAspectRatio = (image, providedRatio) => {
2+
try {
3+
let imageAspectRatio = image.width / image.height;
4+
5+
if (typeof providedRatio === 'number') {
6+
imageAspectRatio = providedRatio;
7+
}
8+
9+
if (typeof providedRatio === 'object') {
10+
const mediaQueries = Object.keys(providedRatio)
11+
.sort((a, b) => a - b);
12+
13+
const activeMedia = mediaQueries.find((mediaQuery) => (
14+
window.innerWidth <= parseInt(mediaQuery, 10)
15+
));
16+
17+
if (activeMedia) {
18+
imageAspectRatio = providedRatio[activeMedia];
19+
}
20+
}
21+
22+
return imageAspectRatio;
23+
} catch {
24+
return 1;
25+
}
26+
}

0 commit comments

Comments
 (0)