Subversion Repositories SmartDukaan

Rev

Rev 6264 | Rev 6453 | 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(){
6262 amit.gupta 70
				var ev = "Product Page";
6303 amit.gupta 71
				var label = window.location.pathname;
6264 amit.gupta 72
				if (label=="" || label=="#")
6261 amit.gupta 73
				{
6303 amit.gupta 74
					label = "";
6262 amit.gupta 75
					ev = "Home Page";
6261 amit.gupta 76
				}
6262 amit.gupta 77
				else if (label.indexOf("shipping") != -1){
78
					ev = "Shipping Page";
79
					var blkstr = [];
6263 amit.gupta 80
					jQuery("#cartDetail").find("span.cart-item-name").each(function(key,str){
6262 amit.gupta 81
						blkstr.push(str);
82
					});
6303 amit.gupta 83
					label = blkstr.join(", ");
84
				} else if (label.substr(label.lastIndexOf('/') + 1).length==5 && typeof label.substr(label.lastIndexOf('/') + 1) =="number") {
85
					ev = "Category Page";
86
				} else if (label.substr(label.lastIndexOf('-') + 1).length==7  && typeof label.substr(label.lastIndexOf('-') + 1) =="number") {
87
					ev = "Product Page";
6262 amit.gupta 88
				}
6261 amit.gupta 89
				trackEventWithGA('Pickup in Store LightBox', ev, label);
6245 kshitij.so 90
			}
91
    	});
92
	});
4126 varun.gupt 93
 
5420 amit.gupta 94
	$('.common-widget-top-bar').live('click', function(e, callback){
4126 varun.gupt 95
		var isColapsed = $(this).data('is_colapsed') == true ? true : false;
96
		var widgetBox = $(this).siblings('.common-widget-content-area');
97
		var controlBox = $(this).siblings('.common-widget-control-bar');
98
		var controlBoxArrowImg = $(this).find('img');
4210 varun.gupt 99
 
4126 varun.gupt 100
		if (isColapsed)	{
101
			if(controlBox.length > 0)	{
102
				$(controlBox).slideDown('fast', function(){
5420 amit.gupta 103
					$(widgetBox).slideDown('fast', callback);
4126 varun.gupt 104
					$(controlBoxArrowImg).attr('src', '/images/IconDownArrow_UnselectedTab.png');
105
				});
106
			} else	{
107
				$(widgetBox).slideDown();
108
				$(controlBoxArrowImg).attr('src', '/images/IconDownArrow_UnselectedTab.png');
109
			}
110
		} else	{
111
			$(widgetBox).slideUp(function(){
112
				$(controlBox).slideUp('fast');
113
				$(controlBoxArrowImg).attr('src', '/images/IconRightArrow_UnselectedTab.png');
114
			});
115
		}
116
		$(this).data('is_colapsed', !isColapsed);
117
	});
118
 
119
	/**
120
	 * Update count of products checked for comparison
121
	 **/
122
	$('#myresearch input[type="checkbox"]').live('click', function(){
4798 varun.gupt 123
		updateCompareCount();
4126 varun.gupt 124
	});
125
 
126
	$("#research_compare").live('click', function(){
127
		var seldata = "";
5322 amit.gupta 128
		var prodnames = "";
4126 varun.gupt 129
		var tot = 1;
130
		var saprt = "";
131
		var par = $('#myresearch').find('input[type=checkbox]:checked');
4926 varun.gupt 132
		var haveSameProductType = true;
133
		var productType = null;
134
 
4126 varun.gupt 135
		$(par).each(function(){
4926 varun.gupt 136
 
137
			if(productType != null && productType != $(this).attr('producttype'))	{
138
				haveSameProductType = false;
139
			}
140
			productType = $(this).attr('producttype');
141
 
4126 varun.gupt 142
			if(tot == 1)	{
5358 amit.gupta 143
				prodnames += $(this).attr("title").replace(/ +/g, '-').replace(/\/+/g,'-').replace(/-+/g,'-').toLowerCase();
4126 varun.gupt 144
				seldata += "p" + tot + "=" + $(this).val();
145
			} else	{
146
				seldata += "&p" + tot + "=" + $(this).val();
5358 amit.gupta 147
				prodnames += "-vs-" + $(this).attr("title").replace(/ +/g, '-').replace(/\/+/g,'-').replace(/-+/g,'-').toLowerCase();
4126 varun.gupt 148
			}
149
			tot ++;
150
		});
4984 varun.gupt 151
 
4926 varun.gupt 152
		if(! haveSameProductType)	{
153
			alert("Only products of same category can be compared");
154
		} else if(tot > 6)	{
4126 varun.gupt 155
			alert("Can compare upto five products only.");
156
		} else if(tot > 2)	{
5552 phani.kuma 157
			window.location = "/compare-" + productType.replace(/ +/g, '-').toLowerCase() + "/" + prodnames + "?" + seldata+"&fromsrc=comparison_widget";
4126 varun.gupt 158
		} else	{
159
			alert("Please select atleast two products");
160
		}
161
	});
162
 
