Skip to content

Instantly share code, notes, and snippets.

@wisnubaldas
Forked from Kcko/keyup-delay1.js
Created August 19, 2022 02:45
Show Gist options
  • Save wisnubaldas/f5e89211bb4dacdf0331655a91f10496 to your computer and use it in GitHub Desktop.
Save wisnubaldas/f5e89211bb4dacdf0331655a91f10496 to your computer and use it in GitHub Desktop.

Revisions

  1. @Kcko Kcko revised this gist Nov 16, 2018. 1 changed file with 14 additions and 0 deletions.
    14 changes: 14 additions & 0 deletions keyup3.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    $('#mySearch').keyup(function() {

    var $this = $(this);

    clearTimeout($.data(this, 'timer'));
    var wait = setTimeout(function(){


    $.get("query.php?q="+$this.val());


    }, 1);
    $(this).data('timer', wait);
    });
  2. @Kcko Kcko revised this gist Apr 16, 2018. 2 changed files with 14 additions and 5 deletions.
    5 changes: 0 additions & 5 deletions keyup-delay.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +0,0 @@
    $('#mySearch').keyup(function() {
    clearTimeout($.data(this, 'timer'));
    var wait = setTimeout(search, 500);
    $(this).data('timer', wait);
    });
    14 changes: 14 additions & 0 deletions keyup-delay1.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    var delay = (function(){
    var timer = 0;
    return function(callback, ms){
    clearTimeout (timer);
    timer = setTimeout(callback, ms);
    };
    })();


    $('input').keyup(function() {
    delay(function(){
    alert('Time elapsed!');
    }, 1000 );
    });
  3. @Kcko Kcko revised this gist Apr 10, 2018. 1 changed file with 9 additions and 0 deletions.
    9 changes: 9 additions & 0 deletions keyup2.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    var timeout = null
    $('input').on('keyup', function() {
    var text = this.value
    clearTimeout(timeout)
    timeout = setTimeout(function() {
    // Do AJAX shit here
    console.log(text)
    }, 500)
    })
  4. @Kcko Kcko created this gist Jul 24, 2017.
    5 changes: 5 additions & 0 deletions keyup-delay.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    $('#mySearch').keyup(function() {
    clearTimeout($.data(this, 'timer'));
    var wait = setTimeout(search, 500);
    $(this).data('timer', wait);
    });