Subversion Repositories SmartDukaan

Rev

Rev 6245 | Rev 6262 | 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(){
4984 varun.gupt 2
	function CollapsibleWidget(container)	{
3
 
4
		this.widgetContainer = container;
5
		this.collapsbiles = $(container).children('.common-widget-control-bar, .common-widget-content-area');
6
		this.isCollapsed = null;
7
 
8
		this.collapse = function()	{
9
			$(this.collapsbiles).each(function()	{
10
				$(this).slideUp();
11
			});
12
			this.isCollapsed = true;
13
		};
14
 
15
		this.open = function()	{
16
			$(this.collapsbiles).each(function()	{
17
				$(this).slideDown();
18
			});
19
			this.isCollapsed = false;
20
		};
21
 
22
		this.test = function()	{
23
		};
24
	}
4798 varun.gupt 25
 
4984 varun.gupt 26
	ResearchWidget.prototype = new CollapsibleWidget();
27
	ResearchWidget.prototype.constructor = CollapsibleWidget;
28
 
29
	function ResearchWidget(container)	{
30
		CollapsibleWidget.call(this, container);
31
	}
32
 
4798 varun.gupt 33
	function updateCompareCount()	{
34
		$('#research_compare_count').html($('#myresearch input[type="checkbox"]:checked').length);
35
	}
36
 
4126 varun.gupt 37
	/** Sidebar Widgets **/
4237 varun.gupt 38
 
39
	$('#shoppingExpInfo').click(function(){
40
		$.colorbox({
4284 varun.gupt 41
    		width: "550px",
42
    		height: "320px",
4237 varun.gupt 43
    		inline: true,
44
    		href: "<h3>Shopping with Saholic.com is completely safe</h3><br />" +
4284 varun.gupt 45
		"<b>1.</b> We are part of Spice Group - India's # 1 Mobile retailer.<br /><br />" +
46
		"<b>2.</b> We procure directly from the Manufacturers - Hence we only sell genuine products with full Manufacturer Warranty.<br /><br />" +
47
		"<b>3.</b> We provide free Next Day Delivery to most locations - You can check the delivery time to your location by entering your pin code on the product page.<br /><br />" +
6173 kshitij.so 48
		"<b>4.</b> We use the best Internet Security technology - Your payment is 100% secure.<br />",
4372 varun.gupt 49
			onComplete: function(){
6261 amit.gupta 50
				trackEventWithGA('Widget', 'Safe shopping sticky banner is clicked', '');
4372 varun.gupt 51
			}
4237 varun.gupt 52
    	});
53
	});
6245 kshitij.so 54
 
55
 
56
	$('#pickupstoreInfo').click(function(){
57
		$.colorbox({
58
    		width: "550px",
59
    		height: "370px",
60
    		inline: true,
61
    		href: "<h3>Frequently Asked Questions</h3><br />" +
62
		"<b>Q)</b> What is 'Buy Online & Pickup in Store' ?<br /><br />" +
63
		"<b>A)</b> Buy Online from Saholic.Com and pickup your product from the nearest Spice Hotspot Retail Store.<br /><br />" +
64
		"<b>Q)</b> How do i avail this facility ?<br /><br />" +
65
		"<b>A)</b> Simply select Pickup In Store On the Shipping Page and select your nearest store. Please note this facility is available only in Delhi/NCR.</a><br /><br />"+
66
		"<b>Q)</b> When will the product be available for pickup ?<br /><br />" +
67
		"<b>A)</b> You can enter your pin code on the Product Page to find estimated time to deliver. After placing the order we will also give you the estimated date for pickup.</a><br /><br />",
68
 
69
			onComplete: function(){
6261 amit.gupta 70
				var ev = "Product Page"
71
				var label = document.URL.substring(document.URL.lastIndexOf('/')+1);
72
				if (label=="")
73
				{
74
					ev = "Home Page"
75
				}
76
				trackEventWithGA('Pickup in Store LightBox', ev, label);
6245 kshitij.so 77
			}
78
    	});
79
	});
4126 varun.gupt 80
 
5420 amit.gupta 81
	$('.common-widget-top-bar').live('click', function(e, callback){
4126 varun.gupt 82
		var isColapsed = $(this).data('is_colapsed') == true ? true : false;
83
		var widgetBox = $(this).siblings('.common-widget-content-area');
84
		var controlBox = $(this).siblings('.common-widget-control-bar');
85
		var controlBoxArrowImg = $(this).find('img');
4210 varun.gupt 86
 
4126 varun.gupt 87
		if (isColapsed)	{
88
			if(controlBox.length > 0)	{
89
				$(controlBox).slideDown('fast', function(){
5420 amit.gupta 90
					$(widgetBox).slideDown('fast', callback);
4126 varun.gupt 91
					$(controlBoxArrowImg).attr('src', '/images/IconDownArrow_UnselectedTab.png');
92
				});
93
			} else	{
94
				$(widgetBox).slideDown();
95
				$(controlBoxArrowImg).attr('src', '/images/IconDownArrow_UnselectedTab.png');
96
			}
97
		} else	{
98
			$(widgetBox).slideUp(function(){
99
				$(controlBox).slideUp('fast');
100
				$(controlBoxArrowImg).attr('src', '/images/IconRightArrow_UnselectedTab.png');
101
			});
102
		}
103
		$(this).data('is_colapsed', !isColapsed);
104
	});
105
 
106
	/**
107
	 * Update count of products checked for comparison
108
	 **/
109
	$('#myresearch input[type="checkbox"]').live('click', function(){
4798 varun.gupt 110
		updateCompareCount();
4126 varun.gupt 111
	});
112
 
113
	$("#research_compare").live('click', function(){
114
		var seldata = "";
5322 amit.gupta 115
		var prodnames = "";
4126 varun.gupt 116
		var tot = 1;
117
		var saprt = "";
118
		var par = $('#myresearch').find('input[type=checkbox]:checked');
4926 varun.gupt 119
		var haveSameProductType = true;
120
		var productType = null;
121
 
4126 varun.gupt 122
		$(par).each(function(){
4926 varun.gupt 123
 
124
			if(productType != null && productType != $(this).attr('producttype'))	{
125
				haveSameProductType = false;
126
			}
127
			productType = $(this).attr('producttype');
128
 
4126 varun.gupt 129
			if(tot == 1)	{
5358 amit.gupta 130
				prodnames += $(this).attr("title").replace(/ +/g, '-').replace(/\/+/g,'-').replace(/-+/g,'-').toLowerCase();
4126 varun.gupt 131
				seldata += "p" + tot + "=" + $(this).val();
132
			} else	{
133
				seldata += "&p" + tot + "=" + $(this).val();
5358 amit.gupta 134
				prodnames += "-vs-" + $(this).attr("title").replace(/ +/g, '-').replace(/\/+/g,'-').replace(/-+/g,'-').toLowerCase();
4126 varun.gupt 135
			}
136
			tot ++;
137
		});
4984 varun.gupt 138
 
4926 varun.gupt 139
		if(! haveSameProductType)	{
140
			alert("Only products of same category can be compared");
141
		} else if(tot > 6)	{
4126 varun.gupt 142
			alert("Can compare upto five products only.");
143
		} else if(tot > 2)	{
5552 phani.kuma 144
			window.location = "/compare-" + productType.replace(/ +/g, '-').toLowerCase() + "/" + prodnames + "?" + seldata+"&fromsrc=comparison_widget";
4126 varun.gupt 145
		} else	{
146
			alert("Please select atleast two products");
147
		}
148
	});
149
 
150
	$("#research_delete").live('click', function(){
151
		var research_tot = $("#research_total").val();
152
		var seldata = [];
153
		var tot = 0;
154
		var saprt = "";
155
		var par = $('#myresearch').find('input[type=checkbox]:checked');
156
 
157
		$(par).each(function(){
158
			seldata.unshift($(this).val());
159
			tot ++;
160
		});
161
 
162
		if(tot > 0)	{
163
			var t = (research_tot * 1) - (tot * 1);
164
			$("#research_total").val(t);
165
 
166
			jQuery.ajax({
167
				type: "GET",
168
				url: "/deletefromresearch/[" + seldata + "]?_method=delete",
169
				success: function(msg)	{
170
					jQuery.each(seldata, function(intIndex, objValue){
171
						delete_from_storage_set("resitems", objValue);
172
						$("#myresearch").find("#" + objValue).fadeOut('slow', function() {
173
							$(this).remove();
174
							if(t === 0)	{
175
								$("#research_default").css("display", "block");
176
							}
177
						});
178
					});
4984 varun.gupt 179
 
4922 varun.gupt 180
					//Updating the count
181
					$('#research_compare_count').html($('#myresearch input[type="checkbox"]:checked').length - seldata.length);
4984 varun.gupt 182
 
183
					if ($('#myresearch input[type="checkbox"]').length - seldata.length <= 0)	{
184
						$("#myresearch").children(".common-widget-top-bar").trigger('click');
185
					}
4126 varun.gupt 186
				}
187
			});
188
		} else	{
189
			alert("Please select atleast one product");
190
		}
191
	});
192
 
193
	// No uid cookie
194
	if (!$.cookie("uid"))	{
195
		// No uid in storage
196
		if (!$.Storage.get("uid"))	{
197
			if (!$.Storage.get("resitems"))	{
198
				$.Storage.set("resitems", "[]");
199
			}
200
			if (!$.Storage.get("histitems"))	{
201
				$.Storage.set("histitems", "[]");
202
			}
203
		}
204
		else	{			// uid in storage : logout
205
			$.Storage.remove("uid");
206
			$.Storage.set("resitems", "[]");
207
			$.Storage.set("histitems", "[]");
208
		}
209
		load_research_widget();
210
		load_history_widget();
211
	}
212
	else	{				// With uid cookie
213
		var cookie = $.cookie("uid");
214
		// Just logged in merge storage items
215
		if (!$.Storage.get("uid"))	{
216
			$.Storage.set("uid", cookie);
217
			merge_history_items();
218
			load_research_items();
219
		}
220
		else	{
221
			// UID changed
222
			if ( cookie != $.Storage.get("uid"))	{
223
				$.Storage.set("uid", cookie);
224
				$.Storage.set("resitems", "[]");
225
				$.Storage.set("histitems", "[]");
226
				merge_history_items();
227
				load_research_items();
228
			}
229
			else	{		// Uid is same
230
				if (!$.Storage.get("resitems"))	{
231
					$.Storage.set("resitems", "[]");
232
					load_research_items();
233
				}
234
				else	{
235
					load_research_widget();
236
				}
237
 
238
				if (!$.Storage.get("histitems"))	{
239
					$.Storage.set("histitems", "[]");
240
					merge_history_items();
241
				}
242
				else	{
243
					load_history_widget();
244
				}
245
			}
246
		}
247
	}
4798 varun.gupt 248
 
249
	function load_research_items(){
250
		jQuery.ajax({
251
			type: "GET",
252
			url: "/myresearch",
253
			cache: false,
254
			success: function(json) {
255
			    $.Storage.set("resitems", json);
256
			    load_research_widget();
257
		    }
258
		});
259
	}
260
 
261
	function load_research_widget(){
262
		var myResearchWidgetContainer = $("#myresearch");
263
 
264
		if($(myResearchWidgetContainer).length == 0) {
265
			return;
266
		}
267
		var resitems = $.Storage.get("resitems");
268
 
269
		if (resitems == "[]") {
270
			var emptyResWidgetHtml = '<table border="0" width="100%" cellspacing="1" cellpadding="0" id="research_default">\
271
		      <tbody>\
272
		        <tr><td align="center"><b>Add items to compare list</b></td></tr>\
273
		       </tbody>\
274
		      </table>';
275
			$(myResearchWidgetContainer).find(".common-widget-content-area").html(emptyResWidgetHtml);
276
			$(myResearchWidgetContainer).children(".common-widget-top-bar").trigger('click');
277
			return;
278
		}
279
		var params = "/" + resitems;
280
 
281
		jQuery.ajax({
282
			type : "GET",
283
			url : "/myresearch" + params,
284
			cache: true,
285
			success : function(html) {
286
	   		    $("#myresearch").html(html);
287
	   			updateCompareCount();
288
 
289
			    // Product Title
290
			    $("#myresearch table td div a.truncate").each(function() {
291
						$(this).truncate({addtitle : true});
292
			    });
293
 
294
			    // Product Price
295
			    $("#myresearch table td div div.price").each(function() {
296
						$(this).truncate({addtitle : true});
297
				});
298
 
299
			    // Product Details
300
			    $("#myresearch table td div div.text").each(function() {
301
						$(this).truncate( {addtitle : true});
302
				});
303
		    }
304
		});
305
	}
4126 varun.gupt 306
});