PageSourceSearch

https://newchurchvineyard.org/wp-content/plugins/vineyard-plugin/resources/js/focuslost.js?ver=5.0.3

js newchurchvineyard.org collected 2026-09-26 21:03:34 UTC 2,314 bytes, 68 lines download raw bytes

1/*
2 * See http://stackoverflow.com/questions/3088738/jquery-need-alternative-to-focusout
3 * This may need some tweaks for performance or compatibility with
4 * newer jQuery or the like
5 *
6 * also
7 */
8
9(function($) {
10    // will store the last focus chain
11    var currentFocusChain = $();
12    // stores a reference to any DOM objects we want to watch focus for
13    var focusWatch = [];
14
15    function checkFocus() {
16
17        // [GSL change] If possible, ignore event if the entirewindow lost focus.
18        // In that case we'll test again once focus has returned.
19        if (typeof document.hasFocus !== 'undefined') {
20            if ( ! document.hasFocus() ) {
21                $(window).one('focus', checkFocus);
22                return;
23            }
24        }
25
26
27        var newFocusChain = $(":focus").parents().andSelf();
28        // elements in the old focus chain that aren't in the new focus chain...
29        var lostFocus = currentFocusChain.not(newFocusChain.get());
30        lostFocus.each(function() {
31            if ($.inArray(this, focusWatch) != -1) {
32                $(this).trigger('focuslost');
33            }
34        });
35
36        var gainedFocus = newFocusChain.not(currentFocusChain.get());
37        gainedFocus.each(function() {
38            if ($.inArray(this, focusWatch) != -1) {
39                $(this).trigger('focusgained');
40            }
41        });
42
43        currentFocusChain = newFocusChain;
44    }
45    // bind to the focus/blur event on all elements:
46    $(document).ready( function () {
47        $("body").on('focus blur', '*', function(e) {
48            // wait until the next free loop to process focus change
49            // when 'blur' is fired, focus will be unset
50            setTimeout(checkFocus, 0);
51        });
52    });
53
54    $.fn.focuslost = function(fn) {
55        return this.each(function() {
56            // tell the live handler we are watching this event
57            if ($.inArray(this, focusWatch) == -1) focusWatch.push(this);
58            $(this).bind('focuslost', fn);
59        });
60    };
61    $.fn.focusgained = function(fn) {
62        return this.each(function() {
63            // tell the live handler we are watching this event
64            if ($.inArray(this, focusWatch) == -1) focusWatch.push(this);
65            $(this).bind('focusgained', fn);
66        });
67    };
68})(jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.