From 3e934acfa0a4770a2a884efc50fa098abe9828c0 Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Mon, 18 Nov 2024 17:16:02 +0100 Subject: [PATCH] Allow "open in new tab" for event typeahead (#4631) * Allow "open in new tab" for event typeahead * use default link-behaviour for e.g. open in new ... * navigate in typeahead with tab, add esc to close --------- Co-authored-by: Richard Schreiber --- .../static/pretixcontrol/js/ui/typeahead.js | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/pretix/static/pretixcontrol/js/ui/typeahead.js b/src/pretix/static/pretixcontrol/js/ui/typeahead.js index 648b86256..c11a14ad2 100644 --- a/src/pretix/static/pretixcontrol/js/ui/typeahead.js +++ b/src/pretix/static/pretixcontrol/js/ui/typeahead.js @@ -14,6 +14,7 @@ $(function () { var lastQuery = null; var runQueryTimeout = null; var loadIndicatorTimeout = null; + var focusOutTimeout = null; function showLoadIndicator() { $container.find("li:not(.query-holder)").remove(); $container.append("
  • "); @@ -76,14 +77,7 @@ $(function () { $("
  • ").append( $("").attr("href", res.url).append( $linkContent - ).on("mousedown", function (event) { - if ($(this).length) { - location.href = $(this).attr("href"); - } - $(this).parent().addClass("active"); - event.preventDefault(); - event.stopPropagation(); - }) + ) ) ); }); @@ -115,8 +109,17 @@ $(function () { event.stopPropagation(); } }); - $query.on("blur", function (event) { - $container.removeClass('focused'); + $container.add($query).on("keydown", function (event) { + if (event.which === 27) { // escape + $container.removeClass('focused'); + } + }).on("focusin", function (event) { + window.clearTimeout(focusOutTimeout); + $(document.body).one("focusout", function (event) { + focusOutTimeout = window.setTimeout(function () { + $container.removeClass('focused'); + }, 100); + }) }); $query.on("keyup", function (event) { var $first = $container.find("li:not(.query-holder)").first();