setAttributes method
void
setAttributes(
- DOMElement domElement,
- T element,
- DOMTreeMap<
T> treeMap, { - bool preserveClass = false,
- bool preserveStyle = false,
Implementation
void setAttributes(DOMElement domElement, T element, DOMTreeMap<T> treeMap,
{bool preserveClass = false, bool preserveStyle = false}) {
for (var attrName in domElement.attributesNames) {
var attr = domElement.getAttribute(attrName)!;
var attrVal = attr.getValue(_domContext, treeMap);
if (preserveClass && attrName == 'class') {
var prev = getAttribute(element, attrName);
if (prev != null && prev.isNotEmpty) {
attrVal =
attrVal != null && attrVal.isNotEmpty ? '$prev $attrVal' : prev;
}
} else if (preserveStyle && attrName == 'style') {
var prev = getAttribute(element, attrName);
if (prev != null && prev.isNotEmpty) {
if (attrVal != null && attrVal.isNotEmpty) {
attrVal =
!prev.endsWith(';') ? '$prev; $attrVal' : '$prev $attrVal';
} else {
attrVal = prev;
}
}
} else if ((attrName == 'src' || attrName == 'href') &&
attrVal != null &&
attrVal.isNotEmpty) {
var attrVal2 = resolveSource(attrVal);
if (attrVal != attrVal2) {
setAttribute(element, '$attrName-original', attrVal);
attrVal = attrVal2;
}
} else if (attr.isBoolean && DOMAttribute.isBooleanAttribute(attrName)) {
if (attrVal != 'true') {
continue;
}
}
setAttribute(element, attrName, attrVal);
}
}