* @restoreSelection: If any selection information was potentially lost, * restore it. This is useful when performing operations that could remove dom * nodes and place them back in, resulting in focus being lost.
(priorSelectionInformation)
| 6660 | * nodes and place them back in, resulting in focus being lost. |
| 6661 | */ |
| 6662 | function restoreSelection(priorSelectionInformation) { |
| 6663 | var curFocusedElem = getActiveElement(); |
| 6664 | var priorFocusedElem = priorSelectionInformation.focusedElem; |
| 6665 | var priorSelectionRange = priorSelectionInformation.selectionRange; |
| 6666 | if (curFocusedElem !== priorFocusedElem && isInDocument(priorFocusedElem)) { |
| 6667 | if (hasSelectionCapabilities(priorFocusedElem)) { |
| 6668 | setSelection(priorFocusedElem, priorSelectionRange); |
| 6669 | } |
| 6670 | |
| 6671 | // Focusing a node can change the scroll position, which is undesirable |
| 6672 | var ancestors = []; |
| 6673 | var ancestor = priorFocusedElem; |
| 6674 | while (ancestor = ancestor.parentNode) { |
| 6675 | if (ancestor.nodeType === ELEMENT_NODE) { |
| 6676 | ancestors.push({ |
| 6677 | element: ancestor, |
| 6678 | left: ancestor.scrollLeft, |
| 6679 | top: ancestor.scrollTop |
| 6680 | }); |
| 6681 | } |
| 6682 | } |
| 6683 | |
| 6684 | priorFocusedElem.focus(); |
| 6685 | |
| 6686 | for (var i = 0; i < ancestors.length; i++) { |
| 6687 | var info = ancestors[i]; |
| 6688 | info.element.scrollLeft = info.left; |
| 6689 | info.element.scrollTop = info.top; |
| 6690 | } |
| 6691 | } |
| 6692 | } |
| 6693 | |
| 6694 | /** |
| 6695 | * @getSelection: Gets the selection bounds of a focused textarea, input or |
no test coverage detected