Skip to content

Instantly share code, notes, and snippets.

@noahub
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noahub/a12b620b7cf756b11e0a to your computer and use it in GitHub Desktop.
Save noahub/a12b620b7cf756b11e0a to your computer and use it in GitHub Desktop.
<script>
// unbounce-horizontal-forms 7453328
function HorizontalForm(a,b){var c=this;this.spacing=a,this.submitPlacement=b,this.$=window.lp.jQuery,this.$(function(){c.$form=c.$(".lp-pom-form").eq(0),c.$fields=c.$("div.lp-pom-form-field"),c.$button=c.$(".lp-pom-form .lp-pom-button").eq(0),"manual"!==c.submitPlacement&&(c.$fields=c.$fields.add(c.$button)),c.doLayout()}),this.$(window).resize(function(){c.doLayout()})}HorizontalForm.prototype.doLayout=function(){for(var a=this.$fields.eq(0).width()+this.spacing,b=this.$fields.eq(0).height(),c=this.$form.parent().width()-this.$form.position().left,d=0,e=0,f=0;f<this.$fields.length;f++){field=this.$fields.eq(f),e=0===f?e:e+a,e+a>c&&(d=0===f?d:d+b+this.spacing,e=0,b=field.height());var g=d;if(field.is(".lp-pom-button"))if("newline"===this.submitPlacement)g=d+b+spacing,e=0;else{g=d+19;var h=this.$form.find(":text").eq(0).height();field.css("height",h-1+"px")}else this.$(field).children("label").length||(g=d+19);field.css({top:g+"px",left:e+"px"}),field.height()>b&&(b=field.height())}this.$form.css({right:"0",width:"auto",height:d+b+"px"})};
// First parameter is spacing between fields, e.g. 20px
// Second parameter is submit button placement. Options:
// - 'inline': in line with the fields
// - 'newline': on a new line
// - 'manual': wherever you place the button in the page builder
new HorizontalForm(20, 'manual');
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment