4 * Returns a function, that, as long as it continues to be invoked, will not
5 * be triggered. The function will be called after it stops being called for
6 * N milliseconds. If `immediate` is passed, trigger the function on the
7 * leading edge, instead of the trailing.
8 * @attribution https://davidwalsh.name/javascript-debounce-function
14 export function debounce(func, wait, immediate) {
17 const context = this, args = arguments;
18 const later = function() {
20 if (!immediate) func.apply(context, args);
22 const callNow = immediate && !timeout;
23 clearTimeout(timeout);
24 timeout = setTimeout(later, wait);
25 if (callNow) func.apply(context, args);
30 * Scroll and highlight an element.
31 * @param {HTMLElement} element
33 export function scrollAndHighlightElement(element) {
35 element.scrollIntoView({behavior: 'smooth'});
37 const color = document.getElementById('custom-styles').getAttribute('data-color-light');
38 const initColor = window.getComputedStyle(element).getPropertyValue('background-color');
39 element.style.backgroundColor = color;
41 element.classList.add('selectFade');
42 element.style.backgroundColor = initColor;
45 element.classList.remove('selectFade');
46 element.style.backgroundColor = '';