1jQuery(function () {
2    if (!JSINFO.plugin.usercontact.users_namespace) {
3        return;
4    }
5    var regex = new RegExp(JSINFO.plugin.usercontact.users_namespace + '$');
6
7    /**
8     * Create and show the overlay
9     *
10     * @param $link object The jQuery object of the link to the user page
11     */
12    function show_overlay($link) {
13        if (!$link.usercontact_popup) {
14            $link.usercontact_popup = dw_page.insituPopup($link, $link.usercontact_id);
15            $link.usercontact_popup.addClass('usercontact_overlay');
16            $link.usercontact_popup.css('visibility', 'hidden');
17            $link.usercontact_popup.load(
18                DOKU_BASE + 'lib/exe/ajax.php',
19                {
20                    call: 'plugin_usercontact',
21                    name: $link.usercontact_name,
22                },
23                function (text, status, jqxhr) {
24                    if (jqxhr.status >= 400) {
25                        return;
26                    }
27                    $link.usercontact_popup.css('visibility', 'visible');
28                }
29            );
30        }
31        $link.usercontact_popup.show().position({my: 'left top', at: 'left bottom', of: $link});
32    }
33
34    /**
35     * Find all links to user pages
36     *
37     * Adds events and info to the links.
38     *
39     * @type {number}
40     */
41    var links = 0;
42    jQuery('.dokuwiki a').each(function () {
43        var $link = jQuery(this);
44        var href = $link.attr('href');
45        if (!href) return;
46        var match = href.replace(/\//g, ':').match(regex);
47        if (!match) return;
48
49        $link.usercontact_name = match[1];
50        $link.usercontact_id = 'usercontact_' + (links++);
51
52        $link.mouseover(function () {
53            $link.usercontact_timer = window.setTimeout(
54                function () {
55                    console.log($link.usercontact_name);
56                    show_overlay($link);
57                    $link.usercontact_timer = null;
58                },
59                300
60            );
61        });
62
63        $link.mouseout(function () {
64            if ($link.usercontact_timer) window.clearTimeout($link.usercontact_timer);
65            $link.usercontact_timer = null;
66        });
67    });
68});
69