Skip to content

Commit 32a3f13

Browse files
authored
use bootstrap3-typeahead for search (#330)
1 parent 6b74acc commit 32a3f13

4 files changed

Lines changed: 32 additions & 375 deletions

File tree

app/public/js/app.js

Lines changed: 30 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -22,44 +22,35 @@ $('.documentation img').each(function (index, img) {
2222

2323
$('.documentation table').addClass('table table-striped table-bordered');
2424

25-
var quickSearchData = null;
26-
27-
var $quickSearchTypeahead = $('#quick-search-typeahead>input');
28-
$quickSearchTypeahead.typeahead({
29-
source: function (query, process) {
30-
if (quickSearchData) {
31-
process(quickSearchData.names);
32-
} else {
33-
var url = $quickSearchTypeahead.attr('data-action');
34-
35-
$.get(url, {}, function (data) {
36-
quickSearchData = data;
37-
process(quickSearchData.names);
25+
var $quickSearchTypeahead = $('#quick-search-typeahead').find('>input');
26+
$quickSearchTypeahead.on("focus", function () {
27+
var url = $quickSearchTypeahead.attr('data-action');
28+
$.get(url, {}, function (quickSearchData) {
29+
$quickSearchTypeahead.typeahead({
30+
source: quickSearchData.names,
31+
items: 'all',
32+
displayText: function (item) {
33+
// get text to display in quick search box
34+
35+
var trailingEmLoc = item.indexOf('<em>');
36+
if (trailingEmLoc !== -1) {
37+
item = item.substring(0, trailingEmLoc);
38+
}
39+
// return display text
40+
return $.trim(item)
41+
},
42+
afterSelect: function (item) {
43+
// Track the search
44+
_paq.push(['trackSiteSearch', item, false, false]);
45+
46+
// get URL to go to
47+
var itemIndex = quickSearchData.names.indexOf(item);
48+
if (itemIndex !== -1) {
49+
window.location.href = quickSearchData.urls[itemIndex];
50+
}
51+
52+
}
3853
});
39-
}
40-
},
41-
items: -1,
42-
updater: function (item) {
43-
// get text to display in quick search box
44-
var displayText = item;
45-
46-
var trailingEmLoc = displayText.indexOf('<em>');
47-
if (trailingEmLoc != -1) {
48-
displayText = displayText.substring(0, trailingEmLoc);
49-
}
50-
51-
// Track the search
52-
_paq.push(['trackSiteSearch', displayText, false, false]);
53-
54-
// get URL to go to
55-
var itemIndex = quickSearchData.names.indexOf(item);
56-
if (itemIndex != -1) {
57-
window.location.href = quickSearchData.urls[itemIndex];
58-
}
59-
60-
// return display text
61-
return $.trim(displayText);
62-
}
63-
});
64-
54+
});
55+
});
6556
});

0 commit comments

Comments
 (0)