* @param {DOMElement} outerNode * @return {?object}
(outerNode)
| 6583 | * @return {?object} |
| 6584 | */ |
| 6585 | function getOffsets(outerNode) { |
| 6586 | var selection = window.getSelection && window.getSelection(); |
| 6587 | |
| 6588 | if (!selection || selection.rangeCount === 0) { |
| 6589 | return null; |
| 6590 | } |
| 6591 | |
| 6592 | var anchorNode = selection.anchorNode, |
| 6593 | anchorOffset = selection.anchorOffset, |
| 6594 | focusNode = selection.focusNode, |
| 6595 | focusOffset = selection.focusOffset; |
| 6596 | |
| 6597 | // In Firefox, anchorNode and focusNode can be "anonymous divs", e.g. the |
| 6598 | // up/down buttons on an <input type="number">. Anonymous divs do not seem to |
| 6599 | // expose properties, triggering a "Permission denied error" if any of its |
| 6600 | // properties are accessed. The only seemingly possible way to avoid erroring |
| 6601 | // is to access a property that typically works for non-anonymous divs and |
| 6602 | // catch any error that may otherwise arise. See |
| 6603 | // https://bugzilla.mozilla.org/show_bug.cgi?id=208427 |
| 6604 | |
| 6605 | try { |
| 6606 | /* eslint-disable no-unused-expressions */ |
| 6607 | anchorNode.nodeType; |
| 6608 | focusNode.nodeType; |
| 6609 | /* eslint-enable no-unused-expressions */ |
| 6610 | } catch (e) { |
| 6611 | return null; |
| 6612 | } |
| 6613 | |
| 6614 | return getModernOffsetsFromPoints(outerNode, anchorNode, anchorOffset, focusNode, focusOffset); |
| 6615 | } |
| 6616 | |
| 6617 | /** |
| 6618 | * Returns {start, end} where `start` is the character/codepoint index of |
no test coverage detected