* @param {DOMElement} outerNode * @return {?object}
(outerNode)
| 5693 | * @return {?object} |
| 5694 | */ |
| 5695 | function getOffsets(outerNode) { |
| 5696 | var selection = window.getSelection && window.getSelection(); |
| 5697 | |
| 5698 | if (!selection || selection.rangeCount === 0) { |
| 5699 | return null; |
| 5700 | } |
| 5701 | |
| 5702 | var anchorNode = selection.anchorNode, |
| 5703 | anchorOffset = selection.anchorOffset, |
| 5704 | focusNode = selection.focusNode, |
| 5705 | focusOffset = selection.focusOffset; |
| 5706 | |
| 5707 | // In Firefox, anchorNode and focusNode can be "anonymous divs", e.g. the |
| 5708 | // up/down buttons on an <input type="number">. Anonymous divs do not seem to |
| 5709 | // expose properties, triggering a "Permission denied error" if any of its |
| 5710 | // properties are accessed. The only seemingly possible way to avoid erroring |
| 5711 | // is to access a property that typically works for non-anonymous divs and |
| 5712 | // catch any error that may otherwise arise. See |
| 5713 | // https://bugzilla.mozilla.org/show_bug.cgi?id=208427 |
| 5714 | |
| 5715 | try { |
| 5716 | /* eslint-disable no-unused-expressions */ |
| 5717 | anchorNode.nodeType; |
| 5718 | focusNode.nodeType; |
| 5719 | /* eslint-enable no-unused-expressions */ |
| 5720 | } catch (e) { |
| 5721 | return null; |
| 5722 | } |
| 5723 | |
| 5724 | return getModernOffsetsFromPoints(outerNode, anchorNode, anchorOffset, focusNode, focusOffset); |
| 5725 | } |
| 5726 | |
| 5727 | /** |
| 5728 | * Returns {start, end} where `start` is the character/codepoint index of |
no test coverage detected