MCPcopy Create free account
hub / github.com/Nynxz/ComfyUI-IdeogramHelper / patchDOMProp

Function patchDOMProp

web/main.js:7149–7192  ·  view source on GitHub ↗
(el, key, value, parentComponent, attrName)

Source from the content-addressed store, hash-verified

7147 }
7148}
7149function patchDOMProp(el, key, value, parentComponent, attrName) {
7150 if (key === "innerHTML" || key === "textContent") {
7151 if (value != null) {
7152 el[key] = key === "innerHTML" ? unsafeToTrustedHTML(value) : value;
7153 }
7154 return;
7155 }
7156 const tag = el.tagName;
7157 if (key === "value" && tag !== "PROGRESS" && // custom elements may use _value internally
7158 !tag.includes("-")) {
7159 const oldValue = tag === "OPTION" ? el.getAttribute("value") || "" : el.value;
7160 const newValue = value == null ? (
7161 // #11647: value should be set as empty string for null and undefined,
7162 // but <input type="checkbox"> should be set as 'on'.
7163 el.type === "checkbox" ? "on" : ""
7164 ) : String(value);
7165 if (oldValue !== newValue || !("_value" in el)) {
7166 el.value = newValue;
7167 }
7168 if (value == null) {
7169 el.removeAttribute(key);
7170 }
7171 el._value = value;
7172 return;
7173 }
7174 let needRemove = false;
7175 if (value === "" || value == null) {
7176 const type = typeof el[key];
7177 if (type === "boolean") {
7178 value = includeBooleanAttr(value);
7179 } else if (value == null && type === "string") {
7180 value = "";
7181 needRemove = true;
7182 } else if (type === "number") {
7183 value = 0;
7184 needRemove = true;
7185 }
7186 }
7187 try {
7188 el[key] = value;
7189 } catch (e) {
7190 }
7191 needRemove && el.removeAttribute(attrName || key);
7192}
7193function addEventListener(el, event, handler, options) {
7194 el.addEventListener(event, handler, options);
7195}

Callers 1

patchPropFunction · 0.85

Calls 1

includeBooleanAttrFunction · 0.85

Tested by

no test coverage detected