1var site = site || {}; 2 3(function($){ 4 5 var getStartedForm = { 6 7 init: function () { 8 this.initVars(); 9 this.initEvents(); 10 }, 11 12 // Init Vars 13 initVars: function () { 14 var _this = this; 15 this.validClass = "valid"; 16 this.invalidClass = "invalid"; 17 this.$requiredFields = $(".required"); 18 this.$formWrap = $(".get-started-form-wrap"); 19 this.$form = $("#insightly_web_to_lead"); 20 this.$btnSubmit = this.$form.find('input[type="submit"]'); 21 }, 22 23 /*================================================= 24 Event Handlers 25 ---------------------------------------------------*/ 26 27 initEvents: function () { 28 var _this = this; 29 30 // Required Fields 31 this.$requiredFields.on("blur", function(){ 32 _this.validateInput(this); 33 }); 34 35 this.$btnSubmit.on("click", function (ev) { 36 ev.preventDefault(); 37 var formIsValid = _this.validateForm(); 38 if(formIsValid){ 39 _this.submitForm(); 40 } else { 41 42 if ( $(window).outerHeight() < 650) { 43 $('html, body').animate({ 44 scrollTop: _this.$formWrap.offset().top - 60 45 }, 700); 46 } 47 } 48 }); 49 50 this.$requiredFields.on("blur", function () { 51 _this.validateInput(this); 52 }); 53 }, 54 55 submitForm: function () { 56 var _this = this; 57 this.$form.submit(); 58 }, 59 60 /*================================================= 61 Validation Methods 62 ---------------------------------------------------*/ 63 64 // Individual input validation 65 validateInput: function (input) { 66 67 var 68 value = input.value, 69 type = $(input).data("input-type"), 70 validator = site.validators[type], 71 isValid = typeof validator === "function" ? validator(value, input) : validator.test(value), 72 $inputWrap = $(input).closest(".form-group"); 73 74 // Toggles invalid/valid class on the input wrap 75 if(isValid){ 76 $inputWrap.addClass(this.validClass); 77 $inputWrap.removeClass(this.invalidClass); 78 } else { 79 $inputWrap.addClass(this.invalidClass); 80 $inputWrap.removeClass(this.validClass); 81 } 82 83 return isValid; 84 }, 85 86 // Validate all requried fields 87 validateForm: function () { 88 var 89 _this = this, 90 isValid = false, 91 $invalidElements; 92 93 // Go through all required inputs and vaidate them 94 this.$requiredFields.each(function(){ 95 if($(this).is(":visible")){ 96 _this.validateInput(this); 97 } 98 }); 99 100 this.$requiredFields.each(function () { 101 if($(this).val().length > 0){ 102 _this.validateInput(this); 103 } 104 }); 105 106 // Store invalid elements to this variable 107 $invalidElements = this.$form.find("." + this.invalidClass); 108 109 // Check if any invalid classes are still applied 110 if($invalidElements.length === 0){ 111 isValid = true; 112 } 113 114 return isValid; 115 } 116 117 }; 118 119 site.getStartedForm = getStartedForm; 120 121 $(function () { 122 123 site.getStartedForm.init(); 124 125 }); 126 127}(jQuery));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.