• Resolved Fibro Jedi

    (@fibrojedi)


    Hey,

    So I’ve been using SIP for a while and, apart from getting a working search results page, the drop-down system is working well.

    I use a different plugin to record internal searches (Search Meter) and it’s led me to consider an issue. Because the box constantly does the searches, is there any way to put in a delay between the typing stopping and the results showing?

    Here’s an example of search results saved:

    bree land exp
    bree land expl
    bree land explo
    bree land explora
    bree land explorat
    bree land explorati
    bree land exploratio
    bree land exploration

    If there was even a whole 1-1? second delay it may help to reduce these queries that are still being typed? Is there anything I can add to achieve this please?
    Thanks,

    FJ

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @fibrojedi

    Thank you very much for using our plugin. You would need to edit the plugin’s code to include a delay in the search process:

    1. Open the “/wp-content/plugins/search-in-place/js/codepeople_shearch_in_place.min.js” file with the text editor of your choice.

    2. Go to the piece of code:

    e.active=jQuery.ajax({url:codepeople_search_in_place_advanced.root+"admin-ajax.php",data:h,cache:!0,dataType:"json",success:function(a){b(a)}})

    and edit it as follows:

    setTimeout(function(){e.active=jQuery.ajax({url:codepeople_search_in_place_advanced.root+"admin-ajax.php",data:h,cache:!0,dataType:"json",success:function(a){b(a)}})}, 1500)

    3. Finally, clear the browser’s cache after editing the plugin files.

    Best regards.

    Thread Starter Fibro Jedi

    (@fibrojedi)

    Okay thanks! I’ll keep a backup of the file as it’ll get overwritten anytime you folks update it.

    Thanks for the speedy response ??

    Thread Starter Fibro Jedi

    (@fibrojedi)

    sorry for the epic delay. It’s taken me ages to get around to trying this.

    Your code snippet gave me a “missing bracket” error. So I had to tweak it to this (unminified):

    setTimeout(function(){
                  e.active = jQuery.ajax({
                  url: atob(codepeople_search_in_place.root) + "admin-ajax.php",
                  data: g,
                  cache: !0,
                  dataType: "json",
                  success: function(a) {
                    b(a)
                  }
                })
              },1500))}

    That got rid of the error, and the search suggestions worked, but the delay didn’t. But I can’t see anything wrong with your setTimeout function either. Any chance you could try it on your end and see what I’ve got wrong, please?

    Thanks!

    • This reply was modified 2 years, 7 months ago by Fibro Jedi. Reason: Code snippet correction
    Plugin Author codepeople

    (@codepeople)

    Hello @fibrojedi

    You could use a code snippet similar to:

    (function(){
        if('search_in_place_timeout_flag' in window) clearTimeout(search_in_place_timeout_flag);
        search_in_place_timeout_flag = setTimeout(function () {
            e.active = jQuery.ajax({
                url: atob(codepeople_search_in_place.root) + "admin-ajax.php",
                data: g,
                cache: !0,
                dataType: "json",
                success:function(a){b(a);}
            });
        }, 2000);    
    })()

    Best regards.

    Thread Starter Fibro Jedi

    (@fibrojedi)

    I’ll stop bugging you about this as it’s not fair as I’m not a paying customer yet.

    But FYI:

    e.active && e.active.abort(), (function(){
        if('search_in_place_timeout_flag' in window) clearTimeout(search_in_place_timeout_flag);
        search_in_place_timeout_flag = setTimeout(function (){
            e.active = jQuery.ajax({
                url: atob(codepeople_search_in_place.root) + "admin-ajax.php",
                data: g,
                cache: !0,
                dataType: "json",
                success:function(a){b(a);}
            });
        }, 2000);
    }))(),

    Gives the error: 11:42:22.142 Uncaught SyntaxError: missing ) in parenthetical codepeople_shearch_in_place.min.js:276:18

    and

    e.active && e.active.abort(), (function(){
        if('search_in_place_timeout_flag' in window) clearTimeout(search_in_place_timeout_flag);
        search_in_place_timeout_flag = setTimeout(function () {
            e.active = jQuery.ajax({
                url: atob(codepeople_search_in_place.root) + "admin-ajax.php",
                data: g,
                cache: !0,
                dataType: "json",
                success:function(a){b(a);}
            });
        }, 2000);
    }))()

    gives the error: 11:43:50.407 Uncaught SyntaxError: unexpected token: ':' codepeople_shearch_in_place.min.js:276:18

    My only other thought would be to use my own JS function on keypress/up with its own setTimeout that triggers your function after the delay. But I’d need some way to stop yours auto-firing first. I’ll have a think.

    I think maybe I’m just asking for something the code was never intended to do, so I’ll leave you in peace now. Thanks for trying!

    • This reply was modified 2 years, 7 months ago by Fibro Jedi. Reason: Added a possible other approach I could take
    Plugin Author codepeople

    (@codepeople)

    Hello @fibrojedi

    I guess you are not replacing the correct piece of code.

    Please, download the modified file from the following link:

    https://resources.developers4web.com/sip/tmp/2022/04/09/codepeople_shearch_in_place.min.js

    Upload it to “/wp-content/plugins/search-in-place/js/codepeople_shearch_in_place.min.js”, and please, remember to clear the website and browser caches.

    Best regards.

    Thread Starter Fibro Jedi

    (@fibrojedi)

    Hey,

    Sorry for my unhelpful silence for so long, I have literally not had a chance to implement this.

    I have done so now and it’s working without errors. Am I correct in presuming that the “loading” animation that appears below the search box appears immediately but doesn’t actually process the search until after the timeout?

    If so, I think I’ve been <b>wrongly</b> presuming that the “loading” animation meant it was ignoring the setTimeout.

    Thanks for your help.

    Plugin Author codepeople

    (@codepeople)

    Hello @fibrojedi

    Exactly. The animation appears immediately, but the plugin calls the server after the timeout.

    Best regards.

    Thread Starter Fibro Jedi

    (@fibrojedi)

    Then it all seems sorted! Thank you ??

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Delay between typing and results’ is closed to new replies.