src/modules/inactive/commands/aryeh_implementation.js
function getPosition(nodeA, offsetA, nodeB, offsetB) {
	// "If node A is the same as node B, return equal if offset A equals offset
	// B, before if offset A is less than offset B, and after if offset A is
	// greater than offset B."
	if (nodeA == nodeB) {
		if (offsetA == offsetB) {
			return "equal";
		}
		if (offsetA < offsetB) {
			return "before";
		}
		if (offsetA > offsetB) {
			return "after";
		}
	}

	// "If node A is after node B in tree order, compute the position of (node
	// B, offset B) relative to (node A, offset A). If it is before, return
	// after. If it is after, return before."
	if (nodeB.compareDocumentPosition(nodeA) & Node.DOCUMENT_POSITION_FOLLOWING) {
		var pos = getPosition(nodeB, offsetB, nodeA, offsetA);
		if (pos == "before") {
			return "after";
		}
		if (pos == "after") {
			return "before";
		}
	}

	// "If node A is an ancestor of node B:"
	if (nodeB.compareDocumentPosition(nodeA) & Node.DOCUMENT_POSITION_CONTAINS) {
		// "Let child equal node B."
		var child = nodeB;

		// "While child is not a child of node A, set child to its parent."
		while (child.parentNode != nodeA) {
			child = child.parentNode;
		}

		// "If the index of child is less than offset A, return after."
		if (getNodeIndex(child) < offsetA) {
			return "after";
		}
	}

	// "Return before."
	return "before";
}
function getPosition(nodeA, offsetA, nodeB, offsetB) {
	// "If node A is the same as node B, return equal if offset A equals offset
	// B, before if offset A is less than offset B, and after if offset A is
	// greater than offset B."
	if (nodeA == nodeB) {
		if (offsetA == offsetB) {
			return "equal";
		}
		if (offsetA < offsetB) {
			return "before";
		}
		if (offsetA > offsetB) {
			return "after";
		}
	}

	// "If node A is after node B in tree order, compute the position of (node
	// B, offset B) relative to (node A, offset A). If it is before, return
	// after. If it is after, return before."
	if (nodeB.compareDocumentPosition(nodeA) & Node.DOCUMENT_POSITION_FOLLOWING) {
		var pos = getPosition(nodeB, offsetB, nodeA, offsetA);
		if (pos == "before") {
			return "after";
		}
		if (pos == "after") {
			return "before";
		}
	}

	// "If node A is an ancestor of node B:"
	if (nodeB.compareDocumentPosition(nodeA) & Node.DOCUMENT_POSITION_CONTAINS) {
		// "Let child equal node B."
		var child = nodeB;

		// "While child is not a child of node A, set child to its parent."
		while (child.parentNode != nodeA) {
			child = child.parentNode;
		}

		// "If the index of child is less than offset A, return after."
		if (getNodeIndex(child) < offsetA) {
			return "after";
		}
	}

	// "Return before."
	return "before";
}
function getPosition ( nodeA , offsetA , nodeB , offsetB ) { // "If node A is the same as node B, return equal if offset A equals offset // B, before if offset A is less than offset B, and after if offset A is // greater than offset B." if ( nodeA == nodeB ) { if ( offsetA == offsetB ) { return "equal" ; } if ( offsetA < offsetB ) { return "before" ; } if ( offsetA > offsetB ) { return "after" ; } } // "If node A is after node B in tree order, compute the position of (node // B, offset B) relative to (node A, offset A). If it is before, return // after. If it is after, return before." if ( nodeB . compareDocumentPosition ( nodeA ) & Node . DOCUMENT_POSITION_FOLLOWING ) { var pos = getPosition ( nodeB , offsetB , nodeA , offsetA ) ; if ( pos == "before" ) { return "after" ; } if ( pos == "after" ) { return "before" ; } } // "If node A is an ancestor of node B:" if ( nodeB . compareDocumentPosition ( nodeA ) & Node . DOCUMENT_POSITION_CONTAINS ) { // "Let child equal node B." var child = nodeB ; // "While child is not a child of node A, set child to its parent." while ( child . parentNode != nodeA ) { child = child . parentNode ; } // "If the index of child is less than offset A, return after." if ( getNodeIndex ( child ) < offsetA ) { return "after" ; } } // "Return before." return "before" ; }
The position of two boundary points relative to one another, as defined by
DOM Range.
The position of two boundary points relative to one another as defined by DOM Range .