Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* tagDiv Newspaper live Search debounce hack */
- jQuery(function() {
- jQuery('.tdb-head-search-form-input').on('keydown', function(e) {
- if (typeof debounce_do_ajax_call === "undefined") {
- console.log('tdbSearch.do_ajax_call override');
- tdbSearch.original_td_do_ajax_call = tdbSearch.do_ajax_call;
- // as hacked out of context, needed to hook context or debounce would trigger on each call
- debounce_do_ajax_call = debounce(tdbSearch.original_td_do_ajax_call, 1500)
- tdbSearch.do_ajax_call = debounce_do_ajax_call
- }
- });
- });
- // https://davidwalsh.name/javascript-debounce-function
- function debounce(func, wait, immediate) {
- var timeout;
- return function() {
- var context = this, args = arguments;
- var later = function() {
- timeout = null;
- if (!immediate) func.apply(context, args);
- };
- var callNow = immediate && !timeout;
- clearTimeout(timeout);
- timeout = setTimeout(later, wait);
- if (callNow) func.apply(context, args);
- };
- };
Advertisement
Add Comment
Please, Sign In to add comment