* @param {DOMElement} outerNode * @return {?object}
(outerNode)
| 6367 | * @return {?object} |
| 6368 | */ |
| 6369 | function getOffsets(outerNode) { |
| 6370 | var selection = window.getSelection && window.getSelection(); |
| 6371 | |
| 6372 | if (!selection || selection.rangeCount === 0) { |
| 6373 | return null; |
| 6374 | } |
| 6375 | |
| 6376 | var anchorNode = selection.anchorNode, |
| 6377 | anchorOffset = selection.anchorOffset, |
| 6378 | focusNode = selection.focusNode, |
| 6379 | focusOffset = selection.focusOffset; |
| 6380 | |
| 6381 | // In Firefox, anchorNode and focusNode can be "anonymous divs", e.g. the |
| 6382 | // up/down buttons on an <input type="number">. Anonymous divs do not seem to |
| 6383 | // expose properties, triggering a "Permission denied error" if any of its |
| 6384 | // properties are accessed. The only seemingly possible way to avoid erroring |
| 6385 | // is to access a property that typically works for non-anonymous divs and |
| 6386 | // catch any error that may otherwise arise. See |
| 6387 | // https://bugzilla.mozilla.org/show_bug.cgi?id=208427 |
| 6388 | |
| 6389 | try { |
| 6390 | /* eslint-disable no-unused-expressions */ |
| 6391 | anchorNode.nodeType; |
| 6392 | focusNode.nodeType; |
| 6393 | /* eslint-enable no-unused-expressions */ |
| 6394 | } catch (e) { |
| 6395 | return null; |
| 6396 | } |
| 6397 | |
| 6398 | return getModernOffsetsFromPoints(outerNode, anchorNode, anchorOffset, focusNode, focusOffset); |
| 6399 | } |
| 6400 | |
| 6401 | /** |
| 6402 | * Returns {start, end} where `start` is the character/codepoint index of |
no test coverage detected