2021-02-22 17:27:13 +05:30
|
|
|
= javascript_tag do
|
2020-07-28 23:09:34 +05:30
|
|
|
:plain
|
|
|
|
if ('loading' in HTMLImageElement.prototype) {
|
|
|
|
document.querySelectorAll('img.lazy').forEach(img => {
|
|
|
|
img.loading = 'lazy';
|
|
|
|
let imgUrl = img.dataset.src;
|
|
|
|
// Only adding width + height for avatars for now
|
|
|
|
if (imgUrl.indexOf('/avatar/') > -1 && imgUrl.indexOf('?') === -1) {
|
|
|
|
const targetWidth = img.getAttribute('width') || img.width;
|
|
|
|
imgUrl += `?width=${targetWidth}`;
|
|
|
|
}
|
|
|
|
img.src = imgUrl;
|
|
|
|
img.removeAttribute('data-src');
|
|
|
|
img.classList.remove('lazy');
|
2023-01-13 00:05:48 +05:30
|
|
|
img.classList.add('js-lazy-loaded');
|
|
|
|
img.dataset.qa_selector = 'js_lazy_loaded_content';
|
2020-07-28 23:09:34 +05:30
|
|
|
});
|
|
|
|
}
|