* @param {DOMElement} outerNode * @return {?object}
(outerNode)
| 6845 | */ |
| 6846 | |
| 6847 | function getOffsets(outerNode) { |
| 6848 | var ownerDocument = outerNode.ownerDocument; |
| 6849 | var win = ownerDocument && ownerDocument.defaultView || window; |
| 6850 | var selection = win.getSelection && win.getSelection(); |
| 6851 | |
| 6852 | if (!selection || selection.rangeCount === 0) { |
| 6853 | return null; |
| 6854 | } |
| 6855 | |
| 6856 | var anchorNode = selection.anchorNode, |
| 6857 | anchorOffset = selection.anchorOffset, |
| 6858 | focusNode = selection.focusNode, |
| 6859 | focusOffset = selection.focusOffset; // In Firefox, anchorNode and focusNode can be "anonymous divs", e.g. the |
| 6860 | // up/down buttons on an <input type="number">. Anonymous divs do not seem to |
| 6861 | // expose properties, triggering a "Permission denied error" if any of its |
| 6862 | // properties are accessed. The only seemingly possible way to avoid erroring |
| 6863 | // is to access a property that typically works for non-anonymous divs and |
| 6864 | // catch any error that may otherwise arise. See |
| 6865 | // https://bugzilla.mozilla.org/show_bug.cgi?id=208427 |
| 6866 | |
| 6867 | try { |
| 6868 | /* eslint-disable no-unused-expressions */ |
| 6869 | anchorNode.nodeType; |
| 6870 | focusNode.nodeType; |
| 6871 | /* eslint-enable no-unused-expressions */ |
| 6872 | } catch (e) { |
| 6873 | return null; |
| 6874 | } |
| 6875 | |
| 6876 | return getModernOffsetsFromPoints(outerNode, anchorNode, anchorOffset, focusNode, focusOffset); |
| 6877 | } |
| 6878 | /** |
| 6879 | * Returns {start, end} where `start` is the character/codepoint index of |
| 6880 | * (anchorNode, anchorOffset) within the textContent of `outerNode`, and |
no test coverage detected