163
	$("#research_delete").live('click', function(){
164
		var research_tot = $("#research_total").val();
165
		var seldata = [];
166
		var tot = 0;
167
		var saprt = "";
168
		var par = $('#myresearch').find('input[type=checkbox]:checked');
169
 
170
		$(par).each(function(){
171
			seldata.unshift($(this).val());
172
			tot ++;
173
		});
174
 
175
		if(tot > 0)	{
176
			var t = (research_tot * 1) - (tot * 1);
177
			$("#research_total").val(t);
178
 
179
			jQuery.ajax({
180
				type: "GET",
181
				url: "/deletefromresearch/[" + seldata + "]?_method=delete",
182
				success: function(msg)	{
183
					jQuery.each(seldata, function(intIndex, objValue){
184
						delete_from_storage_set("resitems", objValue);
185
						$("#myresearch").find("#" + objValue).fadeOut('slow', function() {
186
							$(this).remove();
187
							if(t === 0)	{
188
								$("#research_default").css("display", "block");
189
							}
190
						});
191
					});
4984 varun.gupt 192
 
4922 varun.gupt 193
					//Updating the count
194
					$('#research_compare_count').html($('#myresearch input[type="checkbox"]:checked').length - seldata.length);
4984 varun.gupt 195
 
196
					if ($('#myresearch input[type="checkbox"]').length - seldata.length <= 0)	{
197
						$("#myresearch").children(".common-widget-top-bar").trigger('click');
198
					}
4126 varun.gupt 199
				}
200
			});
201
		} else	{
202
			alert("Please select atleast one product");
203
		}
204
	});
205
 
206
	// No uid cookie
207
	if (!$.cookie("uid"))	{
208
		// No uid in storage
209
		if (!$.Storage.get("uid"))	{
210
			if (!$.Storage.get("resitems"))	{
211
				$.Storage.set("resitems", "[]");
212
			}
213
			if (!$.Storage.get("histitems"))	{
214
				$.Storage.set("histitems", "[]");
215
			}
216
		}
217
		else	{			// uid in storage : logout
218
			$.Storage.remove("uid");
219
			$.Storage.set("resitems", "[]");
220
			$.Storage.set("histitems", "[]");
221
		}
222
		load_research_widget();
223
		load_history_widget();
224
	}
225
	else	{				// With uid cookie
226
		var cookie = $.cookie("uid");
227
		// Just logged in merge storage items
228
		if (!$.Storage.get("uid"))	{
229
			$.Storage.set("uid", cookie);
230
			merge_history_items();
231
			load_research_items();
232
		}
233
		else	{
234
			// UID changed
235
			if ( cookie != $.Storage.get("uid"))	{
236
				$.Storage.set("uid", cookie);
237
				$.Storage.set("resitems", "[]");
238
				$.Storage.set("histitems", "[]");
239
				merge_history_items();
240
				load_research_items();
241
			}
242
			else	{		// Uid is same
243
				if (!$.Storage.get("resitems"))	{
244
					$.Storage.set("resitems", "[]");
245
					load_research_items();
246
				}
247
				else	{
248
					load_research_widget();
249
				}
250
 
251
				if (!$.Storage.get("histitems"))	{
252
					$.Storage.set("histitems", "[]");
253
					merge_history_items();
254
				}
255
				else	{
256
					load_history_widget();
257
				}
258
			}
259
		}
260
	}
4798 varun.gupt 261
 
262
	function load_research_items(){
263
		jQuery.ajax({
264
			type: "GET",
265
			url: "/myresearch",
266
			cache: false,
267
			success: function(json) {
268
			    $.Storage.set("resitems", json);
269
			    load_research_widget();
270
		    }
271
		});
272
	}
273
 
274
	function load_research_widget(){
275
		var myResearchWidgetContainer = $("#myresearch");
276
 
277
		if($(myResearchWidgetContainer).length == 0) {
278
			return;
279
		}
280
		var resitems = $.Storage.get("resitems");
281
 
282
		if (resitems == "[]") {
283
			var emptyResWidgetHtml = '<table border="0" width="100%" cellspacing="1" cellpadding="0" id="research_default">\
284
		      <tbody>\
285
		        <tr><td align="center"><b>Add items to compare list</b></td></tr>\
286
		       </tbody>\
287
		      </table>';
288
			$(myResearchWidgetContainer).find(".common-widget-content-area").html(emptyResWidgetHtml);
289
			$(myResearchWidgetContainer).children(".common-widget-top-bar").trigger('click');
290
			return;
291
		}
292
		var params = "/" + resitems;
293
 
294
		jQuery.ajax({
295
			type : "GET",
296
			url : "/myresearch" + params,
297
			cache: true,
298
			success : function(html) {
299
	   		    $("#myresearch").html(html);
300
	   			updateCompareCount();
301
 
302
			    // Product Title
303
			    $("#myresearch table td div a.truncate").each(function() {
304
						$(this).truncate({addtitle : true});
305
			    });
306
 
307
			    // Product Price
308
			    $("#myresearch table td div div.price").each(function() {
309
						$(this).truncate({addtitle : true});
310
				});
311
 
312
			    // Product Details
313
			    $("#myresearch table td div div.text").each(function() {
314
						$(this).truncate( {addtitle : true});
315
				});
316
		    }
317
		});
318
	}
4126 varun.gupt 319
});