Newer
Older
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
STUDIP.domReady(() => {
// Clear search term
$('#globalsearch-clear').on('click', function() {
var before = $('#globalsearch-input').val();
STUDIP.GlobalSearch.resetSearch();
if ($('html').is('.responsive-display') && before.length === 0) {
STUDIP.GlobalSearch.toggleSearchBar(false);
}
return false;
});
// Bind icon click to performing search.
$('#globalsearch-icon').on('click', function() {
STUDIP.GlobalSearch.doSearch();
if ($('html').hasClass('responsified')) {
var input = $('#globalsearch-input');
input.toggleClass('hidden-small-down', false);
input.focus();
}
return false;
});
// Enlarge search input on focus and show hints.
$('#globalsearch-input').on('focus', function() {
STUDIP.GlobalSearch.toggleSearchBar(true, false);
});
// Start search on Enter
$('#globalsearch-input').on('keypress', function(e) {
if (e.which === 13) {
STUDIP.GlobalSearch.doSearch();
return false;
}
});
// Close search on click on page.
$('div#flex-header, div#layout_page, #layout_footer').on('click', function() {
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
if (!$('#globalsearch-input').hasClass('hidden-js')) {
STUDIP.GlobalSearch.toggleSearchBar(false, false);
}
});
// Show/hide hints on click.
$('#globalsearch-togglehints').on('click', function() {
var toggle = $('#globalsearch-togglehints'),
currentText = toggle.text();
toggle.text(toggle.data('toggle-text').trim());
toggle.data('toggle-text', currentText);
toggle.toggleClass('open');
});
// Delegate events on result container so we don't have to bind them
// one by one
$('#globalsearch-results').on('click', '.globalsearch-category a', function() {
var category = $(this)
.closest('.globalsearch-category')
.data('category');
STUDIP.GlobalSearch.expandCategory(category);
return false;
});
// Key bindings.
$(document).keydown(function(e) {
// Don't do anything if a dialog is open
if (STUDIP.Dialog.stack.length > 0) {
return;
}
// ctrl + space
if (e.which === 32 && e.ctrlKey && !e.altKey && !e.metaKey && !e.shiftKey) {
e.preventDefault();
if ($('#globalsearch-searchbar').hasClass('is-visible')) {
STUDIP.GlobalSearch.toggleSearchBar(false, false);
$('#globalsearch-input').blur();
} else {
$('#globalsearch-input').focus();
}
// escape
} else if (e.which === 27 && !e.ctrlKey && !e.altKey && !e.metaKey && !e.shiftKey) {
e.preventDefault();
STUDIP.GlobalSearch.toggleSearchBar(false, true);
}
});
// Start searching 750 ms after user stopped typing or content was added
// by pasting text via right-click.
$('#globalsearch-input').on('keyup paste',
_.debounce(function() {
STUDIP.GlobalSearch.doSearch();
}, 750)
);
});