-
Notifications
You must be signed in to change notification settings - Fork 14
/
script.js
84 lines (70 loc) · 2.24 KB
/
script.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
/**
* AJAX functions for the pagename quicksearch
*
* @license GPL2 (http://www.gnu.org/licenses/gpl.html)
* @author Andreas Gohr <andi@splitbrain.org>
* @author Adrian Lang <lang@cosmocode.de>
*/
var pr_qsearch = {
$inObj: null,
$outObj: null,
$nsObj: null,
$formObj: null,
timer: null,
init: function () {
pr_qsearch.$inObj = jQuery('#qsearch2__in');
pr_qsearch.$outObj = jQuery('#qsearch2__out');
pr_qsearch.$formObj = jQuery('#dw__search2');
pr_qsearch.$nsObj = jQuery('#dw__ns');
// objects found?
if (pr_qsearch.$inObj.length === 0 ||
pr_qsearch.$outObj.length === 0 ||
pr_qsearch.$formObj.length === 0 ||
pr_qsearch.$nsObj.length === 0) {
return;
}
pr_qsearch.$inObj.attr("autocomplete", "off");
// attach eventhandler to search field
pr_qsearch.$inObj.keyup(function () {
pr_qsearch.clear_results();
if (pr_qsearch.timer) {
window.clearTimeout(pr_qsearch.timer);
pr_qsearch.timer = null;
}
pr_qsearch.timer = window.setTimeout(pr_qsearch.performSearch, 500);
});
// attach eventhandler to output field
pr_qsearch.$outObj.click(function () {
pr_qsearch.$outObj.hide();
});
pr_qsearch.$formObj.submit(function () {
pr_qsearch.$inObj.val(pr_qsearch.$inObj.val() + ' @' + pr_qsearch.$nsObj.val());
return true;
});
},
clear_results: function () {
pr_qsearch.$outObj.hide();
pr_qsearch.$outObj.html('');
},
onCompletion: function (responseText) {
if (responseText === '') return;
pr_qsearch.$outObj.html(responseText);
pr_qsearch.$outObj.show();
},
performSearch: function () {
pr_qsearch.clear_results();
var value = pr_qsearch.$inObj.val();
if (value === '') return;
jQuery.post(
DOKU_BASE + 'lib/exe/ajax.php',
{
call: 'qsearch',
q: value + ' @' + pr_qsearch.$nsObj.val()
},
pr_qsearch.onCompletion
);
}
};
jQuery(function () {
pr_qsearch.init();
});