if (zoomedImage.src && zoomedImage.naturalWidth && zoomedImage.naturalHeight) {
1215 // wait no more than 3 seconds 1216 } else if (Date.now() - timer < 3000) { 1218 t_zoom__waitImgForScale(zoomedImage, timer, callback); 1221 const { naturalWidth, naturalHeight } = zoomedImage; 1222 console.warn(`zoomed image isn't complete, natural width: ${naturalWidth}, natural height: ${naturalHeight}`); 1228 * we cannot check original size of svg, and then we should check, is img has .svg format, 1229 * and if yes, fetch original <svg> to get original height and width 1231 * @param {HTMLImageElement} zoomedImage - current zoomed image 1233function t_zoom_checkToScaleInit(zoomedImage) { 1234 const windowWidth = window.innerWidth; 1235 const windowHeight = window.innerHeight; 1236 const { isMobile, isDoubleTapActivated } = t_getZoomState(); 1237 const zoomerWrapper = document.querySelector('.t-zoomer__wrapper'); 1238 zoomerWrapper.classList.remove('zoomer-no-scale'); 1240 const hasOriginalSvgParams = zoomedImage.hasAttribute('data-original-svg-height') || zoomedImage.hasAttribute('data-original-svg-width'); 1241 const imageHeight = parseInt(zoomedImage.getAttribute('data-original-svg-height'), 10) || zoomedImage.naturalHeight; 1242 const imageWidth = parseInt(zoomedImage.getAttribute('data-original-svg-width'), 10) || zoomedImage.naturalWidth; 1244 if (zoomedImage.src.includes('.svg') && !window.isIE && !hasOriginalSvgParams) { 1245 t_zoom_fetchSVG(zoomedImage, windowHeight, windowWidth); 1246 } else if (windowHeight < imageHeight || windowWidth < imageWidth) { 1247 if (!isDoubleTapActivated && isMobile) t_zoom_doubletapScaleInit(); 1248 t_zoom_scale_init(); 1250 document.querySelector('.t-zoomer__scale').classList.add('t-zoomer__scale--disabled'); 1251 zoomerWrapper.classList.add('zoomer-no-scale'); 1256 * get <svg> to check it real size 1258 * @param {HTMLImageElement} zoomedImage - current image 1259 * @param {number} windowHeight 1260 * @param {number} windowWidth 1262function t_zoom_fetchSVG(zoomedImage, windowHeight, windowWidth) { 1263 const url = zoomedImage.src; 1264 const { isMobile, isDoubleTapActivated } = t_getZoomState(); 1266 .then(response => response.text()) 1268 const div = document.createElement('div'); 1269 document.body.insertAdjacentElement('beforeend', div); 1270 div.innerHTML = svg; 1271 const parsedSVG = div.querySelector('svg'); 1272 let parsedSVGWidth = Math.round(parsedSVG.getBBox().width); 1273 let parsedSVGHeight = Math.round(parsedSVG.getBBox().height); 1274 const svgRatio = parsedSVGWidth / parsedSVGHeight; 1276 const svgLimitWidth = 5000; 1277 if (parsedSVGWidth > svgLimitWidth) { 1278 parsedSVGWidth = svgLimitWidth; 1279 parsedSVGHeight = Math.round(parsedSVGWidth / svgRatio); 1282 zoomedImage.setAttribute('data-original-svg-width', parsedSVGWidth); 1283 zoomedImage.setAttribute('data-original-svg-height', parsedSVGHeight); 1285 const isSvgLargerThanWindow = windowHeight < parsedSVGHeight || windowWidth < parsedSVGWidth; 1287 // Если у SVG не указаны атрибуты с размерами, то без явных размеров он займет размеры контейнера (0, 0) 1288 const attrWidth = parsedSVG.getAttribute('width'); 1289 const attrHeight = parsedSVG.getAttribute('height'); 1290 const hasDefinedSize = attrWidth || attrHeight; 1291 if (!hasDefinedSize || isSvgLargerThanWindow) { 1292 zoomedImage.style.width = `${parsedSVGWidth}px`; 1293 zoomedImage.style.height = `${parsedSVGHeight}px`; 1296 if (isSvgLargerThanWindow) { 1297 if (!isDoubleTapActivated && isMobile) t_zoom_doubletapScaleInit(); 1298 t_zoom_scale_init(); 1300 document.querySelector('.t-zoomer__scale').classList.add('t-zoomer__scale--disabled');