root/branches/quick_search/scripts.js

Revision 61, 2.3 KB (checked in by daris, 3 years ago)

quick search: extension is using jquery now + releasing 1.10

Line 
1
2var quick_search_popup_hovered = false;
3
4function quick_search_onload()
5{
6        if (!$('#navsearch'))
7                return;
8
9        $('#navsearch > a').attr('href', 'javascript:void(0);');
10        $('#navsearch > a').click(function() { quick_search(); });
11}
12
13/*
14        Shows popup
15*/
16function quick_search()
17{
18        var element = document.getElementById('navsearch').childNodes[0];
19        var pos = findPos(element);
20        pos[1] += element.offsetHeight + 3;
21
22        var popup = document.createElement('div');
23        popup.setAttribute('id', 'quick_search_popup');
24
25        popup.style.left =  pos[0] + 'px';
26        popup.style.top =  pos[1] + 'px';
27        document.body.appendChild(popup);
28
29        $('#quick_search_popup').mouseover(function () {quick_search_popup_hovered = true});
30        $('#quick_search_popup').mouseout(function () {quick_search_popup_hovered = false});
31
32        $('#quick_search_popup').html('<form id="quick_search_form" action="' + url_search + '" method="get"><div>' +
33                        '<input type="hidden" name="action" value="search" />' +
34                        '<input type="text" size="20" id="quick_search" name="keywords" /><input type="submit" value="' + lang_search['Submit search'] + '" name="search" />' +
35                        '</div><div>' + lang_search['Display results'] + ': ' +
36                        '<input type="radio" id="show_as_topics" name="show_as" value="topics" checked="checked" /><label for="show_as_topics">' + lang_search['Show as topics'] + '</label> ' +
37                        '<input type="radio" id="show_as_posts" name="show_as" value="posts" /><label for="show_as_posts">' + lang_search['Show as posts'] + '</label>' +
38                '</div></form>' +
39                '<a href="' + url_search + '">' + lang_search['Perform new search'] + '</a>');
40       
41        $('#quick_search').focus();
42        $('#quick_search').select();
43       
44        $('#quick_search_popup').fadeIn('fast');
45
46        quick_search_popup_hovered = true;
47
48        element.click = function() { $('#quick_search_popup').fadeOut('fast', function() {$(this).remove()}) };
49
50        $(document).click(function() {
51                        if (quick_search_popup_hovered == false)
52                                $('#quick_search_popup').fadeOut('fast', function() {$(this).remove()});
53                });
54}
55
56/*
57        Returns obj absolute position [x,y]
58*/
59function findPos(obj)
60{
61        var curleft = curtop = 0;
62        if (obj.offsetParent)
63        {
64                curleft = obj.offsetLeft;
65                curtop = obj.offsetTop;
66                while (obj = obj.offsetParent)
67                {
68                        curleft += obj.offsetLeft;
69                        curtop += obj.offsetTop;
70                }
71        }
72        return [curleft,curtop];
73}
Note: See TracBrowser for help on using the browser.