Skip to content

Commit ed5a1d4

Browse files
committed
Make tree.hasFocus() more robust
1 parent 002d207 commit ed5a1d4

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# 2.33.1-0 / Unreleased
2+
* tree.hasFocus() more reliable.
23

34
# 2.33.0 / 2019-10-29
45
* [Added] event `preInit` (fired before nodes are loaded).

src/jquery.fancytree.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3437,7 +3437,21 @@
34373437
* @returns {boolean}
34383438
*/
34393439
hasFocus: function() {
3440-
return !!this._hasFocus;
3440+
var ae = document.activeElement,
3441+
hasFocus = !!(
3442+
ae && $(ae).closest(".fancytree-container").length
3443+
);
3444+
3445+
if (hasFocus !== !!this._hasFocus) {
3446+
this.warn(
3447+
"hasFocus(): fix inconsistent container state, now: " +
3448+
hasFocus
3449+
);
3450+
this._hasFocus = hasFocus;
3451+
this.$container.toggleClass("fancytree-treefocus", hasFocus);
3452+
}
3453+
return hasFocus;
3454+
// return !!this._hasFocus;
34413455
},
34423456
/** Write to browser console if debugLevel >= 3 (prepending tree name)
34433457
* @param {*} msg string or object or array of such

0 commit comments

Comments
 (0)