Skip to content

Commit

Permalink
Fix icons and autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
oliver-stoehr committed Sep 18, 2023
1 parent a204bab commit df39419
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 8 deletions.
13 changes: 9 additions & 4 deletions themes/belugax/templates/layout/layout.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
'rel' => 'search'
]
);
// We need to generate the icons early, because they may add some stylesheets;
// if we render them after the headLink / headStyle calls, some dependencies
// may not load correctly. Thus, we render early, but use this later.
$icons = !isset($this->renderingError) ? $this->render('js-icons.phtml') : '{}';
?>
<!-- RTL styling -->
<? if ($this->layout()->rtl) {
Expand Down Expand Up @@ -113,10 +117,11 @@
$translations = $this->jsTranslations()->getJSON();
$dsb = DEFAULT_SEARCH_BACKEND;
$setupJS = <<<JS
VuFind.path = '{$root}';
VuFind.defaultSearchBackend = '{$dsb}';
VuFind.addTranslations({$translations});
JS;
VuFind.path = '{$root}';
VuFind.defaultSearchBackend = '{$dsb}';
VuFind.addTranslations({$translations});
VuFind.addIcons({$icons});
JS;
$this->headScript()->appendScript($setupJS);
?>
<?=$this->headScript()?>
Expand Down
48 changes: 48 additions & 0 deletions themes/belugax_hcu/js/missing.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,51 @@ function lessFacets(id) {
$('#more-' + id).removeClass('hidden');
return false;
}

function setupAutocomplete() {
// If .autocomplete class is missing, autocomplete is disabled and we should bail out.
var searchbox = $('#searchForm_lookfor.autocomplete');
if (searchbox.length < 1) {
return;
}
// Search autocomplete
searchbox.autocomplete({
rtl: $(document.body).hasClass("rtl"),
maxResults: 10,
loadingString: VuFind.translate('loading') + '...',
handler: function vufindACHandler(input, cb) {
var query = input.val();
var searcher = extractClassParams(input);
var hiddenFilters = [];
$('#searchForm').find('input[name="hiddenFilters[]"]').each(function hiddenFiltersEach() {
hiddenFilters.push($(this).val());
});
$.fn.autocomplete.ajax({
url: VuFind.path + '/AJAX/JSON',
data: {
q: query,
method: 'getACSuggestions',
searcher: searcher.searcher,
type: searcher.type ? searcher.type : $('#searchForm_type').val(),
hiddenFilters: hiddenFilters
},
dataType: 'json',
success: function autocompleteJSON(json) {
if (json.data.suggestions.length > 0) {
var datums = [];
for (var j = 0; j < json.data.suggestions.length; j++) {
datums.push(json.data.suggestions[j]);
}
cb(datums);
} else {
cb([]);
}
}
});
}
});
// Update autocomplete on type change
$('#searchForm_type').change(function searchTypeChange() {
searchbox.autocomplete().clearCache();
});
}
13 changes: 9 additions & 4 deletions themes/belugax_hcu/templates/layout/layout.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
'rel' => 'search'
]
);
// We need to generate the icons early, because they may add some stylesheets;
// if we render them after the headLink / headStyle calls, some dependencies
// may not load correctly. Thus, we render early, but use this later.
$icons = !isset($this->renderingError) ? $this->render('js-icons.phtml') : '{}';
?>
<!-- RTL styling -->
<? if ($this->layout()->rtl) {
Expand Down Expand Up @@ -114,10 +118,11 @@
$translations = $this->jsTranslations()->getJSON();
$dsb = DEFAULT_SEARCH_BACKEND;
$setupJS = <<<JS
VuFind.path = '{$root}';
VuFind.defaultSearchBackend = '{$dsb}';
VuFind.addTranslations({$translations});
JS;
VuFind.path = '{$root}';
VuFind.defaultSearchBackend = '{$dsb}';
VuFind.addTranslations({$translations});
VuFind.addIcons({$icons});
JS;
$this->headScript()->appendScript($setupJS);
?>
<?=$this->headScript()?>
Expand Down

0 comments on commit df39419

Please sign in to comment.