Skip to content

Instantly share code, notes, and snippets.

@noahub
Last active August 29, 2015 14:22
Show Gist options
  • 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 9698416
function HorizontalForm(a,b){var c=this;this.spacing=a,this.submitPlacement=b,this.$=lp.jQuery,this.form=this.$(".lp-pom-form").eq(0),this.fields=this.$("div.lp-pom-form-field"),this.button=this.$(".lp-pom-form .lp-pom-button").eq(0),"manual"!==this.submitPlacement&&(this.fields=this.fields.add(this.button)),this.$(function(){c.layout()}),this.$(window).resize(function(){c.layout()})}HorizontalForm.prototype.layout=function(){for(var a=this.fields.eq(0).width()+this.spacing,b=this.fields.eq(0).height(),c=this.$(".lp-pom-block-content").eq(0).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=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, 'inline');
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment