-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathdevpi-semantic.js
More file actions
60 lines (51 loc) · 1.95 KB
/
devpi-semantic.js
File metadata and controls
60 lines (51 loc) · 1.95 KB
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
function onIFrameLoaded(iframe) {
iframe.style.minHeight = iframe.contentWindow.document.body.scrollHeight + 'px';
iframe.contentWindow.focus();
}
$(function() {
// Tooltips
$('.icon.tooltip').popup();
searchURL = $('#search').attr('action');
// Search
$('.ui.search').search({
type: 'category',
minCharacters : 3,
apiSettings: {
beforeXHR: function(xhr) {
xhr.setRequestHeader('Accept', 'application/json');
xhr.setRequestHeader('Content-Type', 'application/json');
return xhr;
},
onResponse: function(devpiResponse) {
var response = {results : {}};
// translate devpi API response to work with search
$.each(devpiResponse.result.items, function(index, item) {
var branch = item.data.user + '/' + item.data.index;
// create new language category
if(response.results[branch] === undefined) {
response.results[branch] = {
name : '<i class="icon fork"></i>' + branch,
results : []
};
}
response.results[branch].results.push({
title: item.title,
url: item.url,
});
});
if (devpiResponse.result.info.pagecount > 1) {
response.action = {
url: searchURL + '?query=' + devpiResponse.result.query,
"text": 'View all '+ devpiResponse.result.info.total +' results'
};
}
return response;
},
url: searchURL + '?query={query}'
},
});
// Tox results accordions
$('.toxresult .ui.accordion').accordion({
exclusive: false
});
})