* @getSelection: Gets the selection bounds of a focused textarea, input or * contentEditable node. * -@input: Look up selection bounds of this input * -@return {start: selectionStart, end: selectionEnd}
(input)
| 7149 | */ |
| 7150 | |
| 7151 | function getSelection(input) { |
| 7152 | var selection; |
| 7153 | |
| 7154 | if ('selectionStart' in input) { |
| 7155 | // Modern browser with input or textarea. |
| 7156 | selection = { |
| 7157 | start: input.selectionStart, |
| 7158 | end: input.selectionEnd |
| 7159 | }; |
| 7160 | } else { |
| 7161 | // Content editable or old IE textarea. |
| 7162 | selection = getOffsets(input); |
| 7163 | } |
| 7164 | |
| 7165 | return selection || { |
| 7166 | start: 0, |
| 7167 | end: 0 |
| 7168 | }; |
| 7169 | } |
| 7170 | /** |
| 7171 | * @setSelection: Sets the selection bounds of a textarea or input and focuses |
| 7172 | * the input. |
no test coverage detected