summaryrefslogtreecommitdiff
path: root/plugins/Autocomplete/Autocomplete.js
blob: c3f022702ac0fb107e11a29d67ec859df3be6306 (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
$(document).ready(function(){
    function fullName(row) {
        if (typeof row.fullname == "string" && row.fullname != '') {
            return row.nickname + ' (' + row.fullname + ')';
        } else {
            return row.nickname;
        }
    }
    $('#notice_data-text').autocomplete($('address .url')[0].href+'main/autocomplete/suggest', {
        multiple: true,
        multipleSeparator: " ",
        minChars: 1,
        formatItem: function(row, i, max){
            row = eval("(" + row + ")");
            // the display:inline is because our INSANE stylesheets
            // override the standard display of all img tags for no
            // good reason.
            var div = $('<div><img style="display:inline; vertical-align: middle"> <span></span></div>')
                .find('img').attr('src', row.avatar).end()
                .find('span').text(fullName(row)).end()
            return div.html();
        },
        formatMatch: function(row, i, max){
            row = eval("(" + row + ")");
            return row.nickname;
        },
        formatResult: function(row){
            row = eval("(" + row + ")");
            switch(row.type)
            {
                case 'user':
                    return '@' + row.nickname;
                case 'group':
                    return '!' + row.nickname;
            }
        }
    });
});