$(document).ready(function(){ /* $(window).scroll(function () { setFloatCasePosition(); }); function setFloatCasePosition() { var scrollPosition = $(window).scrollTop(); var caseItem = $('#header .case'); if (!caseItem.hasClass('floatable')) { return true; } var casePosition = 133; var bodyContentWidth = $('#bodyContent').width(); var windowWidth = $(window).width(); var caseRight = (windowWidth-bodyContentWidth)/2; if (scrollPosition>casePosition) { caseItem.addClass('caseFloat'); caseItem.css('right', caseRight); } else { caseItem.removeClass('caseFloat'); caseItem.css('right', 7); } } */ $.fn.showHint = function (hintText, e, action) { var hint; if ($("#hint").length) { hint = $("#hint"); } else { $('body').append('
'); hint = $("#hint"); } var caseItem = $('header .case'); hint.html(hintText); hint.fadeTo(0, 0); hint.css('left', e.pageX+15); hint.css('top', e.pageY+5); hint.css('display', 'block'); if (action=='add') { hint.fadeTo(10, 1).delay(800).animate({left:caseItem.offset().left-20, top: caseItem.offset().top-32, opacity:0.5}, 600).fadeTo(10,0); } else { hint.fadeTo(10, 1).delay(800).fadeTo(10,0).css('display', 'none'); } } function hideCase() { var caseHint = $('#caseHint'); caseHint.css('display', 'none'); caseHint.removeClass('showLast'); } $.fn.showCaseHint = function () { // var deviceAgent = navigator.userAgent.toLowerCase(); // var agentID = deviceAgent.match(/(iphone|ipod|ipad|android|iemobile|ppc|smartphone|blackberry|webos)/); // if (!agentID) { var caseHint = $('#caseHint'); setTimeout(hideCase, 5000); caseHint.addClass('showLast'); caseHint.fadeTo(10, 0); caseHint.css('display', 'block'); caseHint.fadeTo(10, 1).delay(5000).fadeTo(10,0); // } else { // var caseHint = $('#caseHint'); // caseHint.addClass('showLast'); // $('body').addClass('bland'); // caseHint.fadeTo(10, 1); // } } /* $("#header .case ").live("click", function() { window.location.href = '/case/'; }); */ $("body").on('click', '#caseHint .h .btn_close', function(e) { var caseHint = $('#caseHint'); caseHint.css('display', 'none'); caseHint.removeClass('showLast'); $('body').removeClass('bland'); return false; }); $("body").on('click', '.addCard', function(e) { var self = $(this); var item_id = $('.spec li.selected select.variant ').val(); if (item_id == undefined) { var item_id = $('.spec li.selected').attr('item_id'); } if (item_id == undefined) { item_id = $(this).attr('item_id'); } var qty = $(this).parents('.addCaseBlock').find('input').val(); if (qty==undefined) { qty = 1; } var params = { item_id: item_id, addAction: "inc", qty: qty } $.ajax({ url: "/ajax_case.phtml", data: params, type: 'GET', cache: false, success: function(html) { $("header .case").html(html); /* self.html('Перейти в корзину'); self.removeClass('addCard'); self.attr('href', '/case/'); $('.goodAdded').addClass('show'); */ $(this).showCaseHint(); } }); return false; }) $("body").on('click', '.caseDel', function(e) { var item_id = $(this).attr('item_id'); var size_id = $(this).attr('size_id'); params = { item_id: item_id, size_id: size_id, action: "rm" }; $.ajax({ url: "/ajax_case.phtml", data: params, type: 'GET', cache: false, success: function(html) { $(".casePage .caseBody").html(html); $.ajax({ url: "/ajax_case.phtml", type: 'GET', cache: false, success: function(html) { $("header .case").html(html); } }); } }); }); $("body").on('click', '.promoAdd', function(e) { var code = $("#promo").val(); params = { code: code, action: "setPromoCode" }; $.ajax({ url: "/ajax_case.phtml", data: params, type: 'GET', cache: false, success: function(html) { $(".casePage .caseBody").html(html); $.ajax({ url: "/ajax_case.phtml", type: 'GET', cache: false, success: function(html) { $("header .case i>div").html(html); } }); } }); }); $("body").on('click', '.promoRemove', function(e) { var code = $("#promo").val(); params = { code: code, action: "removePromoCode" }; $.ajax({ url: "/ajax_case.phtml", data: params, type: 'GET', cache: false, success: function(html) { $(".casePage .caseBody").html(html); $.ajax({ url: "/ajax_case.phtml", type: 'GET', cache: false, success: function(html) { $("header .case i>div").html(html); initXForm(); } }); } }); }); $("body").on('click', ".caseTable .qty i", function(e) { var action= ($(this).hasClass('inc')?'inc':'dec'); var item_id = $(this).parents('tr').attr('item_id'); var size_id = $(this).parents('tr').attr('size_id'); var type = 'qty'; params = { item_id: item_id, size_id: size_id, action: action, type: type }; $.ajax({ url: "/ajax_case.phtml", data: params, type: 'GET', cache: false, success: function(html) { $(".casePage .caseBody").html(html); $.ajax({ url: "/ajax_case.phtml", type: 'GET', cache: false, success: function(html) { $("header .case ").html(html); } }); } }); }); $("body").on('change', ".caseTable .lookup_qty", function(e) { var action= 'set'; var item_id = $(this).parents('tr').attr('item_id'); var size_id = $(this).parents('tr').attr('size_id'); var type = 'qty'; var qty = $(this).val(); params = { item_id: item_id, size_id: size_id, action: action, type: type, qty: qty }; $.ajax({ url: "/ajax_case.phtml", data: params, type: 'GET', cache: false, success: function(html) { $(".casePage .caseBody").html(html); $.ajax({ url: "/ajax_case.phtml", type: 'GET', cache: false, success: function(html) { $("header .case").html(html); } }); } }); }); /* $(".caseTable .q input").live('keyup', function(e) { self = $(this); t_event = e; clearTimeout(t); t=setTimeout("timeUpdateQty()",1000); }); $("#createOrderButton").click(function() { var fio = $(".caseForm #fio").val(); var email = $(".caseForm #email").val(); var tel = $(".caseForm #tel").val(); var orderComment = $(".caseForm #orderComment").val(); $.ajax({ url: "/ajax_case.phtml", data: {fio: fio, email: email, tel:tel, orderComment:orderComment, action: 'createOrder'}, type: 'POST', cache: false, success: function(html) { alert('Ваш заказ принят, мереждер в ближайшее время '); } }); }) */ $.fn.createOrder = function(params) { // params = { // action: "create" // }; $.ajax({ url: "/auth/ajax_order.phtml", data: params, type: 'GET', cache: false, dataType: 'json', success: function(data) { if (data.status=='ok') { // alert('2'); window.dataLayer = window.dataLayer || []; dataLayer.push({ 'event': 'gtm-event', 'gtm-event-category': 'form', 'gtm-event-action': 'order', 'gtm-event-label': 'create', 'gtm-non-interaction': 'False' }); if (params.type=='getDiscount') { console.log('getDiscount'); dataLayer.push({ 'event': 'event-get-discount', 'order-number': data.npp, 'order_id': data.order_id, 'pageUrl': '', 'fio': data.fio, 'email': data.email, 'city': data.city, 'tel': data.tel, 'message': data.message }); $.fancybox({ 'padding' : 20, 'transitionIn' : 'none', 'transitionOut' : 'none', 'href' : '/forms/getDiscountSuccess.phtml?order_id='+data.order_id, 'type' : 'ajax', 'afterClose' : function() { window.location.reload(); } }); } else { if (params.managerId==undefined || params.managerId=='') { dataLayer.push({ 'ecommerce': { 'currencyCode': data.currency, 'purchase': { 'actionField': { 'id': data.npp, 'affiliation': 'Neopolis casa', 'revenue': data.revenue, 'tax': '0', 'shipping': data.shipping }, 'products': data.products } }, 'event': 'gtm-ee-purchase-event', 'gtm-ee-event-category': 'Enhanced Ecommerce', 'gtm-ee-event-action': 'Purchase', 'gtm-ee-event-non-interaction': 'False', 'fio': data.fio, 'email': data.email, 'city': data.city, 'tel': data.tel, 'message': data.message, 'order_id': data.order_id }); $.fancybox({ 'padding' : 20, 'transitionIn' : 'none', 'transitionOut' : 'none', 'href' : '/order/success.phtml', 'type' : 'ajax', afterClose : function() { window.location.href='/user/'; } }); } else { window.location.href='/admin/comm/'; } } } } }); } $("body").on('click', '.addWish', function(e) { var self = $(this); var item_id = $(this).parents('.itemInfo').attr('item_id'); if (item_id == undefined) { item_id = $(this).parents('.item').attr('item_id'); } if (item_id == undefined) { item_id = $(this).attr('item_id'); } var action = 'inc'; if (self.hasClass('is_wish')) { action = 'rm'; } var params = { item_id: item_id, action: action } $.ajax({ url: "/ajax_wish.phtml", data: params, type: 'GET', cache: false, success: function(html) { $("header .fav i div").html(html); if (action=='inc') { self.addClass('is_wish'); self.find('b').html('Удалить из избранного'); self.find('i').addClass('w_on'); } else { self.removeClass('is_wish'); self.find('b').html('Добавить в избранное'); self.find('i').removeClass('w_on'); } } }); return false; }); $("body").on('click', '.addCompare', function(e) { var self = $(this); var item_id = $(this).parents('.itemInfo').attr('item_id'); if (item_id == undefined) { item_id = $(this).parents('.item').attr('item_id'); } if (item_id == undefined) { item_id = $(this).attr('item_id'); } var action = 'inc'; if (self.hasClass('is_wish')) { action = 'rm'; } var params = { item_id: item_id, action: action } $.ajax({ url: "/ajax_compare.phtml", data: params, type: 'GET', cache: false, success: function(html) { $("header .comp i div").html(html); self.html('В сравнении'); self.attr('href', '/compare/'); self.removeClass('addCompare'); } }); return false; }); $("table.compare").on('click', '.del', function(e) { var item_id = $(this).attr('item_id'); params = { item_id: item_id, action: "rm" }; $.ajax({ url: "/ajax_compare.phtml", data: params, type: 'GET', cache: false, success: function(html) { window.location.reload(); } }); }); $(".userDiscount .variants > li").click(function() { $(this).siblings().removeClass('selected'); $(this).addClass('selected'); }); $("#caseContainer").on('click', '.count-box a', function(e) { var action= ($(this).hasClass('inc')?'inc':'dec'); var item_id = $(this).parents('.caseItem').attr('item_id'); var type = $(this).parents('.count-box').find('input').attr('name'); params = { item_id: item_id, action: action, type: type }; $.ajax({ url: "/ajax_case.phtml", data: params, type: 'GET', cache: false, success: function(html) { $("#caseContainer").html(html); $.ajax({ url: "/ajax_case.phtml", type: 'GET', cache: false, success: function(html) { $("header .case").html(html); } }); } }); return false; }); $("#caseContainer").on('click', '.removeBtn', function(e) { var action= 'rm'; var item_id = $(this).parents('.caseItem').attr('item_id'); params = { item_id: item_id, action: action }; $.ajax({ url: "/ajax_case.phtml", data: params, type: 'GET', cache: false, success: function(html) { if (html=='') { window.location.reload(); } else { $("#caseContainer").html(html); $.ajax({ url: "/ajax_case.phtml", type: 'GET', cache: false, success: function(html) { $("header .case").html(html); } }); } } }); return false; }); $(".caseBody").on('click', '.back', function(e) { history.back(); return false; }); }); var t; var self; var t_event; function timeUpdateQty() { clearTimeout(t); var item_id = self.parents('tr').attr('item_id'); var qty = self.val(); var type = self.attr('name'); // if (t_event.which > 47 && t_event.which < 58) { if (qty>0) { params = { item_id: item_id, action: 'set', qty: qty, type: type }; $.ajax({ url: "/ajax_case.phtml", data: params, type: 'GET', cache: false, success: function(html) { $(".contentTable #container").html(html); $(this).showHint('Кол-во изменено', t_event); $.ajax({ url: "/ajax_case.phtml", type: 'GET', cache: false, success: function(html) { $("#header .case i").html(html); } }); } }); } }