* @param {DOMElement} outerNode * @return {?object}
(outerNode)
| 6332 | * @return {?object} |
| 6333 | */ |
| 6334 | function getOffsets(outerNode) { |
| 6335 | var selection = window.getSelection && window.getSelection(); |
| 6336 | |
| 6337 | if (!selection || selection.rangeCount === 0) { |
| 6338 | return null; |
| 6339 | } |
| 6340 | |
| 6341 | var anchorNode = selection.anchorNode, |
| 6342 | anchorOffset = selection.anchorOffset, |
| 6343 | focusNode = selection.focusNode, |
| 6344 | focusOffset = selection.focusOffset; |
| 6345 | |
| 6346 | // In Firefox, anchorNode and focusNode can be "anonymous divs", e.g. the |
| 6347 | // up/down buttons on an <input type="number">. Anonymous divs do not seem to |
| 6348 | // expose properties, triggering a "Permission denied error" if any of its |
| 6349 | // properties are accessed. The only seemingly possible way to avoid erroring |
| 6350 | // is to access a property that typically works for non-anonymous divs and |
| 6351 | // catch any error that may otherwise arise. See |
| 6352 | // https://bugzilla.mozilla.org/show_bug.cgi?id=208427 |
| 6353 | |
| 6354 | try { |
| 6355 | /* eslint-disable no-unused-expressions */ |
| 6356 | anchorNode.nodeType; |
| 6357 | focusNode.nodeType; |
| 6358 | /* eslint-enable no-unused-expressions */ |
| 6359 | } catch (e) { |
| 6360 | return null; |
| 6361 | } |
| 6362 | |
| 6363 | return getModernOffsetsFromPoints(outerNode, anchorNode, anchorOffset, focusNode, focusOffset); |
| 6364 | } |
| 6365 | |
| 6366 | /** |
| 6367 | * Returns {start, end} where `start` is the character/codepoint index of |
no test coverage detected