From f1b115c4437160798df971b78501936ca3a5561d Mon Sep 17 00:00:00 2001 From: Marius Kittler Date: Wed, 20 Sep 2023 13:55:15 +0200 Subject: [PATCH] Fix key navigation on test details When viewing a test live and test module details are added to the page dynamically, then the key navigation breaks. It skips steps instead of just selecting the next/previous step. This is because the event handler is registered multiple times. This change fixes the issue by making sure the event handler is only registered once. Related ticket: https://progress.opensuse.org/issues/113468 --- assets/javascripts/test_result.js | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/assets/javascripts/test_result.js b/assets/javascripts/test_result.js index b19372aa216..b8ea5fce0af 100644 --- a/assets/javascripts/test_result.js +++ b/assets/javascripts/test_result.js @@ -644,16 +644,20 @@ function renderTestModules(response) { setCurrentPreviewFromStepLinkIfPossible($("[href='" + hash + "'], [data-href='" + hash + "']")); } - // setup keyboard navigation through test details - $(window).keydown(handleKeyDownOnTestDetails); - - // ensure the size of the preview container is adjusted when the window size changes - $(window).resize(function () { - const currentPreview = $('.current_preview'); - if (currentPreview.length) { - setCurrentPreview($('.current_preview'), true); - } - }); + // setup event handlers for the window + if (!this.hasWindowEventHandlers) { + // setup keyboard navigation through test details + $(window).keydown(handleKeyDownOnTestDetails); + + // ensure the size of the preview container is adjusted when the window size changes + $(window).resize(function () { + const currentPreview = $('.current_preview'); + if (currentPreview.length) { + setCurrentPreview($('.current_preview'), true); + } + }); + this.hasWindowEventHandlers = true; + } // setup result filter, define function to apply filter changes const detailsFilter = $('#details-filter');