Skip to content

Commit 2c304d0

Browse files
authored
feat: UI enhancements to allow control-click etc on the search results (provided by @kivinen - see ietf-tools#4747)
Fixes ietf-tools#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
1 parent 4c47198 commit 2c304d0

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

ietf/static/js/select2.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,24 @@ function prettify_tz(x) {
1919
return x.text.replaceAll("_", " ").replaceAll("/", " / ");
2020
}
2121

22+
function search_template_result(data) {
23+
if (data.url == null) {
24+
return data.text;
25+
}
26+
var $link = $("<a>" + data.text + "</a>");
27+
$link.prop("href", data.url);
28+
$link.on("mouseup", function (evt) {
29+
// Do not propagate any events which have modifiers keys
30+
// or if some other mouse button than 1 (left) was used.
31+
if (evt.shiftKey || evt.ctrlKey || evt.metaKey || evt.altKey ||
32+
evt.which != 1) {
33+
evt.stopPropagation();
34+
}
35+
});
36+
37+
return $link;
38+
}
39+
2240
// Copyright The IETF Trust 2015-2021, All Rights Reserved
2341
// JS for ietf.utils.fields.SearchableField subclasses
2442
window.setupSelect2Field = function (e) {
@@ -37,7 +55,8 @@ window.setupSelect2Field = function (e) {
3755
);
3856
}
3957

40-
template_modify = e.hasClass("tz-select") ? prettify_tz : undefined;
58+
template_modify = e.hasClass("tz-select") ? prettify_tz :
59+
(e.hasClass("search-select") ? search_template_result : undefined);
4160

4261
// focus the search field automatically
4362
$(document)

ietf/templates/base.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
{% endif %}
7070

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

0 commit comments

Comments
 (0)