/
site_suggestions.js
63 lines (59 loc) 路 2.56 KB
/
site_suggestions.js
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Init site search suggestions and populate the suggestions container.
(function() {
// AMO search init.
$('#search #search-q').searchSuggestions($('#site-search-suggestions'),
processResults, 'AMO');
function processResults(settings) {
if (!settings || !settings.category) {
return;
}
// Update the 'Search add-ons for <b>"{addon}"</b>' text.
settings['$results'].find('p b').html(format('"{0}"',
settings.searchTerm));
var li_item = template(
'<li><a href="{url}"><span {cls} {icon}>{name}</span>{subtitle}</a></li>'
);
$.ajaxCache({
url: settings['$results'].attr('data-src'),
data: settings['$form'].serialize() + '&cat=' + settings.category,
newItems: function(formdata, items) {
var eventName;
if (items !== undefined) {
var ul = '';
$.each(items, function(i, item) {
var d = {
url: escape_(item.url) || '#',
icon: '',
cls: '',
subtitle: ''
};
if (item.icons && item.icons['32']) {
d.icon = format(
'style="background-image:url({0})"',
escape_(item.icons['32'])
);
}
if (item.cls) {
d.cls = format('class="{0}"',
escape_(item.cls));
if (item.cls == 'cat') {
d.subtitle = format(
' <em class="subtitle">{0}</em>',
gettext('Category')
);
}
}
if (item.name) {
d.name = escape_(item.name);
// Append the item only if it has a name.
ul += li_item(d);
}
});
settings['$results'].find('ul').html(ul);
}
settings['$results'].trigger('highlight', [settings.searchTerm])
.trigger('resultsUpdated', [items]);
}
});
}
})();