Created
November 22, 2017 17:05
-
-
Save hostedpixel/1a9e5b82a80618c616c7cabff3e8c808 to your computer and use it in GitHub Desktop.
WordPress Shortcode for Pardot form - mobile resizer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Pardot form | |
function pardot_form( $atts ) { | |
$a = shortcode_atts( array( | |
'mobile-height' => '900', | |
'height' => '500', | |
'class' => '', | |
'form' => '' | |
), $atts ); | |
return '<script type="text/javascript"> | |
pardot_mobile_height = ' . $a['mobile-height'] . '; | |
pardot_desktop_height = ' . $a['height'] . '; | |
onResize = function() { | |
if (window.innerWidth < 1181) { | |
console.log("smaller"); | |
jQuery("iframe").attr("height", pardot_mobile_height); | |
} else { | |
console.log("taller"); | |
jQuery("iframe").attr("height", pardot_desktop_height); | |
} | |
} | |
jQuery(window).resize(onResize); | |
jQuery(document).ready(onResize); | |
</script><iframe src="' . $a['form'] . '" width="100%" height="' . $a['height'] . '" class="' . $a['class'] . '" type="text/html" frameborder="0" allowTransparency="true" style="border: 0"></iframe>'; | |
} | |
add_shortcode( 'pardot', 'pardot_form' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment