From 1b6bf85b97aa1560761f91d85a8e278b1b16e56b Mon Sep 17 00:00:00 2001 From: David Cook Date: Wed, 19 Aug 2020 15:14:14 +1000 Subject: [PATCH] Bug 26248: Simplify keep_text function used in header search The current code is functional but not very readable. This patch simplifies the code to be more readable and to be more efficient. To test: 1) Apply patch 2) Refresh browser cache 3) Type "A" in "Check out" tab 4) Click "Check in" (and other tabs) 5) Observe that text is persisted from original tab 6) Type "B" in "Search the catalog" tab 7) Click "Renew" tab 8) Observe that text is persisted from latest changed tab Signed-off-by: Mazen Khallaf --- koha-tmpl/intranet-tmpl/prog/js/staff-global.js | 30 +++++++++---------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/staff-global.js b/koha-tmpl/intranet-tmpl/prog/js/staff-global.js index 4f06af9465..b2ae1e34e3 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/staff-global.js +++ b/koha-tmpl/intranet-tmpl/prog/js/staff-global.js @@ -259,28 +259,18 @@ function playSound( sound ) { // For keeping the text when navigating the search tabs function keep_text(clicked_index) { var searchboxes = document.getElementsByClassName("head-searchbox"); - var persist = searchboxes[0].value; - - for (i = 0; i < searchboxes.length - 1; i++) { - if (searchboxes[i].value != searchboxes[i+1].value) { - if (i === searchboxes.length-2) { - if (searchboxes[i].value != searchboxes[0].value) { - persist = searchboxes[i].value; - } else if (searchboxes.length === 2) { - if (clicked_index === 0) { - persist = searchboxes[1].value; - } - } else { - persist = searchboxes[i+1].value; - } - } else if (searchboxes[i+1].value != searchboxes[i+2].value) { - persist = searchboxes[i+1].value; - } + var current_value = searchboxes[clicked_index].value; + var different_value = ""; + for (i = 0; i < searchboxes.length; i++) { + if ( searchboxes[i].value != current_value ){ + different_value = searchboxes[i].value; + break; } } - - for (i = 0; i < searchboxes.length; i++) { - searchboxes[i].value = persist; + if (different_value){ + for (i = 0; i < searchboxes.length; i++) { + searchboxes[i].value = different_value; + } } } -- 2.11.0