$(function () { $(".carousel-warrior").owlCarousel({ responsive: { 0: {items: 1}, 600: {items: 3}, 1000: {items: 3} }, animateOut: 'fadeOut', loop: true, autoplay: true, autoplayTimeout: 10000, autoplayHoverPause: true }); $(".variantSelector").on("change", function () { var id = $(this).data('id'), form = $(this).closest('form'), val = $(this).val(), max = $(this).find(":selected").data("max"), order = $(this).find(":selected").data("onlyorder"), price = "" + $(this).find(":selected").data("price-original") + " " + $(this).find(":selected").data("price"); $("#variant" + id).attr("name", "cart" + val).attr("max", max); form.find(".onlyorder").hide(); //console.log(order); if (order === 1) { price = "" + $(this).find(":selected").data("price") + " "; form.find(".onlyorder").show(); //form.find("[type='submit']").hide(); } else { form.find(".onlyorder").hide(); //form.find("[type='submit']").show(); } $("#price" + id).html(price); $("#dealprice" + id).html(price); }); $(".variantSelector").each(function () { $(this).children("option:first").attr('selected', 'selected').change(); }); $(".lazy").lazyload({effect: "fadeIn"}); $('[data-toggle="tooltip"]').tooltip(); $('.tobasket').bind('click touchstart', add2cart); $("#registr_link,.registr_link").bind("click", register_link); $(".login_link").bind("click touchstart", login_link); $(".gallery").lazyload({effect: "fadeIn"}).colorbox({rel: 'gallery', maxWidth: '95%', maxHeight: '95%'}); $(".dop_gallery").lazyload({effect: "fadeIn"}).colorbox({rel: 'dop_gallery', maxWidth: '95%', maxHeight: '95%'}); $(".mod-links").click(function () { $href = $(this).attr("href"); if ($href.indexOf("?") >= 0) { link = $href + "&"; } else { link = $href + "?"; } $(".mod-links").colorbox({maxWidth: '95%', maxHeight: '95%', href: "" + link + "isNaked=1"}); }); setView(); modalBasket(); $("[type='tel']").keypress(function (e) { var symbol = (e.which) ? e.which : e.keyCode; console.log(symbol); if (symbol == 43 || symbol == 45 || symbol == 46 || symbol == 32 || (symbol > 47 && symbol < 58)) { return true; } return false; }); }); $(document).on('cbox_open', function () { $('body').css({overflow: 'hidden'}); jQuery("#colorbox").swipe({ //Generic swipe handler for all directions swipeLeft: function (event, direction, distance, duration, fingerCount) { jQuery.colorbox.prev(); }, swipeRight: function (event, direction, distance, duration, fingerCount) { jQuery.colorbox.next(); }, //Default is 75px, set to 0 for demo so any distance triggers swipe threshold: 0 }); }).on('cbox_closed', function () { $('body').css({overflow: ''}); }); function tableSize(which, form) { var f = document.form[form]; for (var i = 0; i < f.elements.length; i++) { if ((f.elements[i].type == 'select-one')) { f.elements[i].selectedIndex = which; } } } function modalBasket() { $('#basketModal').on('show.bs.collapse', function () { $.post("/netcat/modules/netshop/actions/cart.php", {json: 1}, function (response) { console.log(response); // Обновим блок «Корзина» на странице var totalItems = response.TotalItemCount; var cartHtml = "
" + v.Message + "
"); console.log("" + v.Message + "
"); }); return true; } return true; } function add2cart(e) { var button = $(this), itemKey = button.data('itemkey'), form = $(e.target).closest('form'); $("#content").fadeTo(1, 0.5, function () { $("#basketResponse").fadeTo("fast", 1).html("").show(); $.post(form.attr('action'), form.serialize() + "&json=1", function (response) { var res = processCartResponse(response); // $("#basketResponse").html(response); if (res) { $("#basketResponse").html("Товар добавлен в корзину").delay(1000).hide('100', function () { $("#content").fadeTo(1, 1); }); } // else { // $("#basketResponse").html(res).delay(5000).hide('100', function () { // $("#content").fadeTo(1, 1); // }); // } $("#basketResponse") }, 'json'); }); return false; } function remove4cart(e) { var button = $(this), itemKey = button.attr('data-itemkey'), form = $(e.target).closest('form'); $.post(form.attr('action'), form.serialize() + "&json=1", function (response) { processCartResponse(response); if (response.TotalItemCount > 0) { $("#basketShow").css({visibility: 'visible'}).show(); } else { $("#basketShow").css({visibility: 'hidden'}).hide(); } $("#basketResult").html("Товар удален из корзины").show().delay(5000).hide('100'); button.removeClass('delete4cart').addClass('add2cart').html("В корзину").unbind('click').bind('click', add2cart); form.find("[name='cart" + itemKey + "']").val('1'); }, 'json'); return false; } function processRegistrForm(event) { event.preventDefault(); $("#adminForm").find(".form-group").removeClass('has-error').children(".help-block").empty(); var flds = $("#adminForm").serialize(); $.post($("#adminForm").attr("action") + "?json=1&isNaked=1", flds, function (data) { console.log(data); if (!data.result) { // if error $.each(data.errors, function (index, value) { b = $("#adminForm").find("#f_" + index).parent().parent(".form-group"); b.addClass('has-error'); b.children(".help-block").html(value); }); } else { $("#adminForm").replaceWith(data.success); console.log('form submit'); } }, 'json'); } function processAuthForm(resp) { $('input').each(function () { $(this).removeAttr('disabled'); }); resp = JSON.parse(resp); console.log(resp); if (!resp.login) { $('#auth_status').html('Не угадали. Попробуйте еще раз.').show(); return false; } else { if (resp.login) { $('#registr_block').html(resp.login); $(".registr-icon a").attr("href", "#").attr("title", "Выход"); $(".registr-icon a i").addClass("fa-sign-out").removeClass("fa-sign-in"); $("#modalWindow").modal('hide'); return false; } else { $('#auth_status').html('Не угадали. Попробуйте еще раз.').show(); return false; } } } /** * Склонение русских слов * @param {Number} itemQuantity Количество товаров * @param {String} one «товар» * @param {String} two «товара» * @param {String} many «товаров» * @returns {String} */ function pluralForm(itemQuantity, one, two, many) { itemQuantity = Math.abs(itemQuantity) % 100; var underHundred = itemQuantity % 10, result = many; if (underHundred > 1 && underHundred < 5) { result = two; } if (underHundred == 1) { result = one; } if (itemQuantity > 10 && itemQuantity < 20) { result = many; } return result; }