/
githubmirror
/
amphtml
Обзор
Документация
Войти
/
githubmirror
/
amphtml
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/core/dom/img.js
17 строк
576 B
Ryan Cebulko
♻️ Migrate most of #core to pass TS typechecking (#37141)
09 дек 2021, 21:22
Не верифицирован
09 дек 2021, 21:22
58a1c29
Код
Авторство
О чём код?
/** * Sets the img src to the first url in the srcset if srcset is defined but * src is not for browsers that do not support srcset. * @param {Element} img */ export function guaranteeSrcForSrcsetUnsupportedBrowsers(img) { // The <img> tag does not have a src and does not support srcset if (!img.hasAttribute('src') && 'srcset' in img == false) { const srcset = img.getAttribute('srcset') || ''; const matches = /\S+/.exec(srcset); if (matches == null) { return; } const srcseturl = matches[0]; img.setAttribute('src', srcseturl); } }