Home | History | Annotate | Download | only in js

Lines Matching refs:element

5 function focus(element) {
6 // Focus the target element in order to send keys to it.
7 // First, the currently active element is blurred, if it is different from
8 // the target element. We do not want to blur an element unnecessarily,
10 // element.
11 // Secondly, we focus the target element.
12 // Thirdly, if the target element is newly focused and is a text input, we
14 // Fourthly, we check if the new active element is the target element. If not,
17 // - |document.activeElement| is the currently focused element, or body if
18 // no element is focused
19 // - Even if |document.hasFocus()| returns true and the active element is
20 // the body, sometimes we still need to focus the body element for send
26 var doc = element.ownerDocument || element;
28 if (element != prevActiveElement && prevActiveElement)
30 element.focus();
31 if (element != prevActiveElement && element.value &&
32 element.value.length && element.setSelectionRange) {
34 element.setSelectionRange(element.value.length, element.value.length);
41 if (element != doc.activeElement)
42 throw new Error('cannot focus element');