(function ($) { $(function () { var options = $.extend(true, { form_id: undefined, gtm_data: {}, step: undefined, currency: 'CHF', summary_product_tpl_class: undefined, }, fasoon_quote_step6_products_vars); var $form = $('#' + options.form_id); $summary_products = $('.summary-products', $form); var summary_product_tpl = $('.' + options.summary_product_tpl_class, $form)[0].outerHTML; if (!summary_product_tpl) { alert('Summary product template is not found.'); return; } $('.' + options.summary_product_tpl_class, $form).remove(); var _current_scroll_pos = 0; var $overlay = $('.partner-info-overlay'); $('.product-info-btn').on('click', function () { var $this = $(this); var selector = $this.data('product-info'); $overlay.find(selector).show(); $overlay.show(); _current_scroll_pos = document.documentElement.scrollTop || document.body.scrollTop $(document).scrollTop(0); productGtmEvent('Information', { title: $this.data('apiname'), price: $this.data('price'), }); return false; }); $overlay.on('click', function () { $(this).hide(); $overlay.find('[id^="product-info-"]').hide(); $(document).scrollTop(_current_scroll_pos); }); var $products = $('.products-list', $form); if ($products.length) { $products.each(function (i, el) { // partner block $('.add_btn', el).on('click', add_product); $('.remove_btn', el).on('click', remove_product); }); } $('ul>li', $summary_products).each(function (i, el) { var li = $(el); li.find('.remove_btn').on('click', remove_product); $summary_products.show(); }); function productGtmEvent(action, product) { fasoon_gtm.push({ "event": "company_foundation", "step_number": "6", "step_progress": "In Progress", "item_category": "Additional Services", "item_action": action, "item_name": product.title, "item_currency": options.currency, "item_price": product.price, }); } function add_product(ev) { var target = $(ev.currentTarget); var product_id = target.data('id'); var product_title = target.data('title'); var product_price = target.data('price'); var product_apiname = target.data('apiname') var li = $(summary_product_tpl).clone(); li.removeClass(options.summary_product_tpl_class); li.find('input[type=hidden]').val(product_id); li.find('.remove_btn').on('click', remove_product); li.find('.remove_btn').attr('data-id', product_id); li.find('.title').html(product_title); li.find('.price').html('CHF ' + QuotePriceStep6.formatPrice(product_price)); li.attr('data-id', product_id); li.attr('data-price', product_price); li.attr('data-apiname', product_apiname); $('ul', $summary_products).append(li); $summary_products.show(); $products.find('.add_btn[data-id=' + product_id + ']').addClass('hidden'); $products.find('.remove_btn[data-id=' + product_id + ']').removeClass('hidden'); QuotePriceStep6.setActivePaymentMethod(); // update summary productGtmEvent('Add', { title: product_apiname, price: product_price, }); } function remove_product(ev) { var product_id = $(ev.currentTarget).data('id'); var li = $('li[data-id=' + product_id + ']', $summary_products); productGtmEvent('Remove', { title: li.data('apiname'), price: li.data('price'), }); li.remove(); $products.find('.remove_btn[data-id=' + product_id + ']').addClass('hidden'); $products.find('.add_btn[data-id=' + product_id + ']').removeClass('hidden'); if (!$('ul>li', $summary_products).length) { $summary_products.hide(); } QuotePriceStep6.setActivePaymentMethod(); // update summary } }); })(jQuery);