Skip to content

Commit

Permalink
chore: build v2.7.12
Browse files Browse the repository at this point in the history
  • Loading branch information
Amr Wagdy committed Mar 19, 2022
1 parent c225ef5 commit 6dc5eeb
Show file tree
Hide file tree
Showing 17 changed files with 138 additions and 115 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ Types of changes:
- ...

-------------
## 2.7.12 - 2022-03-19
### Changed
- hotspots init method

## 2.7.11 - 2022-03-17
### Fixed
- canvas aspect ratio
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Release](https://img.shields.io/badge/release-v2.7.11-blue.svg)](https://github.com/scaleflex/js-cloudimage-360-view/releases)
[![Release](https://img.shields.io/badge/release-v2.7.12-blue.svg)](https://github.com/scaleflex/js-cloudimage-360-view/releases)
[![Contributions welcome](https://img.shields.io/badge/contributions-welcome-orange.svg)](#contributing)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)
[![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)
Expand Down
6 changes: 3 additions & 3 deletions build/js-cloudimage-360-view.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ <h2 class="text-center">Ready to get started?</h2>
<p>Include the following script into your project after all content in body tag</p>
<figure class="highlight">
<pre><code class="javascript">
&lt;script src="https://cdn.scaleflex.it/plugins/js-cloudimage-360-view/2.7.11/js-cloudimage-360-view.min.js"&gt;&lt;/script&gt;
&lt;script src="https://cdn.scaleflex.it/plugins/js-cloudimage-360-view/2.7.12/js-cloudimage-360-view.min.js"&gt;&lt;/script&gt;
</code></pre>
</figure>
</div>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "js-cloudimage-360-view",
"version": "2.7.11",
"version": "2.7.12",
"main": "dist/index.js",
"description": "",
"author": "scaleflex",
Expand Down
42 changes: 31 additions & 11 deletions src/ci360.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ import {
removeChildFromParent,
initLazyload,
} from './utils';
import { togglePopupEvents } from './utils/hotspots/toggle-popup-events';

class CI360Viewer {
constructor(container, fullscreen, hotspotConfig) {
constructor(container, fullscreen, hotspotsConfigs) {
this.container = container;
this.movementStart = { x: 0, y: 0 };
this.isStartSpin = false;
Expand All @@ -69,7 +70,7 @@ import {
this.devicePixelRatio = Math.round(window.devicePixelRatio || 1);
this.isMobile = !!('ontouchstart' in window || navigator.msMaxTouchPoints);
this.id = container.id;
this.hotspotConfig = hotspotConfig && generateHotspotsConfigs(hotspotConfig);
this.hotspotsConfigs = hotspotsConfigs && generateHotspotsConfigs(hotspotsConfigs);
this.isMagnifyOpen = false;
this.isDragged = false;
this.startPointerZoom = false;
Expand Down Expand Up @@ -109,6 +110,10 @@ import {
this.isClicked = true;
this.isDragged = false;

if (this.hotspotsConfigs) {
togglePopupEvents(this.hotspotsConfigs, event, true);
}

if (isMouseOnHotspotElement) {
this.isClicked = false;
}
Expand All @@ -125,6 +130,10 @@ import {
this.show360ViewCircleIcon();
}

if (this.hotspotsConfigs) {
togglePopupEvents(this.hotspotsConfigs);
}

if (this.pointerZoom && !this.fullscreenView) {
setTimeout(() => {
this.isZoomReady = true;
Expand Down Expand Up @@ -225,7 +234,7 @@ import {

const zoomSteps = generateZoomInSteps(this.pointerZoom);

if (this.hotspotConfig) {
if (this.hotspotsConfigs) {
hideHotspotsIcons();
}

Expand Down Expand Up @@ -794,13 +803,14 @@ import {
if (this.mouseTracked) {
this.updateImageScale(ctx);
} else {
if (this.hotspotConfig && !this.autoplay) {
if (this.hotspotsConfigs && !this.autoplay) {
updateHotspots(
this.container,
this.hotspotConfig,
this.hotspotsConfigs,
this.activeImageX,
this.activeImageY,
this.movingDirection
this.movingDirection,
this.isClicked
);
}

Expand Down Expand Up @@ -883,10 +893,10 @@ import {
this.addFullscreenIcon();
}

if (this.hotspotConfig && !this.autoplay) {
if (this.hotspotsConfigs && !this.autoplay) {
updateHotspots(
this.container,
this.hotspotConfig,
this.hotspotsConfigs,
this.activeImageX,
this.activeImageY,
this.movingDirection
Expand Down Expand Up @@ -921,6 +931,16 @@ import {
}

this.initControls();

if (this.hotspotsConfigs && !this.autoplay) {
updateHotspots(
this.container,
this.hotspotsConfigs,
this.activeImageX,
this.activeImageY,
this.movingDirection
);
}
}

magnify(event) {
Expand Down Expand Up @@ -972,7 +992,7 @@ import {

const fullscreenContainer = createFullscreenModal(this.container);

new CI360Viewer(fullscreenContainer, true, this.hotspotConfig);
new CI360Viewer(fullscreenContainer, true, this.hotspotsConfigs);
}

setFullscreenEvents(_, event) {
Expand Down Expand Up @@ -1343,8 +1363,8 @@ import {
this.canvas = createCanvas(this.innerBox);
this.loader = createLoader(this.innerBox);

if (this.hotspotConfig && !this.fullscreenView) {
createHotspots(container, this.hotspotConfig);
if (this.hotspotsConfigs && !this.fullscreenView) {
createHotspots(container, this.hotspotsConfigs);
}

applyStylesToContainer(this.container);
Expand Down
1 change: 1 addition & 0 deletions src/ci360.utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,6 @@ export {
get360ViewProps,
setView360Icon,
attr,
isTrue,
debounce
}
29 changes: 19 additions & 10 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import 'core-js/features/array/for-each';
import 'core-js/features/array/filter';
import 'core-js/features/array/includes';
import CI360Viewer from './ci360.service';
import { attr } from './ci360.utils';
import { isTrue } from './ci360.utils';

function setContainerId(container) {
function getContainerWithId(container) {
const containerId = container.id;

if (!containerId) {
Expand All @@ -20,17 +20,15 @@ function setContainerId(container) {
function init() {
const viewers = [];
const view360Array = document.querySelectorAll('.cloudimage-360:not(.initialized)');
const hotspotsConfigs = window.CI360.hotspots|| {};

[].slice.call(view360Array).forEach(container => {
const containerWithId = setContainerId(container);
[].slice.call(view360Array).forEach(_container => {
const container = getContainerWithId(_container);

const hotspotInstanceName = attr(containerWithId, 'hotspot-instance') ||
attr(containerWithId, 'data-hotspot-instance');
const isHotspotsEnabled = isTrue(container, 'hotspots')

const hotspotConfig = hotspotsConfigs?.[hotspotInstanceName];

viewers.push(new CI360Viewer(containerWithId, false, hotspotConfig));
if (!isHotspotsEnabled) {
viewers.push(new CI360Viewer(container));
}
})

window.CI360._viewers = viewers;
Expand Down Expand Up @@ -80,12 +78,23 @@ function isNoViewers() {
return !(window.CI360._viewers && window.CI360._viewers.length > 0);
}

function addHotspots(instanceId, config) {
const view360Array = document.querySelectorAll('.cloudimage-360:not(.initialized)');
const container = Array.from(view360Array)
.find(view => view.id === instanceId);

if (container) {
window.CI360._viewers.push(new CI360Viewer(container, false, config))
}
}

window.CI360 = window.CI360 || {};
window.CI360.init = init;
window.CI360.destroy = destroy;
window.CI360.getActiveIndexByID = getActiveIndexByID;
window.CI360.update = update;
window.CI360.add = add;
window.CI360.addHotspots = addHotspots;

if (!window.CI360.notInitOnLoad) {
init();
Expand Down
8 changes: 5 additions & 3 deletions src/static/css/hotspots.css
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
border: 1px solid #FFFFFF33;
border-radius: 50%;
box-sizing: border-box;
transition: opacity 800ms ease-in-out;
transition: opacity 300ms ease-in-out;
cursor: auto;
}

Expand All @@ -61,7 +61,7 @@
.cloudimage-360-hotspot-custom-icon::after {
content: '+';
position: absolute;
width: 8px;
line-height: 20px;
left: 50%;
top: 100%;
color: #FFF;
Expand Down Expand Up @@ -131,6 +131,8 @@
.cloudimage-360-images-carousel .cloudimage-360-carousel-image {
display: none;
min-height: 187px;
max-width: 100%;
max-height: 100%;
}

.cloudimage-360-images-carousel .cloudimage-360-carousel-image.active-image {
Expand Down Expand Up @@ -194,10 +196,10 @@
padding: 4px 8px;
transition: background-color 200ms ease-in-out;
border-radius: 2px;
text-decoration: none;
}

.cloudimage-360-modal-more-details:hover {
text-decoration: none;
color: #76AD01;
background-color: #e1f5d8;
}
Expand Down
6 changes: 6 additions & 0 deletions src/utils/hotspots/attach-events/hide-popup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const hidePopup = (popup, isVisible) => {
if (!isVisible) {
popup.removeAttribute('data-show');
popup.removeAttribute('data-cloudimage-360-show');
}
};
6 changes: 6 additions & 0 deletions src/utils/hotspots/attach-events/show-popup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const showPopup = (popup, popperInstance) => {
popup.setAttribute('data-show', '');
popup.setAttribute('data-cloudimage-360-show', '');

popperInstance.update();
}
49 changes: 0 additions & 49 deletions src/utils/hotspots/attach-popup-events.js

This file was deleted.

44 changes: 33 additions & 11 deletions src/utils/hotspots/elements/create-hotspot-icon.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,53 @@
import { hidePopup } from '../attach-events/hide-popup';
import { showPopup } from '../attach-events/show-popup';
import { hideHotspotIcon } from '../hide-hotspot-icon';

export const createHotspotIcon = (container, hotspotConfig) => {
export const createHotspotIcon = (container, hotspotConfig, popup, popperInstance) => {
const { indicatorSelector, variant } = hotspotConfig;
const { url, anchorId } = variant;
const { popupProps: { open = false } } = hotspotConfig;

let isVisible;
const hotspotIcon = document.createElement('div');

const mouseEnterHotspot = () => {
hotspotIcon.setAttribute('data-cloudimage-360-show', '');
};

const mouseLeaveHotspot = () => {
hotspotIcon.removeAttribute('data-cloudimage-360-show');
};

hotspotIcon.style.position = 'absolute';

hotspotIcon.className = `cloudimage-360-hotspot-${url ? 'link' : 'custom'}-icon ${indicatorSelector}`;

hotspotIcon.setAttribute('data-hotspot-icon-id', anchorId);
hotspotIcon.setAttribute('data-cloudimage-360-hotspot', '');

hotspotIcon.addEventListener('mouseenter', mouseEnterHotspot);
hotspotIcon.addEventListener('mouseleave', mouseLeaveHotspot);
const popupMouseEnter = () => {
isVisible = true;
};

const popupMouseLeave = () => {
isVisible = false;

!open && hidePopup(popup, isVisible);
}

hotspotIcon.onclick = (e) => e.stopPropagation();

const showEvents = ['mouseenter', 'touchstart', 'focus'];
const hideEvents = ['mouseleave', 'blur'];

showEvents.forEach((event) => {
hotspotIcon.addEventListener(event, () => showPopup(popup, popperInstance));
});

if (!open) {
hideEvents.forEach((event) => {
hotspotIcon.addEventListener(
event,
() => setTimeout(() => hidePopup(popup, isVisible), 160)
);
});
}

popup.addEventListener('mouseenter', popupMouseEnter);
popup.addEventListener('mouseleave', popupMouseLeave);

hideHotspotIcon(hotspotIcon);

container.appendChild(hotspotIcon);
Expand Down
Loading

0 comments on commit 6dc5eeb

Please sign in to comment.