feat: UI enhancements to allow control-click etc on the search results (provided by @kivinen - see #4747)

Fixes #4711 i.e., allows using control-click or context menu to open items in the top right search list to open multiple documents in different tabs.

Authored by @kivinen
This commit is contained in:
Robert Sparks 2022-11-14 23:08:28 +00:00 committed by GitHub
parent 4c471983c3
commit 2c304d0364
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 2 deletions

View file

@ -19,6 +19,24 @@ function prettify_tz(x) {
return x.text.replaceAll("_", " ").replaceAll("/", " / "); return x.text.replaceAll("_", " ").replaceAll("/", " / ");
} }
function search_template_result(data) {
if (data.url == null) {
return data.text;
}
var $link = $("<a>" + data.text + "</a>");
$link.prop("href", data.url);
$link.on("mouseup", function (evt) {
// Do not propagate any events which have modifiers keys
// or if some other mouse button than 1 (left) was used.
if (evt.shiftKey || evt.ctrlKey || evt.metaKey || evt.altKey ||
evt.which != 1) {
evt.stopPropagation();
}
});
return $link;
}
// Copyright The IETF Trust 2015-2021, All Rights Reserved // Copyright The IETF Trust 2015-2021, All Rights Reserved
// JS for ietf.utils.fields.SearchableField subclasses // JS for ietf.utils.fields.SearchableField subclasses
window.setupSelect2Field = function (e) { window.setupSelect2Field = function (e) {
@ -37,7 +55,8 @@ window.setupSelect2Field = function (e) {
); );
} }
template_modify = e.hasClass("tz-select") ? prettify_tz : undefined; template_modify = e.hasClass("tz-select") ? prettify_tz :
(e.hasClass("search-select") ? search_template_result : undefined);
// focus the search field automatically // focus the search field automatically
$(document) $(document)

View file

@ -69,7 +69,7 @@
{% endif %} {% endif %}
<label class="d-none d-md-block" aria-label="Document search"> <label class="d-none d-md-block" aria-label="Document search">
<input class="form-control select2-field" <input class="form-control select2-field search-select"
id="navbar-doc-search" id="navbar-doc-search"
data-select2-ajax-url="{% url 'ietf.doc.views_search.ajax_select2_search_docs' model_name='docalias' doc_type='draft' %}" data-select2-ajax-url="{% url 'ietf.doc.views_search.ajax_select2_search_docs' model_name='docalias' doc_type='draft' %}"
type="text" type="text"