-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsearch.js
94 lines (81 loc) · 2.77 KB
/
search.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
goog.provide('jvjsdoc');
goog.require('goog.dom');
goog.require('goog.dom.classes');
goog.require('goog.events');
goog.require('goog.events.EventType');
goog.require('goog.events.KeyHandler');
goog.require('goog.ui.ac');
goog.require('goog.ui.ac.AutoComplete.EventType');
/**
* Initialise the javascript supported search box.
*/
jvjsdoc.enableSearch = function() {
var search = goog.dom.getElement('search');
var go = goog.dom.getElement('go');
var xRef = window['jvXRef'];
var baseDir = window['jvBaseDir'];
var keys = [];
for (var key in xRef) {
keys.push(key);
}
var ac = goog.ui.ac.createSimpleAutoComplete(keys, search);
ac.setMaxMatches(20);
goog.events.listen(ac, goog.ui.ac.AutoComplete.EventType.UPDATE,
function(e) { go.click(); });
goog.events.listen(search, goog.events.EventType.KEYDOWN,
function(e) {
if (e.keyCode == 13) {
setTimeout(function() {
go.click();
}, 1);
}
});
goog.events.listen(go, goog.events.EventType.CLICK,
function(e) {
var key = search.value;
var next = xRef[key];
if (next) {
window.location.href = baseDir + '/' + next;
} else {
alert('unknown symbol ' + key);
}
return true;
});
var allKeys = new goog.events.KeyHandler(document);
goog.events.listen(allKeys, 'key',
function(e) {
if (e.target != search &&
e.charCode === "f".charCodeAt(0) &&
!e.altKey &&
!e.ctrlKey &&
!e.metaKey) {
search.focus();
search.select();
e.preventDefault();
}
});
goog.dom.classes.remove(search.parentElement, 'off');
};
/**
* Allow to un-hide information about protected and deprecated methods.
*/
jvjsdoc.enableHiddenContent = function() {
var hidden = goog.dom.getElementsByClass('hidden');
function helper(elem, e) {
goog.dom.classes.toggle(elem, 'hidden');
};
for (var i = 0; i < hidden.length; ++i) {
var elem = hidden[i];
var trigger = elem.firstChild;
goog.events.listen(trigger, goog.events.EventType.CLICK,
goog.bind(helper, undefined, elem));
}
};
/**
* Initialise our javascript helpers.
*/
jvjsdoc.init = function() {
jvjsdoc.enableSearch();
jvjsdoc.enableHiddenContent();
};
goog.exportSymbol('init', jvjsdoc.init);