forked from bitcoin-dot-org/Bitcoin.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdevsearch.js
56 lines (51 loc) · 1.49 KB
/
devsearch.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
---
# This file is licensed under the MIT License (MIT) available on
# http://opensource.org/licenses/MIT.
---
"use strict";
var search_data = {{ site.devsearches_json }}
{% raw %}
// code adapted from http://jqueryui.com/autocomplete/#categories
// MIT license: https://jquery.org/license/
$.widget("custom.catcomplete", $.ui.autocomplete, {
_create: function() {
this._super();
this.widget().menu("option", "items", "> :not(.ui-autocomplete-category)");
},
_renderMenu: function(ul, items) {
var that = this,
currentCategory = "";
$.each(items, function(index, item) {
var li;
if (item.category !== currentCategory) {
ul.append("<li class='ui-autocomplete-category'>" + item.category + "</li>");
currentCategory = item.category;
}
li = that._renderItemData(ul, item);
if (item.category) {
li.attr("aria-label", item.category + " : " + item.label);
}
});
}
});
$(function() {
$("#glossary_term").catcomplete({
source: function(request, respond) {
var lang = $('html').attr('lang');
var term = request.term;
var results = search_data.filter(function(data) {
return (
(data.label.indexOf(term) !== -1 && data.lang === lang) || data.category !== "Glossary"
);
});
respond(results);
},
delay: 0,
minLength: 2,
autoFocus: true,
select: function(event, ui) {
location.href = ui.item.uri;
}
});
});
{% endraw %}