basket.js
2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
(function($){
$.fn.basket = function(callerSettings) {
var basket_id = this;
var find_products = function(){
$("a[rel~='product']").each(function (i) {
$(this).bind('click',function(){
var rel = $(this).attr('rel');
var id = rel.substr(8);
var count = 1;
go_product({product_id : id,count:count});
return false;
})
})
}
var go_product = function(data){
$.get("/ajax/basket.php", data ,
function(data){
alert_msg("Òîâàð äîáàâëåí â êîðçèíó!");
start_basket();
});
}
var start_basket = function(){
$.get("/ajax/basket.php",
function(data){
$(basket_id).html(data);
});
}
find_products();
start_basket();
var find_compare = function(){
$("input[rel~='compare']").each(function (i) {
$(this).bind('click',function(){
var id = $(this).val();
$.get("/ajax/compare.php", {product_id : id} ,
function(data){
alert(data);
is_compare_products();
});
})
})
}
var is_compare_products = function(){
$.get("/ajax/compare_count.php",
function(data){
if(data>0){
$("#compare").css("display","block");
}
});
}
var alert_msg = function(msg){
winW = document.body.offsetWidth;
winH = document.body.offsetHeight
$('.cabinet_box').remove();
$('#cabinet_form').remove();
$('body').append('<div class="cabinet_box"></div>');
$('body').append('<div id="cabinet_form"></div>');
$('#cabinet_form').append('<div class="wrp"></div>');
$('#cabinet_form').css( "width", '450px' );
$('#cabinet_form').css( "height", '200px' );
$('#cabinet_form').css( "left", ((winW-450)/2)+'px' );
var scrollTop = document.documentElement.scrollTop
if (navigator.userAgent.toLowerCase().indexOf('chrome') > -1) {
scrollTop = document.body.scrollTop;
}
$('#cabinet_form').css( "top", (scrollTop+200)+'px' );
$('#cabinet_form .wrp').append('<img src="/img/close2.jpg" id="cabinet_close" border="0" width="32" height="32" align="right" />');
$('#cabinet_form .wrp').append('<h1>Êîðçèíà</h1>');
$('#cabinet_form .wrp').append('<hr />');
app = '<center>';
app += msg;
app += '<br /><br /><input type="submit" class="submit4" style="text-transform:none;" value="Ïåðåéòè â êîðçèíó" onClick="document.location=\'/catalogs/basket/\'" /> ';
app += '<input type="submit" class="submit4" style="text-transform:none;" id="p_close" value="Ïðîäîëæèòü ïîêóïêè" />';
app += '</center>';
$('#cabinet_form .wrp').append(app);
$(".cabinet_box, #cabinet_close, #p_close").click(function() {
$('.cabinet_box').remove();
$('#cabinet_form').remove();
});
}
find_compare();
is_compare_products();
}
})(jQuery);