From: Meik S. <acy...@ph...> - 2009-11-05 14:59:13
|
Author: acydburn Date: Thu Nov 5 14:58:25 2009 New Revision: 10254 Log: update to r10069 (try to detect auto completion on input fields and do not submit form if user uses enter key for auto completion instead of right arrow key) Modified: branches/phpBB-3_0_0/phpBB/styles/prosilver/template/forum_fn.js Modified: branches/phpBB-3_0_0/phpBB/styles/prosilver/template/forum_fn.js ============================================================================== *** branches/phpBB-3_0_0/phpBB/styles/prosilver/template/forum_fn.js (original) --- branches/phpBB-3_0_0/phpBB/styles/prosilver/template/forum_fn.js Thu Nov 5 14:58:25 2009 *************** *** 317,322 **** --- 317,325 ---- } } + var in_autocomplete = false; + var last_key_entered = ''; + /** * Usually used for onkeypress event, to submit a form on enter */ *************** *** 326,334 **** --- 329,355 ---- if (!event.which && ((event.charCode || event.charCode === 0) ? event.charCode : event.keyCode)) event.which = event.charCode || event.keyCode; + // Keycode is array down? + if (event.keyCode && event.keyCode == 40) + in_autocomplete = true; + + // Make sure we are not within an "autocompletion" field + if (in_autocomplete) + { + // If return pressed and key changed we reset the autocompletion + if (!last_key_entered || last_key_entered == event.which) + { + in_autocompletion = false; + return true; + } + } + // Keycode is not return, then return. ;) if (event.which != 13) + { + last_key_entered = event.which; return true; + } var current = selector['parentNode']; *************** *** 373,384 **** --- 394,422 ---- if (!default_button || default_button.length <= 0) return true; + // Keycode is array down? + if (e.keyCode && e.keyCode == 40) + in_autocomplete = true; + + // Make sure we are not within an "autocompletion" field + if (in_autocomplete) + { + // If return pressed and key changed we reset the autocompletion + if (!last_key_entered || last_key_entered == e.which) + { + in_autocompletion = false; + return true; + } + } + if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) { default_button.click(); return false; } + last_key_entered = e.which; + return true; }); |