Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion ietf/static/js/select2.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,24 @@ function prettify_tz(x) {
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
// JS for ietf.utils.fields.SearchableField subclasses
window.setupSelect2Field = function (e) {
Expand All @@ -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
$(document)
Expand Down
2 changes: 1 addition & 1 deletion ietf/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
{% endif %}

<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"
data-select2-ajax-url="{% url 'ietf.doc.views_search.ajax_select2_search_docs' model_name='docalias' doc_type='draft' %}"
type="text"
Expand Down