$(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 = $(this).parents('.itemInfo').attr('item_id'); var size_id = 0; if (item_id == undefined) { item_id = $(this).parents('.item').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, size_id: size_id, addAction: "inc", qty: qty } $.ajax({ url: "/ajax_case.phtml", data: params, type: 'GET', cache: false, success: function(html) { $("header .case i div").html(html); self.html('Перейти в корзину'); self.removeClass('addCard'); self.attr('href', '/case/'); $('.goodAdded').addClass('show'); fbq('track', 'AddToCart', {content_type: 'product', content_ids: item_id}); $(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 i>div").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 i>div").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 i>div").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: "/order/ajax_order.phtml", data: params, type: 'GET', cache: false, success: function(html) { if (html=='ok') { window.location.href='/order/success/'; } } }); } $("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'); }); }); 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); } }); } }); } }