Каталог файловtilda-lazyload-1.0.js
501 * @param {HTMLElement} el502 * @param {String} imageUrl503 */504 function t_lazyload__checkParentBackground(el, imageUrl) {505 var coverId = el.getAttribute('data-content-cover-id');506 if (!coverId) return;507 var parentEl = document.getElementById('recorddiv' + coverId);508 if (!parentEl) return;509 parentEl.style.backgroundImage = '';510 }511 512 /**
История файла и сравнение версий
* Функция округления размеров
515 function t_lazyload__round(comm, width, height, round) { 516 var roundedWidth = width; 517 var roundedHeight = height; 519 if (comm == 'cover' && roundedWidth > 0 && roundedHeight > 0) { 520 var rr = roundedWidth / roundedHeight; 525 if (rr <= 0.8) ratio = 0.8; 526 if (rr <= 0.751) ratio = 0.75; 527 if (rr <= 0.667) ratio = 0.667; 528 if (rr <= 0.563) ratio = 0.562; 529 if (rr <= 0.501) ratio = 0.5; 530 roundedHeight = Math.ceil(roundedHeight / round) * round; 531 roundedWidth = Math.ceil(roundedHeight * ratio); 532 roundedWidth = Math.ceil(roundedWidth / 10) * 10; 534 if (rr >= 1.25) ratio = 1.25; 535 if (rr >= 1.332) ratio = 1.333; 536 if (rr >= 1.5) ratio = 1.5; 537 if (rr >= 1.777) ratio = 1.777; 538 if (rr >= 2.0) ratio = 2.0; 539 roundedWidth = Math.ceil(roundedWidth / round) * round; 540 roundedHeight = Math.ceil(roundedWidth / ratio); 541 roundedHeight = Math.ceil(roundedHeight / 10) * 10; 544 if (roundedWidth > 0) { 545 roundedWidth = Math.ceil(roundedWidth / round) * round; 547 if (roundedHeight > 0) { 548 roundedHeight = Math.ceil(roundedHeight / round) * round; 552 return [roundedWidth, roundedHeight]; 556 * Функция преобразования URL картинки, добавляя в путь модификаторы трансформации и конвертации в WEBP 557 * - Если URL не наш или SVG - ничего не делает 558 * - Для ретины - удваивает размеры 559 * - Если размеры > 1000 - ничего не делает (т.к в выигрыша в весе файла не получается, но зато происходит двойная компрессия) 560 * - При DPR = 1 и размере изображения меньше 400px по большей размерности увеличиваем размеры изображения в 1.2 раз 562 function t_lazyload__getResizeUrl(tagName, comm, str, width, height, x, y) { 563 if (str == 'undefined' || str == null) return str; 565 var url = str?.toLowerCase() || ''; 567 url.indexOf('.svg') > 0 || 568 url.indexOf('.gif') > 0 || 569 url.indexOf('.ico') > 0 || 570 url.indexOf('.apng') > 0 || 571 url.indexOf('static.tildacdn.') === -1 || 572 url.indexOf('-/empty/') > 0 || 573 url.indexOf('-/resizeb/') > 0 || 574 url.indexOf('/-/') > -1 || 575 (width == 0 && height == 0) || 576 window.lazy_err_thumb == 'y' || 577 url.indexOf('lib') > -1 || 578 (tagName !== 'IMG' && tagName !== 'DIV' && tagName !== 'TD' && tagName !== 'A') 584 if (window.devicePixelRatio === 1 && Math.max(width, height) <= 400) k = 1.2; 585 if (window.devicePixelRatio > 1) k = 2; 587 var updatedWidth = width; 588 var updatedHeight = height; 590 if (updatedWidth > 0) updatedWidth = parseInt(k * updatedWidth); 591 if (updatedHeight > 0) updatedHeight = parseInt(k * updatedHeight); 596 if (updatedWidth > 1000 || updatedHeight > 1800) { 597 return t_lazyload__getWebPUrl(str); 600 const isAvif = url.endsWith('.avif');