Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

js-cloudimage-360-view

Package Overview
Dependencies
Maintainers
1
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js-cloudimage-360-view - npm Package Compare versions

Comparing version 2.0.4 to 2.0.5

392

dist/ci360.service.js

@@ -21,3 +21,2 @@ 'use strict';

this.activeImage = 1;
this.previousActiveImage = 1;
this.movementStart = 0;

@@ -30,2 +29,5 @@ this.isClicked = false;

this.ratio = ratio;
this.images = [];
this.devicePixelRatio = Math.round(window.devicePixelRatio || 1);
this.isMobile = !!('ontouchstart' in window || navigator.msMaxTouchPoints);

@@ -97,3 +99,2 @@ this.init(container);

event.preventDefault();
this.movementStart = event.touches[0].clientX;

@@ -175,22 +176,28 @@ this.isClicked = true;

value: function onMove(pageX) {
if (pageX - this.movementStart > this.speedFactor) {
var itemsSkipped = Math.floor((event.pageX - this.movementStart) / this.speedFactor) || 1;
if (pageX - this.movementStart >= this.speedFactor) {
var itemsSkippedRight = Math.floor((pageX - this.movementStart) / this.speedFactor) || 1;
if (itemsSkippedRight >= 3 * this.speedFactor) itemsSkippedRight = 3 * this.speedFactor;
this.movementStart = pageX;
this.previousActiveImage = this.activeImage;
this.activeImage = (this.activeImage + itemsSkipped) % this.amount || 1;
if (this.spinReverse) {
this.moveActiveIndexDown(itemsSkippedRight);
} else {
this.moveActiveIndexUp(itemsSkippedRight);
}
if (this.bottomCircle) this.hide360ViewCircleIcon();
this.update(this.activeImage);
} else if (pageX - this.movementStart <= -this.speedFactor) {
var _itemsSkipped = Math.abs(Math.floor((pageX - this.movementStart) / this.speedFactor)) || 1;
} else if (this.movementStart - pageX >= this.speedFactor) {
var itemsSkippedLeft = Math.floor((this.movementStart - pageX) / this.speedFactor) || 1;
if (itemsSkippedLeft >= 3 * this.speedFactor) itemsSkippedLeft = 3 * this.speedFactor;
this.movementStart = pageX;
this.previousActiveImage = this.activeImage;
if (this.activeImage - _itemsSkipped < 1) {
this.activeImage = this.amount + (this.activeImage - _itemsSkipped);
if (this.spinReverse) {
this.moveActiveIndexUp(itemsSkippedLeft);
} else {
this.activeImage = this.activeImage - _itemsSkipped;
this.moveActiveIndexDown(itemsSkippedLeft);
}

@@ -203,2 +210,16 @@

}, {
key: 'moveActiveIndexUp',
value: function moveActiveIndexUp(itemsSkipped) {
this.activeImage = (this.activeImage + itemsSkipped) % this.amount || 1;
}
}, {
key: 'moveActiveIndexDown',
value: function moveActiveIndexDown(itemsSkipped) {
if (this.activeImage - itemsSkipped < 1) {
this.activeImage = this.amount + (this.activeImage - itemsSkipped);
} else {
this.activeImage = this.activeImage - itemsSkipped;
}
}
}, {
key: 'loop',

@@ -211,3 +232,2 @@ value: function loop(reversed) {

value: function next() {
this.previousActiveImage = this.activeImage;
this.activeImage = this.activeImage % this.amount + 1;

@@ -220,3 +240,2 @@

value: function prev() {
this.previousActiveImage = this.activeImage;
if (this.activeImage - 1 === 0) {

@@ -233,15 +252,32 @@ this.activeImage = this.amount;

value: function update(activeImage) {
var prevImage = this.container.children[this.previousActiveImage - 1];
var nextImage = this.container.children[activeImage - 1];
var image = this.images[activeImage - 1];
var ctx = this.canvas.getContext("2d");
prevImage.style.display = 'none';
nextImage.style.display = 'block';
ctx.scale(this.devicePixelRatio, this.devicePixelRatio);
if (this.fullScreenView) {
this.canvas.width = window.innerWidth * this.devicePixelRatio;
this.canvas.style.width = window.innerWidth + 'px';
this.canvas.height = window.innerHeight * this.devicePixelRatio;
this.canvas.style.height = window.innerHeight + 'px';
var _contain = (0, _ci.contain)(this.canvas.width, this.canvas.height, image.width, image.height),
offsetX = _contain.offsetX,
offsetY = _contain.offsetY,
width = _contain.width,
height = _contain.height;
ctx.drawImage(image, offsetX, offsetY, width, height);
} else {
this.canvas.width = this.container.offsetWidth * this.devicePixelRatio;
this.canvas.style.width = this.container.offsetWidth + 'px';
this.canvas.height = this.container.offsetWidth * this.devicePixelRatio / image.width * image.height;
this.canvas.style.height = this.container.offsetWidth / image.width * image.height + 'px';
ctx.drawImage(image, 0, 0, this.canvas.width, this.canvas.height);
}
}
}, {
key: 'onImageLoad',
value: function onImageLoad() {
this.loadedImages += 1;
var percentage = Math.round(this.loadedImages / this.amount * 100);
key: 'updatePercentageInLoader',
value: function updatePercentageInLoader(percentage) {
if (this.loader) {

@@ -254,70 +290,117 @@ this.loader.style.width = percentage + '%';

}
}
}, {
key: 'onAllImagesLoaded',
value: function onAllImagesLoaded() {
this.imagesLoaded = true;
this.container.style.cursor = 'grab';
this.removeLoader();
if (this.loadedImages === this.amount) {
this.imagesLoaded = true;
this.container.style.cursor = 'grab';
this.removeLoader();
if (!this.fullScreenView) {
this.speedFactor = Math.floor(this.speed / 150 * 36 / this.amount * 25 * this.container.offsetWidth / 1500) || 1;
} else {
var containerRatio = this.container.offsetHeight / this.container.offsetWidth;
var imageOffsetWidth = this.container.offsetWidth;
if (!this.fullScreenView) {
this.speedFactor = Math.floor(36 / this.amount * 25 * this.container.offsetWidth / 1500) || 1;
} else {
var containerRatio = this.container.offsetHeight / this.container.offsetWidth;
var imageOffsetWidth = this.container.offsetWidth;
if (this.ratio > containerRatio) {
imageOffsetWidth = this.container.offsetHeight / this.ratio;
}
if (this.ratio > containerRatio) {
imageOffsetWidth = this.container.offsetHeight / this.ratio;
}
this.speedFactor = Math.floor(this.speed / 150 * 36 / this.amount * 25 * imageOffsetWidth / 1500) || 1;
}
this.speedFactor = Math.floor(36 / this.amount * 25 * imageOffsetWidth / 1500) || 1;
}
if (this.autoplay) {
this.play();
}
if (this.autoplay) {
this.play();
}
if (this.view360Icon) {
this.view360Icon.innerText = '';
(0, _ci.setView360Icon)(this.view360Icon);
}
}
}, {
key: 'onFirstImageLoaded',
value: function onFirstImageLoaded(event) {
var _this2 = this;
if (this.view360Icon) {
this.view360Icon.innerText = '';
(0, _ci.setView360Icon)(this.view360Icon);
}
} else if (this.loadedImages === 1) {
this.add360ViewIcon();
this.add360ViewIcon();
if (this.lazyload) {
[].slice.call(this.container.children).filter(function (image) {
return image.nodeName === 'IMG';
}).forEach(function (image, index) {
if (index === 0) return;
if (this.fullScreenView) {
this.canvas.width = window.innerWidth * this.devicePixelRatio;
this.canvas.style.width = window.innerWidth + 'px';
this.canvas.height = window.innerHeight * this.devicePixelRatio;
this.canvas.style.height = window.innerHeight + 'px';
var dataSrc = image.getAttribute('data-src');
var ctx = this.canvas.getContext("2d");
if (dataSrc) {
image.src = image.getAttribute('data-src');
}
});
}
var _contain2 = (0, _ci.contain)(this.canvas.width, this.canvas.height, event.target.width, event.target.height),
offsetX = _contain2.offsetX,
offsetY = _contain2.offsetY,
width = _contain2.width,
height = _contain2.height;
if (this.ratio) {
this.container.style.minHeight = 'auto';
}
ctx.drawImage(event.target, offsetX, offsetY, width, height);
} else {
this.canvas.width = this.container.offsetWidth * this.devicePixelRatio;
this.canvas.style.width = this.container.offsetWidth + 'px';
this.canvas.height = this.container.offsetWidth * this.devicePixelRatio / event.target.width * event.target.height;
this.canvas.style.height = this.container.offsetWidth / event.target.width * event.target.height + 'px';
if (this.magnifier && !this.fullScreenView) {
this.addMagnifier();
}
var _ctx = this.canvas.getContext("2d");
if (this.boxShadow && !this.fullScreenView) {
this.addBoxShadow();
}
_ctx.drawImage(event.target, 0, 0, this.canvas.width, this.canvas.height);
}
if (this.bottomCircle && !this.fullScreenView) {
this.add360ViewCircleIcon();
}
if (this.lazyload && !this.fullScreenView) {
this.images.forEach(function (image, index) {
if (index === 0) {
_this2.container.removeChild(_this2.lazyloadInitImage);
return;
}
if (this.fullScreen && !this.fullScreenView) {
this.addFullScreenIcon();
} else if (this.fullScreenView) {
this.addCloseFullScreenView();
}
var dataSrc = image.getAttribute('data-src');
if (dataSrc) {
image.src = image.getAttribute('data-src');
}
});
}
if (this.ratio) {
this.container.style.minHeight = 'auto';
}
if (this.magnifier && !this.fullScreenView) {
this.addMagnifier();
}
if (this.boxShadow && !this.fullScreenView) {
this.addBoxShadow();
}
if (this.bottomCircle && !this.fullScreenView) {
this.add360ViewCircleIcon();
}
if (this.fullScreen && !this.fullScreenView) {
this.addFullScreenIcon();
} else if (this.fullScreenView) {
this.addCloseFullScreenView();
}
}
}, {
key: 'onImageLoad',
value: function onImageLoad(event) {
var percentage = Math.round(this.loadedImages / this.amount * 100);
this.loadedImages += 1;
this.updatePercentageInLoader(percentage);
if (this.loadedImages === this.amount) {
this.onAllImagesLoaded(event);
} else if (this.loadedImages === 1) {
this.onFirstImageLoaded(event);
}
}
}, {
key: 'addCloseFullScreenView',

@@ -370,3 +453,3 @@ value: function addCloseFullScreenView() {

value: function magnify() {
var _this2 = this;
var _this3 = this;

@@ -378,4 +461,4 @@ var src = '' + this.folder + this.filename.replace('{index}', this.activeImage);

image.onload = function () {
if (_this2.glass) {
_this2.glass.style.cursor = 'none';
if (_this3.glass) {
_this3.glass.style.cursor = 'none';
}

@@ -405,3 +488,3 @@ };

var fullScreenContainer = this.container.cloneNode();
var image = this.container.children[0];
var image = this.images[0];
var ratio = image.height / image.width;

@@ -493,3 +576,3 @@

value: function play() {
var _this3 = this;
var _this4 = this;

@@ -500,3 +583,3 @@ if (this.bottomCircle) this.hide360ViewCircleIcon();

this.loopTimeoutId = window.setInterval(function () {
_this3.loop(_this3.reversed);
_this4.loop(_this4.reversed);
}, this.speed * 36 / this.amount);

@@ -511,6 +594,57 @@ }

}, {
key: 'getSrc',
value: function getSrc(responsive, container, folder, filename, ciSize, ciToken, ciOperation, ciFilters) {
var src = '' + folder + filename;
if (responsive) {
var imageOffsetWidth = container.offsetWidth;
if (this.fullScreenView) {
var containerRatio = container.offsetHeight / container.offsetWidth;
if (this.ratio > containerRatio) {
imageOffsetWidth = container.offsetHeight / this.ratio;
}
}
var ciSizeNext = (0, _ci.getSizeAccordingToPixelRatio)(ciSize || (0, _ci.getResponsiveWidthOfContainer)(imageOffsetWidth));
src = 'https://' + ciToken + '.cloudimg.io/' + ciOperation + '/' + ciSizeNext + '/' + ciFilters + '/' + src;
}
return src;
}
}, {
key: 'preloadImages',
value: function preloadImages(amount, src, lazyload, lazySelector) {
var _this5 = this;
[].concat(_toConsumableArray(new Array(amount))).map(function (item, index) {
var image = new Image();
var resultSrc = src.replace('{index}', index + 1);
if (lazyload && !_this5.fullScreenView) {
image.setAttribute('data-src', resultSrc);
image.className = image.className.length ? image.className + (' ' + lazySelector) : lazySelector;
if (index === 0) {
_this5.lazyloadInitImage = image;
image.style.position = 'absolute';
image.style.top = '0';
image.style.left = '0';
_this5.container.appendChild(image);
}
} else {
image.src = resultSrc;
}
image.onload = _this5.onImageLoad.bind(_this5);
image.onerror = _this5.onImageLoad.bind(_this5);
_this5.images.push(image);
});
}
}, {
key: 'init',
value: function init(container) {
var _this4 = this;
var _get360ViewProps = (0, _ci.get360ViewProps)(container),

@@ -540,70 +674,42 @@ folder = _get360ViewProps.folder,

lazyload = _get360ViewProps.lazyload,
lazySelector = _get360ViewProps.lazySelector;
lazySelector = _get360ViewProps.lazySelector,
spinReverse = _get360ViewProps.spinReverse;
this.addLoader();
[].concat(_toConsumableArray(new Array(amount))).map(function (item, index) {
var image = new Image();
var src = '' + folder + filename.replace('{index}', index + 1);
this.folder = folder;
this.filename = filename;
this.amount = amount;
this.bottomCircle = bottomCircle;
this.bottomCircleOffset = bottomCircleOffset;
this.boxShadow = boxShadow;
this.autoplay = autoplay && !this.isMobile;
this.speed = speed;
this.reversed = autoplayReverse;
this.fullScreen = fullScreen;
this.magnifier = !this.isMobile && magnifier ? magnifier : false;
this.lazyload = lazyload;
this.ratio = ratio;
this.spinReverse = spinReverse;
if (responsive) {
var imageOffsetWidth = container.offsetWidth;
container.style.position = 'relative';
container.style.width = '100%';
container.style.cursor = 'wait';
container.setAttribute('draggable', 'false');
if (_this4.fullScreenView) {
var containerRatio = _this4.container.offsetHeight / _this4.container.offsetWidth;
this.canvas = document.createElement('canvas');
this.canvas.style.width = '100%';
this.canvas.style.fontSize = '0';
if (_this4.ratio > containerRatio) {
imageOffsetWidth = _this4.container.offsetHeight / _this4.ratio;
}
}
if (ratio) {
container.style.minHeight = container.offsetWidth * ratio + 'px';
this.canvas.height = container.style.minHeight;
}
var ciSizeNext = (0, _ci.getSizeAccordingToPixelRatio)(ciSize || (0, _ci.getResponsiveWidthOfContainer)(imageOffsetWidth));
this.container.appendChild(this.canvas);
src = 'https://' + ciToken + '.cloudimg.io/' + ciOperation + '/' + ciSizeNext + '/' + ciFilters + '/' + src;
}
var src = this.getSrc(responsive, container, folder, filename, ciSize, ciToken, ciOperation, ciFilters);
if (lazyload) {
image.setAttribute('data-src', src);
image.className = image.className.length ? image.className + (' ' + lazySelector) : lazySelector;
} else {
image.src = src;
}
this.preloadImages(amount, src, lazyload, lazySelector);
image.style.height = 'auto';
image.style.width = '100%';
image.style.display = index === 0 ? 'block' : 'none';
image.onload = _this4.onImageLoad.bind(_this4);
image.onerror = _this4.onImageLoad.bind(_this4);
_this4.folder = folder;
_this4.filename = filename;
_this4.amount = amount;
_this4.bottomCircle = bottomCircle;
_this4.bottomCircleOffset = bottomCircleOffset;
_this4.boxShadow = boxShadow;
_this4.autoplay = autoplay;
_this4.speed = speed;
_this4.reversed = autoplayReverse;
_this4.fullScreen = fullScreen;
_this4.magnifier = magnifier;
_this4.lazyload = lazyload;
container.style.position = 'relative';
container.style.cursor = 'wait';
if (_this4.fullScreenView) {
var imageBackground = document.createElement('div');
(0, _ci.setFullScreenImageStyles)(imageBackground, src, index);
container.appendChild(imageBackground);
} else {
_this4.ratio = ratio;
if (ratio) {
container.style.minHeight = container.offsetWidth * ratio + 'px';
}
container.appendChild(image);
}
});
if (draggable) {

@@ -616,4 +722,4 @@ container.addEventListener('mousedown', this.mousedown.bind(this));

if (swipeable) {
container.addEventListener('touchstart', this.touchstart.bind(this));
container.addEventListener('touchend', this.touchend.bind(this));
container.addEventListener('touchstart', this.touchstart.bind(this), { passive: true });
container.addEventListener('touchend', this.touchend.bind(this), { passive: true });
container.addEventListener('touchmove', this.touchmove.bind(this));

@@ -620,0 +726,0 @@ }

@@ -12,12 +12,12 @@ 'use strict';

speed: parseInt(attr(image, 'speed') || attr(image, 'data-speed') || 150, 10),
keys: attr(image, 'keys') !== null || attr(image, 'data-keys') !== null,
keys: isTrue(image, 'keys'),
boxShadow: attr(image, 'box-shadow') || attr(image, 'data-box-shadow'),
autoplay: attr(image, 'autoplay') !== null || attr(image, 'data-autoplay') !== null,
autoplayReverse: attr(image, 'autoplay-reverse') !== null || attr(image, 'data-autoplay-reverse') !== null,
bottomCircle: attr(image, 'bottom-circle') !== null || attr(image, 'data-bottom-circle') !== null,
fullScreen: attr(image, 'full-screen') !== null || attr(image, 'data-full-screen') !== null,
autoplay: isTrue(image, 'autoplay'),
autoplayReverse: isTrue(image, 'autoplay-reverse'),
bottomCircle: isTrue(image, 'bottom-circle'),
fullScreen: isTrue(image, 'full-screen'),
magnifier: (attr(image, 'magnifier') !== null || attr(image, 'data-magnifier') !== null) && parseInt(attr(image, 'magnifier') || attr(image, 'data-magnifier'), 10),
bottomCircleOffset: parseInt(attr(image, 'bottom-circle-offset') || attr(image, 'data-bottom-circle-offset') || 5, 10),
ratio: parseFloat(attr(image, 'ratio') || attr(image, 'data-ratio') || 0) || false,
responsive: attr(image, 'responsive') !== null || attr(image, 'data-responsive') !== null,
responsive: isTrue(image, 'responsive'),
ciToken: attr(image, 'responsive') || attr(image, 'data-responsive') || 'demo',

@@ -27,7 +27,15 @@ ciSize: attr(image, 'size') || attr(image, 'data-size'),

ciFilters: attr(image, 'filters') || attr(image, 'data-filters') || 'q35',
lazyload: attr(image, 'lazyload') !== null || attr(image, 'data-lazyload') !== null,
lazySelector: attr(image, 'lazyload-selector') || attr(image, 'data-lazyload-selector') || 'lazyload'
lazyload: isTrue(image, 'lazyload'),
lazySelector: attr(image, 'lazyload-selector') || attr(image, 'data-lazyload-selector') || 'lazyload',
spinReverse: isTrue(image, 'spin-reverse')
};
};
var isTrue = function isTrue(image, type) {
var imgProp = attr(image, type);
var imgDataProp = attr(image, 'data-' + type);
return imgProp !== null && imgProp !== 'false' || imgDataProp !== null && imgDataProp !== 'false';
};
var attr = function attr(element, attribute) {

@@ -53,2 +61,3 @@ return element.getAttribute(attribute);

view360Icon.style.lineHeight = '100px';
view360Icon.style.zIndex = '2';
};

@@ -71,2 +80,3 @@

view360CircleIcon.style.transition = '0.5s all';
view360CircleIcon.style.zIndex = '2';
};

@@ -97,10 +107,2 @@

var setFullScreenImageStyles = function setFullScreenImageStyles(image, src, index) {
image.style.background = 'url(\'' + src + '\') 50% 50% / contain no-repeat';
image.style.width = '100%';
image.style.height = '100%';
image.style.margin = 'auto';
image.style.display = index === 0 ? 'block' : 'none';
};
var setMagnifyIconStyles = function setMagnifyIconStyles(magnifyIcon, fullScreen) {

@@ -255,2 +257,30 @@ magnifyIcon.style.position = 'absolute';

var fit = function fit(contains) {
return function (parentWidth, parentHeight, childWidth, childHeight) {
var scale = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1;
var offsetX = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 0.5;
var offsetY = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : 0.5;
var childRatio = childWidth / childHeight;
var parentRatio = parentWidth / parentHeight;
var width = parentWidth * scale;
var height = parentHeight * scale;
if (contains ? childRatio > parentRatio : childRatio < parentRatio) {
height = width / childRatio;
} else {
width = height * childRatio;
}
return {
width: width,
height: height,
offsetX: (parentWidth - width) * offsetX,
offsetY: (parentHeight - height) * offsetY
};
};
};
var contain = fit(true);
exports.get360ViewProps = get360ViewProps;

@@ -262,3 +292,2 @@ exports.set360ViewIconStyles = set360ViewIconStyles;

exports.setView360Icon = setView360Icon;
exports.setFullScreenImageStyles = setFullScreenImageStyles;
exports.magnify = magnify;

@@ -270,2 +299,3 @@ exports.setMagnifyIconStyles = setMagnifyIconStyles;

exports.getResponsiveWidthOfContainer = getResponsiveWidthOfContainer;
exports.getSizeAccordingToPixelRatio = getSizeAccordingToPixelRatio;
exports.getSizeAccordingToPixelRatio = getSizeAccordingToPixelRatio;
exports.contain = contain;
{
"name": "js-cloudimage-360-view",
"version": "2.0.4",
"version": "2.0.5",
"main": "dist/index.js",

@@ -5,0 +5,0 @@ "description": "",

@@ -1,2 +0,2 @@

[![Release](https://img.shields.io/badge/release-v2.0.4-blue.svg)](https://github.com/scaleflex/js-cloudimage-360-view/releases)
[![Release](https://img.shields.io/badge/release-v2.0.5-blue.svg)](https://github.com/scaleflex/js-cloudimage-360-view/releases)
[![Contributions welcome](https://img.shields.io/badge/contributions-welcome-orange.svg)](#contributing)

@@ -67,3 +67,3 @@ [![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)

```javascript
<script src="https://cdn.scaleflex.it/filerobot/js-cloudimage-360-view/v2.0.4.min.js"></script>
<script src="https://cdn.scaleflex.it/filerobot/js-cloudimage-360-view/v2.0.5.min.js"></script>
```

@@ -70,0 +70,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc