'; } function findAncestor (el, cls) { while ((el = el.parentNode) && el.className.indexOf(cls) < 0); return el; } function acuityBookButtonHandler() { var type = this.getAttribute("data-acuity-event"); insertAcuity(findAncestor(this, "gw-acuity-container"), type); } function isScrolledIntoView(el) { var rect = el.getBoundingClientRect(); var elemTop = rect.top; var elemBottom = rect.bottom; // Partially visible elements return true: isVisible = elemTop < window.innerHeight && elemBottom >= 0; return isVisible; } function showFormIfInView(el){ if(isScrolledIntoView(el)) { return acuityBookButtonHandler.call(el); } setTimeout(showFormIfInView.bind(null, el), 400); }