/** * Front setup. */ function front() { // Handle parsed content. $('.parsed_content').children('p').css({'margin-bottom': '20px'}).find('span').css({'font-size': '100%', 'font-family': 'inherit'}); } $.fn.hasAttr = function(name) { return this.attr(name) !== undefined; }; /** * Shop setup. */ function shop() { // Store default image. img_default = img_active = $('img.slot-image:first').attr('src'); // Bind configs. if ($('#product_configs').children().length) { $('#product_configs div.product_configs_row select').on('change', shop_configs_check); $('#product_configs div.product_configs_row input[type=radio]').on('click', shop_configs_click); $('#product_configs div.product_configs_row label.for').on('click', shop_configs_hover).each(function() { /* mouseenter mouseleave */ if ($(this).prev('input').is(':checked')) { shop_configs_hover(false, $(this)); } }); /*var config = $('#product_config input[value="'+ string.substr(1) +'"]').click(); // Hide some stuff. if (!config.length){ shop_configs_check(); }*/ //change image by selectbox var sel = $("#product_configs div.product_configs_row select"); if(sel.length){ sel.on('change', function(){ $(this).find('option').each(function() { if($(this).is(':selected') && $(this).hasAttr('data-target') && $(this).attr('data-target').length > 0){ $('img.slot-image:first').attr('src', $(this).attr('data-target')); } }); }); } } // Bind options. $(document).on('change', '#product_options div.product_options_row select', shop_options_total); $(document).on('click', '#product_options div.product_options_row input', shop_options_total); // Run some stuff. shop_options_total(false); } function shop_configs_hover(event, obj) { // Default to click. if (event == false) { event = {type : 'click'}; } else { obj = $(this); } switch (event.type) { case 'click': case 'mouseenter': var next = obj.next('input'); if (next.length) { $('img.slot-image:first').attr('src', next.val()).parent().parent().attr('href', next.val()); if (event.type == 'click') { img_active = next.val(); } } else { $('img.slot-image:first').attr('src', img_default).parent().parent().attr('href', next.val()); } break; case 'mouseleave': if (obj.parent().hasClass('active')) { break; } $('img.slot-image:first').attr('src', img_active ? img_active : img_default).parent().parent().attr('href', img_active ? img_active : img_default); break; } } /** * Handle config clicks. */ function shop_configs_click() { // Get value. var obj = $(this); var row = obj.closest('div.product_configs_row'); // Remove actives. obj.parent().addClass('active').siblings().removeClass('active'); // Handle color label. if (row.hasClass('attr_color')) { row.children('span.color').text($(this).siblings('label').text()); shop_configs_check(); } // Run check. $('#product_form').on('submit', shop_configs_check); } /** * Check configs and modify price. */ function shop_configs_check(event) { var state = true, string = ''; // Check all config rows to see if config is complete. $('#product_configs .product_configs_row').not('.quantity').each(function() { var obj = $(this).find('select, input:checked'); var val = obj.val(); if (typeof val == 'undefined') { state = false; return false; } string += ';'+ obj.attr('rel') +':'+ val; }); // Select a config. var config = $('#product_config input[value="'+ string.substr(1) +'"]').click(); // Hide some stuff. if (!config.length || !state) { $('div.product_message').show(); $('#product_options').hide(); $('div.base_price, div.price').text('---'); return false; } // Retrieve and split the data. var data = config.attr('rel').split(':'); // Set base and price. $('div.base_price').text(data[1]); $('div.price').text(data[2]); $('div.product_message').hide(); $.ajax({ type: "POST", data: $('#product_form').serialize(), url: this_url +'?block=product_options&product='+ $('#product_id').val() +'&cart='+ $('#cart_id').val(), success: function(data) { var orig = $('#product_options div.product_options_row'); $(data).filter('div.product_options_row').each(function(key, val) { orig.eq(key).html($(this).html()); }); shop_options_total(false); } }); $('#product_options').show(); return true; } function shop_options_total(event) { if (event && $(this).is('input[type="radio"]')) { $(this).closest('.product_options_section').find('select').hide().attr('disabled', true); $(this).siblings('select').show().attr('disabled', false); } var total = parseFloat($('.price:first').text().substr(2).replace('.', '').replace(',', '.')); $('#product_options div.product_options_row .product').each(function() { if ($(this).is('input') && !$(this).is(':checked')) { return true; } var qt = $(this).closest('div.product_options_row').find('.quantity').val(); var val = $(this).val().split(':'); if (!qt || !val[0]) { return true; } total += val[1] * qt; }); $('#product_options_total span.total').text(number_format(total, 2, ',', '.')); }