list.childElementCount !== 0) { list.children[0].className = "active"; } e.preventDefault(); break; } } // debounce 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); }; } return { init: function(type, inputfield, formfield, submitdata = true) { suggest_type = type; input = inputfield; form = formfield; submit = submitdata; input.addEventListener("input", onInputClick); input.addEventListener("keydown", onKeyDown); window.addEventListener('resize', debounce(setListLocation, 150)); document.addEventListener("click", resetResults); } } }()); Ә