mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-23 07:09:20 +01:00
Patch from Raphael Alla to prevent flooding by waiting to see if the user is done typing before sending request.
This commit is contained in:
parent
78dd1cdf03
commit
25a9f1165d
@ -18,6 +18,14 @@
|
|||||||
//xajaxDebug = 1;
|
//xajaxDebug = 1;
|
||||||
var current_app = 'etemplate';
|
var current_app = 'etemplate';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Settings for the timeout to prevent flooding the server with requests
|
||||||
|
*
|
||||||
|
* Adjust ajax_select_timeout to change how long to wait before sending the request (in ms)
|
||||||
|
*/
|
||||||
|
var ajax_select_timer_id = 0;
|
||||||
|
var ajax_select_timeout = 300;
|
||||||
|
|
||||||
function ajax_select_widget_setup(widget_id, onchange, options, currentapp) {
|
function ajax_select_widget_setup(widget_id, onchange, options, currentapp) {
|
||||||
current_app = currentapp;
|
current_app = currentapp;
|
||||||
if(onchange) {
|
if(onchange) {
|
||||||
@ -47,10 +55,10 @@ function ajax_select_widget_setup(widget_id, onchange, options, currentapp) {
|
|||||||
|
|
||||||
if(widget.addEventListener) {
|
if(widget.addEventListener) {
|
||||||
widget.addEventListener('keydown', checkKey, true);
|
widget.addEventListener('keydown', checkKey, true);
|
||||||
widget.addEventListener('keyup', change, false);
|
widget.addEventListener('keyup', timer_change, false);
|
||||||
widget.addEventListener('blur', hideBox, false);
|
widget.addEventListener('blur', hideBox, false);
|
||||||
} else {
|
} else {
|
||||||
widget.onkeyup = change;
|
widget.onkeyup = timer_change;
|
||||||
widget.onblur = hideBox;
|
widget.onblur = hideBox;
|
||||||
widget.onkeydown = checkKey;
|
widget.onkeydown = checkKey;
|
||||||
}
|
}
|
||||||
@ -180,6 +188,23 @@ function checkKey(e, value) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a timeout to prevent user from flooding the server with requests as
|
||||||
|
* they type. Waits to see if the user is still typing before sending the
|
||||||
|
* request. Adjust ajax_select_timeout to change how long to wait (in ms).
|
||||||
|
*/
|
||||||
|
function timer_change(e, value) {
|
||||||
|
if ( ajax_select_timer_id != 0) {
|
||||||
|
clearTimeout(ajax_select_timer_id);
|
||||||
|
}
|
||||||
|
ajax_select_timer_id = setTimeout(
|
||||||
|
function() {
|
||||||
|
change(e, value);
|
||||||
|
},
|
||||||
|
ajax_select_timeout
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function change(e, value) {
|
function change(e, value) {
|
||||||
if(!e) {
|
if(!e) {
|
||||||
var e = window.event;
|
var e = window.event;
|
||||||
|
Loading…
Reference in New Issue
Block a user