summaryrefslogtreecommitdiff
path: root/static/saclay/js/search.js
blob: 90495a74d81aac8557f20ce3bf00bf60ec96bca0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
function load_search_box(){
    if (!search_url) return;
    $.ajax({url: search_url}).done(function( data ) {
        $("#search-box").html(data);
    });
}

function haystack_search(evt, page){
    search_result = new Array();
    $('#categories').find('#ul_categories > li > input').attr("checked", false);
    if (!$('#id_q').val()){
        $('.ac-results').remove();
        $('#search-result').html('').show('slow');
        return false;
    }

    var value = $('#id_q').val().replace(/#/g , "%23");
    var c_url = search_url + "?q=" + value;
    if (page){
        c_url += '&page=' + page;
    }
    $.get(c_url).done(function( data ) {
        $('.ac-results').remove();
        $('#search-result').html(data).show('slow');
    });
    return false;
}

function welcome_search(){
    if ($("#welcome").is(":visible") && $("#id_welcome_search").val()) {
        $("#id_q").val($("#id_welcome_search").val());
        $("#action-search").click();
        $('#welcome').dialog('close');
        $("#haystack-search").click();
        return true;
    }
}

// disable enter
$(window).keydown(function(event){
    if (event.keyCode == 13) {
        event.preventDefault();
        if (!welcome_search()){
            $("#haystack-search").click();
        }
        return false;
    }
});