From 8a3693d8d26bc6a7efd9abb0446ac98cac68b748 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Tue, 26 May 2009 18:07:37 +0000 Subject: [PATCH] merged Nathans fixes r26507 and r27070 to 1.6 --- etemplate/js/ajax_select.js | 44 ++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/etemplate/js/ajax_select.js b/etemplate/js/ajax_select.js index 7d41ca1e11..3ded8a26fe 100644 --- a/etemplate/js/ajax_select.js +++ b/etemplate/js/ajax_select.js @@ -26,6 +26,13 @@ var current_app = 'etemplate'; var ajax_select_timer_id = 0; var ajax_select_timeout = 300; +// These keys will not trigger a search if the results box is currently displayed +var no_search_keys = [ + '9', // Tab + '38', '63232', // Up + '40', '63233' // Down +]; + function ajax_select_widget_setup(widget_id, onchange, options, currentapp) { current_app = currentapp; if(onchange) { @@ -93,10 +100,17 @@ function checkKey(e, value) { /* * We check for Tab, Up and Down */ - if (e.keyCode != '9' // Tab - && e.keyCode != '38' && e.keyCode != '63232' // Up - && e.keyCode != '40' && e.keyCode != '63233' // Down - ) return; // The user has not pressed anything we're interested in + var interested = false; + for(var i = 0; i < no_search_keys.length; i++) { + if(e.keyCode == no_search_keys[i]) { + interested = true; + break; + } + } + if (!interested) { + return; // The user has not pressed anything we're interested in + } + if(e.target) { var target = e.target; } else if (e.srcElement) { @@ -116,6 +130,7 @@ function checkKey(e, value) { if(results.childNodes.length > 0) { e.cancelBubble = true; if(e.stopPropegation) e.stopPropegation(); + clearTimeout(ajax_select_timer_id); } else { return false; } @@ -231,16 +246,25 @@ function change(e, value) { } var base_id = id.substr(0, id.lastIndexOf('[')); + if(document.getElementById(base_id + '[results]')) { set_id = base_id + '[results]'; - if(document.getElementById(set_id).style.display == 'block') { - // Tab and arrow keys don't trigger the search - if(e.keyCode == 9 - || e.keyCode == 38 || e.keyCode == 40 - || e.keyCode == 63232 || e.keyCode == 63233) { - return; + + /* + * We check for Tab, Up and Down + */ + var interested = false; + for(var i = 0; i < no_search_keys.length; i++) { + if(e.keyCode == no_search_keys[i]) { + interested = true; + break; } } + if (interested && document.getElementById(set_id).style.display == 'block') { + clearTimeout(ajax_select_timer_id); + return; // Results are shown, allow keys to move the selection cursor + } + } else { set_id = base_id + '[search]'; }