<script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/v2.js"></script>
<script>
hbspt.forms.create({
portalId: "6821620",
formId: "<?php the_field('footer_text_top_right_form_id','options'); ?>",
css: ' ',
cssClass: '#ahubspot',
<?php if(get_field('footer_text_top_right_form_link_thanks','options')){ ?>
onFormSubmit: function(){
window.location = "<?php the_field('footer_text_top_right_form_link_thanks','options') ?>";
}
<?php }else{ ?>
onFormSubmit: function(){
scroll_to_anchor_if_not_in_view_port('form-wrapper-<?php echo $GLOBALS['form_anchor_id']; ?>');
}
<?php } ?>
});
function scroll_to_anchor_if_not_in_view_port(id){
// console.log('scroll_to_anchor_if_not_in_view_port');
wintop_anchor = jQuery(window).scrollTop(); // calculate distance from top of window
winheight_anchor = jQuery(window).height();
topcoords_anchor = jQuery('#'+id).offset().top; // element's distance from top of page in pixels
if(wintop_anchor > (topcoords_anchor - (winheight_anchor*.9))) {
section_offset = topcoords_anchor - winheight_anchor*0.25;
jQuery('body,html').animate({
scrollTop: section_offset
}, 500);
}
}
</script>