10 examples of 'jquery lost focus' in JavaScript

Every line of 'jquery lost focus' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
160function onBlur(e) {
161 if (!isValidFocusTarget(e.target)) {
162 return;
163 }
164
165 if (
166 e.target.classList.contains('focus-visible') ||
167 e.target.hasAttribute('data-focus-visible-added')
168 ) {
169 // To detect a tab/window switch, we look for a blur event followed
170 // rapidly by a visibility change.
171 // If we don't see a visibility change within 100ms, it's probably a
172 // regular focus change.
173 hadFocusVisibleRecently = true;
174 window.clearTimeout(hadFocusVisibleRecentlyTimeout);
175 hadFocusVisibleRecentlyTimeout = window.setTimeout(function() {
176 hadFocusVisibleRecently = false;
177 window.clearTimeout(hadFocusVisibleRecentlyTimeout);
178 }, 100);
179 removeFocusVisibleClass(e.target);
180 }
181}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

42function detectKeyboardFocus(instance, element, callback) {
43 var attempt = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
44
45 process.env.NODE_ENV !== "production" ? (0, _warning2.default)(instance.keyboardFocusCheckTime, 'Material-UI: missing instance.keyboardFocusCheckTime') : void 0;
46 process.env.NODE_ENV !== "production" ? (0, _warning2.default)(instance.keyboardFocusMaxCheckTimes, 'Material-UI: missing instance.keyboardFocusMaxCheckTimes') : void 0;
47
48 instance.keyboardFocusTimeout = setTimeout(function () {
49 var doc = (0, _ownerDocument2.default)(element);
50
51 if (focusKeyPressed() && (doc.activeElement === element || (0, _contains2.default)(element, doc.activeElement))) {
52 callback();
53 } else if (attempt < instance.keyboardFocusMaxCheckTimes) {
54 detectKeyboardFocus(instance, element, callback, attempt + 1);
55 }
56 }, instance.keyboardFocusCheckTime);
57}
3public SetFocus(element: HTMLElement): void {
4 element.focus();
5}
98handleFocusLost() {
99 const that = this;
100 setTimeout(() => {
101 if (!document.activeElement.classList.contains('keyboard-button')
102 && !document.activeElement.classList.contains('keyboard')
103 && !document.activeElement.classList.contains('keyboard-row')
104 && !document.activeElement.classList.contains('react-draggable-transparent-selection')) {
105
106 if (that.props.onBlur) {
107 that.props.onBlur(that.props.value);
108 }
109
110 that.setState({ ...that.state, showKeyboard: false });
111 }
112 }, 0);
113}
9function focus(element) {
10 if (!isFocusable(element)) {
11 return false;
12 }
13
14 element.focus();
15 return true;
16}
14function _focus(input: HTMLInputElement, handler: EventHandler): void {
15 const focus = (): void => {
16 input.focus();
17
18 const end = input.value.length;
19 try {
20 if (typeof input.selectionStart !== "undefined") {
21 input.selectionStart = end;
22 input.selectionEnd = end;
23 return;
24 }
25 } catch (e) {
26 //ignore
27 }
28 // eslint-disable-next-line @typescript-eslint/no-explicit-any
29 if ((document as any).selection) {
30 // eslint-disable-next-line @typescript-eslint/no-explicit-any
31 const range = (input as any).createTextRange();
32 range.collapse();
33 range.moveEnd("character", end);
34 range.moveStart("character", end);
35 range.select();
36 }
37 };
38 handler.tryWithOffEvents(input, "blur", () => {
39 focus();
40 });
41}
1553_onFocus(event, element) {
1554 // NOTE(mmalerba): We currently set the classes based on the focus origin of the most recent
1555 // focus event affecting the monitored element. If we want to use the origin of the first event
1556 // instead we should check for the cdk-focused class here and return if the element already has
1557 // it. (This only matters for elements that have includesChildren = true).
1558 // If we are not counting child-element-focus as focused, make sure that the event target is the
1559 // monitored element itself.
1560 const /** @type {?} */ elementInfo = this._elementInfo.get(element);
1561 if (!elementInfo || (!elementInfo.checkChildren && element !== event.target)) {
1562 return;
1563 }
1564 // If we couldn't detect a cause for the focus event, it's due to one of three reasons:
1565 // 1) The window has just regained focus, in which case we want to restore the focused state of
1566 // the element from before the window blurred.
1567 // 2) It was caused by a touch event, in which case we mark the origin as 'touch'.
1568 // 3) The element was programmatically focused, in which case we should mark the origin as
1569 // 'program'.
1570 if (!this._origin) {
1571 if (this._windowFocused && this._lastFocusOrigin) {
1572 this._origin = this._lastFocusOrigin;
1573 }
1574 else if (this._wasCausedByTouch(event)) {
1575 this._origin = 'touch';
1576 }
1577 else {
1578 this._origin = 'program';
1579 }
1580 }
1581 this._setClasses(element, this._origin);
1582 elementInfo.subject.next(this._origin);
1583 this._lastFocusOrigin = this._origin;
1584 this._origin = null;
1585}
74private focusInHandler(e: Event) {
75 if (
76 e.target instanceof HTMLElement &&
77 !(e.target instanceof HTMLInputElement) && // child input elements don't count as editor focus
78 isChildElement(this._editorElement, e.target)
79 ) {
80 this._hasFocus = true;
81 } else {
82 this._isSkipping = true;
83 this._hasFocus = false;
84 }
85}
79function loseFocus(obj){
80 alert(obj);
81}
77function handleFocus(event: FocusEvent) {
78 window.clearTimeout(timeout);
79 timeout = undefined;
80 window.removeEventListener("focus", handleFocus, true);
81 focusAdded = false;
82
83 if (!isKeyboardInput(event.target as Element)) {
84 return;
85 }
86
87 timeout = window.setTimeout(() => {
88 timeout = undefined;
89 }, KEYBOARD_WAIT);
90}

Related snippets