[gitea] Avoid showing unnecessary JS errors when there are elements with different origin on the page (#29081)

Try to fix #29080

(cherry picked from commit f290c24d286b996ac6b512f49a30aa5aef1a2dbe)
This commit is contained in:
wxiaoguang 2024-02-08 10:42:18 +08:00 committed by Earl Warren
parent 73e32eae5b
commit 51c6103195
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
3 changed files with 19 additions and 9 deletions

View file

@ -59,6 +59,17 @@ export function onDomReady(cb) {
}
}
// checks whether an element is owned by the current document, and whether it is a document fragment or element node
// if it is, it means it is a "normal" element managed by us, which can be modified safely.
export function isDocumentFragmentOrElementNode(el) {
try {
return el.ownerDocument === document && el.nodeType === Node.ELEMENT_NODE || el.nodeType === Node.DOCUMENT_FRAGMENT_NODE;
} catch {
// in case the el is not in the same origin, then the access to nodeType would fail
return false;
}
}
// autosize a textarea to fit content. Based on
// https://github.com/github/textarea-autosize
// ---------------------------------------------------------------------