var fasoon = fasoon || {}; (function (ns, $) { "use strict"; ns.QuotePriceStep3 = function () { this.construct.apply(this, arguments); }; var proto = ns.QuotePriceStep3.prototype; proto.construct = function (options) { this.options = $.extend({ form_id: undefined, company_zip_id: undefined, company_city_id: undefined, company_canton_id: undefined, zip_codes: 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.company_zip = $('#' + this.options.company_zip_id, this.form); if (!this.company_zip.length) { alert('Element #' + this.options.company_zip_id + ' is not found.'); return; } this.company_city = $('#' + this.options.company_city_id, this.form); if (!this.company_city.length) { alert('Element #' + this.options.company_city_id + ' is not found.'); return; } /*this.company_zip.autoNumeric( 'init', { vMin: 0, vMax: 999999999, aSep: '', mDec: 0 } );*/ this.company_zip.autocomplete({ source: this.options.zip_codes, select: $.proxy(function(event, ui) { this.company_city.val(ui.item.city); this.company_canton.val(ui.item.canton); this.company_city.trigger('blur'); }, this) }); this.company_canton = $('#' + this.options.company_canton_id, this.form); if (!this.company_canton.length) { alert('Element #' + this.options.company_canton_id + ' is not found.'); return; } fasoon_gtm.company_foundation(3, "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 () { this.options.gtm_data.click_name = "Back"; this.options.gtm_data.region = this.company_canton.val(); fasoon_gtm.company_foundation(3, "Complete", this.options.gtm_data); return true; }; proto.onSubmit = function () { this.options.gtm_data.click_name = "Continue"; this.options.gtm_data.region = this.company_canton.val(); fasoon_gtm.company_foundation(3, "Complete", this.options.gtm_data); return true; }; })(fasoon, jQuery);