substance
Version:
Substance is a JavaScript library for web-based content editing. It provides building blocks for realizing custom text editors and web-based publishing system. It is developed to power our online editing platform [Substance](http://substance.io).
25 lines (23 loc) • 764 B
JavaScript
export const BEFORE = -1
export const AFTER = 1
export const PARENT = -2
export const CHILD = 2
export default function compareDOMElementPosition (a, b) {
if (a.el._isBrowserDOMElement) {
const res = a.getNativeElement().compareDocumentPosition(b.getNativeElement())
if (res & window.Node.DOCUMENT_POSITION_CONTAINS) {
return CHILD
} else if (res & window.Node.DOCUMENT_POSITION_CONTAINED_BY) {
return PARENT
} else if (res & window.Node.DOCUMENT_POSITION_PRECEDING) {
return AFTER
} else if (res & window.Node.DOCUMENT_POSITION_FOLLOWING) {
return BEFORE
} else {
return 0
}
} else {
console.error('FIXME: compareDOMElementPosition() is not implemented for MemoryDOMElement.')
return 0
}
}