From 60ac3f27d73a64802385188859a8010f7c0c9fad Mon Sep 17 00:00:00 2001 From: Christoph Herbst Date: Mon, 5 Jul 2010 13:35:30 +0200 Subject: [PATCH] search.js: only load on certain input --- web/js/search.js | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/web/js/search.js b/web/js/search.js index d6bcc4f..8384bf0 100644 --- a/web/js/search.js +++ b/web/js/search.js @@ -1,17 +1,37 @@ +var doLoad = false; +var oldValue; + +function doAjaxCall( value, action ) { + //alert('got argument:' + value+ ':' + action ); + $('#loader').show(); + $('#anlagen').load( + action + ' #anlagen', + { query: value + '*' }, + function() { $('#loader').hide(); } + ); + doLoad = false; +} + $(document).ready(function() { //$('.search input[type="submit"]').hide(); $('#search_keywords').keyup(function(key) { - if (this.value.length >= 3 || this.value == '') + if ( key.which != '8' && key.which != '46' && !doLoad ) + return; + if ( (this.value.length >= 3 || this.value == '' ) && + oldValue != this.value ) { - $('#loader').show(); - $('#anlagen').load( - $(this).parents('form').attr('action') + ' #anlagen', - { query: this.value + '*' }, - function() { $('#loader').hide(); } - ); + oldValue = this.value; + doAjaxCall(this.value, + $(this).parents('form').attr('action')); } }); + + $('#search_keywords').keypress(function(key) + { + if (this.value.length >= 2) + doLoad = true; + }); });