Subversion Repositories SmartDukaan

Rev

Rev 4126 | Rev 4237 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4126 varun.gupt 1
$(function(){
2
	/** Sidebar Widgets **/
3
 
4
	$('.common-widget-top-bar').live('click', function(){
5
		var isColapsed = $(this).data('is_colapsed') == true ? true : false;
6
		var widgetBox = $(this).siblings('.common-widget-content-area');
7
		var controlBox = $(this).siblings('.common-widget-control-bar');
8
		var controlBoxArrowImg = $(this).find('img');
4210 varun.gupt 9
 
4126 varun.gupt 10
		if (isColapsed)	{
11
			if(controlBox.length > 0)	{
12
				$(controlBox).slideDown('fast', function(){
13
					$(widgetBox).slideDown();
14
					$(controlBoxArrowImg).attr('src', '/images/IconDownArrow_UnselectedTab.png');
15
				});
16
			} else	{
17
				$(widgetBox).slideDown();
18
				$(controlBoxArrowImg).attr('src', '/images/IconDownArrow_UnselectedTab.png');
19
			}
20
		} else	{
21
			$(widgetBox).slideUp(function(){
22
				$(controlBox).slideUp('fast');
23
				$(controlBoxArrowImg).attr('src', '/images/IconRightArrow_UnselectedTab.png');
24
			});
25
		}
26
		$(this).data('is_colapsed', !isColapsed);
27
	});
28
 
29
	/**
30
	 * Update count of products checked for comparison
31
	 **/
32
	$('#myresearch input[type="checkbox"]').live('click', function(){
33
		$('#research_compare_count').html($('#myresearch input[type="checkbox"]:checked').length);
34
	});
35
 
36
	$("#research_compare").live('click', function(){
37
		var seldata = "";
38
		var tot = 1;
39
		var saprt = "";
40
		var par = $('#myresearch').find('input[type=checkbox]:checked');
41
 
42
		$(par).each(function(){
43
			if(tot == 1)	{
44
				seldata += "p" + tot + "=" + $(this).val();
45
			} else	{
46
				seldata += "&p" + tot + "=" + $(this).val();
47
			}
48
			tot ++;
49
		});
50
 
51
		if(tot > 6)	{
52
			alert("Can compare upto five products only.");
53
		} else if(tot > 2)	{
54
			window.location = "/compare-mobile-phones?" + seldata;
55
		} else	{
56
			alert("Please select atleast two products");
57
		}
58
	});
59
 
60
	$("#research_delete").live('click', function(){
61
		var research_tot = $("#research_total").val();
62
		var seldata = [];
63
		var tot = 0;
64
		var saprt = "";
65
		var par = $('#myresearch').find('input[type=checkbox]:checked');
66
 
67
		$(par).each(function(){
68
			seldata.unshift($(this).val());
69
			tot ++;
70
		});
71
 
72
		if(tot > 0)	{
73
			var t = (research_tot * 1) - (tot * 1);
74
			$("#research_total").val(t);
75
 
76
			jQuery.ajax({
77
				type: "GET",
78
				url: "/deletefromresearch/[" + seldata + "]?_method=delete",
79
				success: function(msg)	{
80
					jQuery.each(seldata, function(intIndex, objValue){
81
						delete_from_storage_set("resitems", objValue);
82
						$("#myresearch").find("#" + objValue).fadeOut('slow', function() {
83
							$(this).remove();
84
							if(t === 0)	{
85
								$("#research_default").css("display", "block");
86
							}
87
						});
88
					});
89
				}
90
			});
91
		} else	{
92
			alert("Please select atleast one product");
93
		}
94
	});
95
 
96
	// No uid cookie
97
	if (!$.cookie("uid"))	{
98
		// No uid in storage
99
		if (!$.Storage.get("uid"))	{
100
			if (!$.Storage.get("resitems"))	{
101
				$.Storage.set("resitems", "[]");
102
			}
103
			if (!$.Storage.get("histitems"))	{
104
				$.Storage.set("histitems", "[]");
105
			}
106
		}
107
		else	{			// uid in storage : logout
108
			$.Storage.remove("uid");
109
			$.Storage.set("resitems", "[]");
110
			$.Storage.set("histitems", "[]");
111
		}
112
		load_research_widget();
113
		load_history_widget();
114
	}
115
	else	{				// With uid cookie
116
		var cookie = $.cookie("uid");
117
		// Just logged in merge storage items
118
		if (!$.Storage.get("uid"))	{
119
			$.Storage.set("uid", cookie);
120
			merge_history_items();
121
			load_research_items();
122
		}
123
		else	{
124
			// UID changed
125
			if ( cookie != $.Storage.get("uid"))	{
126
				$.Storage.set("uid", cookie);
127
				$.Storage.set("resitems", "[]");
128
				$.Storage.set("histitems", "[]");
129
				merge_history_items();
130
				load_research_items();
131
			}
132
			else	{		// Uid is same
133
				if (!$.Storage.get("resitems"))	{
134
					$.Storage.set("resitems", "[]");
135
					load_research_items();
136
				}
137
				else	{
138
					load_research_widget();
139
				}
140
 
141
				if (!$.Storage.get("histitems"))	{
142
					$.Storage.set("histitems", "[]");
143
					merge_history_items();
144
				}
145
				else	{
146
					load_history_widget();
147
				}
148
			}
149
		}
150
	}
151
});