/
githubmirror
/
amphtml
Обзор
Документация
Войти
/
githubmirror
/
amphtml
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/core/dom/propagate-attributes.js
28 строк
888 B
Ryan Cebulko
♻️ Migrate most of #core to pass TS typechecking (#37141)
09 дек 2021, 21:22
Не верифицирован
09 дек 2021, 21:22
58a1c29
Код
Авторство
О чём код?
import {arrayOrSingleItemToArray} from '#core/types/array'; /** * Utility method that propagates attributes from a source element * to an updateable element. * If `opt_removeMissingAttrs` is true, then also removes any specified * attributes that are missing on the source element from the updateable element. * @param {string|Array<string>} attributes * @param {Element} sourceElement * @param {Element} updateElement * @param {boolean=} opt_removeMissingAttrs */ export function propagateAttributes( attributes, sourceElement, updateElement, opt_removeMissingAttrs ) { const attrs = arrayOrSingleItemToArray(attributes); for (const attr of attrs) { const val = sourceElement.getAttribute(attr); if (null !== val) { updateElement.setAttribute(attr, val); } else if (opt_removeMissingAttrs) { updateElement.removeAttribute(attr); } } }