From 2c304d0364fbcb666ac3cb5ebefc8db985f46ac4 Mon Sep 17 00:00:00 2001 From: Robert Sparks Date: Mon, 14 Nov 2022 23:08:28 +0000 Subject: [PATCH] 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 --- ietf/static/js/select2.js | 21 ++++++++++++++++++++- ietf/templates/base.html | 2 +- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/ietf/static/js/select2.js b/ietf/static/js/select2.js index caf72e3dc..5b9590f09 100644 --- a/ietf/static/js/select2.js +++ b/ietf/static/js/select2.js @@ -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 = $("" + data.text + ""); + $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) { @@ -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) diff --git a/ietf/templates/base.html b/ietf/templates/base.html index 10e999112..1571ff500 100644 --- a/ietf/templates/base.html +++ b/ietf/templates/base.html @@ -69,7 +69,7 @@ {% endif %}