var fasoon = fasoon || {}; (function (ns, $) { "use strict"; ns.QuotePriceStep2 = function () { this.construct.apply(this, arguments); }; var proto = ns.QuotePriceStep2.prototype; proto.construct = function (options) { this.options = $.extend(true, { form_id: undefined, phone_id: undefined, email_id: undefined, street_id: undefined, zip_id: undefined, city_id: undefined, gtm_data: {}, plugins_url: undefined }, options); this.form = $('#' + this.options.form_id); if (!this.form.length) { alert('Form #' + this.options.form_id + ' is not found.'); return; } this.phone = $('#' + this.options.phone_id, this.form); if (!this.phone.length) { alert('Element #' + this.options.phone_id + ' is not found.'); return; } this.phone.intlTelInput({ allowExtensions: true, autoFormat: true, autoHideDialCode: false, preferredCountries: ['ch', 'de', 'at'], initialCountry: 'ch', nationalMode: false, utilsScript: this.options.plugins_url + '/js/intl-tel-input/utils.js' }); this.email = $('#' + this.options.email_id, this.form); if (!this.email.length) { alert('Element #' + this.options.email_id + ' is not found.'); return; } this.street = $('#' + this.options.street_id, this.form); if (!this.street.length) { alert('Element #' + this.options.street_id + ' is not found.'); return; } this.zip = $('#' + this.options.zip_id, this.form); if (!this.zip.length) { alert('Element #' + this.options.zip_id + ' is not found.'); return; } this.zip.autoNumeric( 'init', { vMin: 0, vMax: 999999999, aSep: '', mDec: 0 } ); this.city = $('#' + this.options.city_id, this.form); if (!this.city.length) { alert('Element #' + this.options.city_id + ' is not found.'); return; } fasoon_gtm.company_foundation(2, "Initiated", this.options.gtm_data); this.form.find('#back').on('click', $.proxy(this.onBack, this)); this.form.on('submit', $.proxy(this.onSubmit, this)); }; proto.onBack = function () { fasoon_gtm.company_foundation(2, "Complete", this.getGtmData("Back")); return true; }; proto.onSubmit = function () { fasoon_gtm.company_foundation(2, "Complete", this.getGtmData("Continue")); return true; }; proto.getGtmData = function (click_name) { var data = this.options.gtm_data; data.click_name = click_name; data.contact_email = this.email.val(); data.contact_street = this.street.val(); data.contact_zip = this.zip.val(); data.contact_city = this.city.val(); data.contact_phone = this.phone.val(); return data; }; })(fasoon, jQuery);