Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
538 rajveer 1
/** 
2
  * Author 			: Raj Kumar Bharti
3
  * Creation Date 	: 06 Dec 2010
4
  * Project 		: Shop2020
5
  * Copyright 2010 Evon Technologies
6
*/
7
 
8
$(document).ready(function(){
9
 
10
	// Variables for pagination result of browse, other tab content and search result
11
	x = y = z = 0;
12
	arrBrowsePaginationResult = new Array();
13
	arrBrowsePaginationResult.push([0, 0]);
14
 
15
	arrOtherPaginationResult = new Array();
16
	arrOtherPaginationResult.push([0, 0]);
17
 
18
	arrSearchPaginationResult = new Array();
19
	arrSearchPaginationResult.push([0, 0]);
20
 
21
 
22
	// Setting tab button id attr to empty
23
	$('#tabButton div').each(function(){
24
		$("a", this).attr("id", "");
25
	});
26
 
27
	// Activating Browse tab
28
	activeTab("catTab1");
29
 
30
	// Hide other tab common content for best deals, latest arrivals, best sellers
31
	hideShowTabContent("otherTabContent", "hide");
32
 
33
	// Adjust current filters section css
34
	if($("#currentFilters:visible").length == 0){
35
		$("#filterBy h2").css("margin-top", "0");
36
		$("#currentFilters").css("padding-bototom", "0");
37
	}
38
 
39
	// Browse tab pagination
40
	initBrowsePagination();	
41
 
42
	// Search Result Pagination
43
	initSearchResultPagination();
44
 
45
	// Filter by heading slideup and slidedown
46
	filterByOptionSlide();
47
 
48
	// Filter by values selection
49
	filterByValues();
50
 
51
	// Sort Search Results
52
	sortSearchResult();
53
 
54
	// Align properly new icon in search result pages for a product
55
	var newIconLeft = $("#searchResult #productListCenter .productItem .productImg img").css("left");
56
	$("#searchResult #productListCenter .productItem .productImg .newIcon").css("left", newIconLeft);
57
});
58
 
59
/*
60
 *  sort search results
61
*/
62
function sortSearchResult(){
63
	$("#sortBy a").click(function(){
64
		id = $(this).attr("id");
65
 
66
		if(id == "sortByPrice"){
67
			$(this).removeClass('active').addClass('active');
68
			$("#sortByRelevance").removeClass('active');
69
 
70
			alert("Sort by Price");
71
			// Ajax call to fecth data in page class
72
 
73
		}else if(id == "sortByRelevance"){
74
			$(this).removeClass('active').addClass('active');
75
			$("#sortByPrice").removeClass('active');
76
 
77
			alert("Sort by Relevance");
78
			// Ajax call to fecth data in page class
79
		}
80
	});
81
 
82
	initSearchResultPagination();
83
}
84
 
85
/*
86
 *  Filter by values selection
87
*/
88
function filterByValues(){
89
 
90
	// Talk time
91
	$("#filterByTalkTime .filterOption a").click(function(){
92
		id = $(this).attr("id");
93
		v = $("#" + id).text();
94
 
95
		alert("Selected id:  " + id + "\nValue: " + v);
96
	});
97
 
98
	// Data Connectivity
99
	$("#filterByDataConnectivity .filterOption a").click(function(){
100
		v =  $(this).text()
101
		alert("Value: " + v);
102
	});
103
 
104
	// Note for price slider value see priceSlider.js
105
}
106
 
107
/*
108
 * Filter by heading slideup and slidedown
109
*/
110
function filterByOptionSlide(){
111
	$("#filterBy .filterHeading").click(function(){
112
 
113
		// Image angle change
114
		if($(this).parent().find(".filterArrow").length == 1){
115
			$(this).parent().find(".filterArrow").removeClass('filterArrow').addClass('filterArrowRotate');
116
		}else if($(this).parent().find(".filterArrowRotate").length == 1){
117
			$(this).parent().find(".filterArrowRotate").removeClass('filterArrowRotate').addClass('filterArrow');
118
		}
119
 
120
		// Content slideup and slide down
121
		if($(this).parent().find(".filterOption").length == 1){
122
			$(this).parent().find(".filterOption").slideToggle();
123
		}else{
124
			$(this).parent().find("#priceSlider").slideToggle();
125
		}
126
	});
127
}
128
 
129
/*
130
 * Browse content pagination
131
*/
132
function initBrowsePagination(){
133
 
134
	if($('#browseContent:visible').length == 1){
135
		// Total page length
136
		totalPages = $('#browseContent #productListCenter1 div.page').length;	
137
 
138
		if(totalPages > 0){
139
			defaultPaginationLen = 6;	// Length of pages to show in pagination
140
 
141
			// Whether to show ellipse or not, if yes then how many
142
			edgePaginationLen = (totalPages >= defaultPaginationLen) ? 1 : 0;
143
 
144
			// Number of pages to display in pagination
145
			numOfPageDisplay = (totalPages >= defaultPaginationLen) ? defaultPaginationLen : totalPages;	
146
 
147
			// Select current page in pagination
148
			curPageSelection = 0;
149
 
150
			$("#browseContent .pagination1").pagination(totalPages, {
151
				num_display_entries : numOfPageDisplay,
152
				num_edge_entries	: edgePaginationLen,
153
				current_page 		: curPageSelection,
154
				items_per_page		: 1,
155
				callback			: browseContentCallback,
156
				link_to				: 'javascript: void(0);'
157
			});
158
 
159
			// Show result no
160
			curPageItemNo = $('#browseContent #productListCenter1 div.page:eq(0) .productItem').length;
161
 
162
			x = 1;
163
			y = curPageItemNo;
164
			z = $('#browseContent #productListCenter1 div.page .productItem').length;
165
			result = x + ' to ' + y + ' of <span class="resultLimit">' + z + '</span> <span class="style1">results</span>';
166
 
167
			len = arrBrowsePaginationResult.length;
168
			for(var i=0; i<len; i++){
169
				arrBrowsePaginationResult.pop();
170
			}
171
 
172
			$('#browseContent #productListCenter1 div.page').each(function(){
173
				arrBrowsePaginationResult.push([x, y]);
174
 
175
				x = y + 1;
176
				y = x + ($('.productItem', this).length - 1);
177
			});
178
 
179
			$("#browseContent .productListResult").html(result);
180
		}else{
181
			result = '0 to 0 of <span class="resultLimit"> 0 </span> <span class="style1">results</span>';
182
 
183
			$("#browseContent .productListResult").html(result);
184
		}
185
	}
186
}
187
 
188
/*
189
 * Browse content
190
*/
191
function browseContentCallback(page_index, jq){
192
 
193
	// Show page content
194
	$('#browseContent #productListCenter1 div.page:visible').hide();
195
	$('#browseContent #productListCenter1 div.page:eq(' + page_index + ')').show(); 
196
 
197
	x = arrBrowsePaginationResult[page_index][0];
198
	y = arrBrowsePaginationResult[page_index][1];
199
	z = $('#browseContent #productListCenter1 div.page .productItem').length; 
200
 
201
	result = x + ' to ' + y + ' of <span class="resultLimit">' + z + '</span> <span class="style1">results</span>';
202
 
203
	$("#browseContent .productListResult").html(result);
204
 
205
	return false;
206
}
207
 
208
/*
209
 * Other tab content pagination
210
*/
211
function initOtherPagination(){
212
 
213
	// Total page length
214
	totalPages = $('#otherTabContent #productListCenter2 div.page').length;	
215
 
216
	if(totalPages > 0){
217
		defaultPaginationLen = 6;	// Length of pages to show in pagination
218
 
219
		// Whether to show ellipse or not, if yes then how many
220
		edgePaginationLen = (totalPages >= defaultPaginationLen) ? 1 : 0;
221
 
222
		// Number of pages to display in pagination
223
		numOfPageDisplay = (totalPages >= defaultPaginationLen) ? defaultPaginationLen : totalPages;	
224
 
225
		// Select current page in pagination
226
		curPageSelection = 0;
227
 
228
		$("#otherTabContent .pagination2").pagination(totalPages, {
229
			num_display_entries : numOfPageDisplay,
230
			num_edge_entries	: edgePaginationLen,
231
			current_page 		: curPageSelection,
232
			items_per_page		: 1,
233
			callback			: otherTabContentCallback,
234
			link_to				: 'javascript: void(0);'
235
		});
236
 
237
		// Show result no
238
		curPageItemNo = $('#otherTabContent #productListCenter2 div.page:eq(0) .productItem').length;
239
 
240
		x = 1;
241
		y = curPageItemNo;
242
		z = $('#otherTabContent #productListCenter2 div.page .productItem').length;
243
		result = x + ' to ' + y + ' of <span class="resultLimit">' + z + '</span> ' + $("#otherTabContent .productListHeading").text();
244
 
245
		len = arrOtherPaginationResult.length;
246
		for(var i=0; i<len; i++){
247
			arrOtherPaginationResult.pop();
248
		}
249
 
250
		$('#otherTabContent #productListCenter2 div.page').each(function(){
251
			arrOtherPaginationResult.push([x, y]);
252
 
253
			x = y + 1;
254
			y = x + ($('.productItem', this).length - 1);
255
		});
256
 
257
		$("#otherTabContent .productListResult").html(result);
258
	}else{
259
		result = '0 to 0 of <span class="resultLimit"> 0 </span> ' + $("#otherTabContent .productListHeading").text();
260
 
261
		$("#otherTabContent .productListResult").html(result);
262
	}
263
}
264
 
265
/*
266
 * Browse content
267
*/
268
function otherTabContentCallback(page_index, jq){
269
 
270
	// Show page content
271
	$('#otherTabContent #productListCenter2 div.page:visible').hide();
272
	$('#otherTabContent #productListCenter2 div.page:eq(' + page_index + ')').show(); 
273
 
274
	x = arrOtherPaginationResult[page_index][0];
275
	y = arrOtherPaginationResult[page_index][1];
276
	z = $('#otherTabContent #productListCenter2 div.page .productItem').length; 
277
 
278
	result = x + ' to ' + y + ' of <span class="resultLimit">' + z + '</span> ' + $("#otherTabContent .productListHeading").text();
279
 
280
	$("#otherTabContent .productListResult").html(result);
281
 
282
	return false;
283
}
284
 
285
/*
286
 * Search Result content pagination
287
*/
288
function initSearchResultPagination(){
289
 
290
	if($('#searchResult:visible').length == 1){
291
		// Total page length
292
		totalPages = $('#searchResult #searchResultContent div.page').length;	
293
 
294
		if(totalPages > 0){
295
			defaultPaginationLen = 6;	// Length of pages to show in pagination
296
 
297
			// Whether to show ellipse or not, if yes then how many
298
			edgePaginationLen = (totalPages >= defaultPaginationLen) ? 1 : 0;
299
 
300
			// Number of pages to display in pagination
301
			numOfPageDisplay = (totalPages >= defaultPaginationLen) ? defaultPaginationLen : totalPages;	
302
 
303
			// Select current page in pagination
304
			curPageSelection = 0;
305
 
306
			$("#searchResult #searchResultContent .pagination1").pagination(totalPages, {
307
				num_display_entries : numOfPageDisplay,
308
				num_edge_entries	: edgePaginationLen,
309
				current_page 		: curPageSelection,
310
				items_per_page		: 1,
311
				callback			: searchContentCallback,
312
				link_to				: 'javascript: void(0);'
313
			});
314
 
315
			// Show result no
316
			curPageItemNo = $('#searchResult #searchResultContent div.page:eq(0) .productItem').length;
317
 
318
			x = 1;
319
			y = curPageItemNo;
320
			z = $('#searchResult #searchResultContent div.page .productItem').length;
321
			result = x + ' to ' + y + ' of <span class="resultLimit">' + z + '</span> <span class="style1">results</span>';
322
 
323
			len = arrSearchPaginationResult.length;
324
			for(var i=0; i<len; i++){
325
				arrSearchPaginationResult.pop();
326
			}
327
 
328
			$('#searchResult #searchResultContent div.page').each(function(){
329
				arrSearchPaginationResult.push([x, y]);
330
 
331
				x = y + 1;
332
				y = x + ($('.productItem', this).length - 1);
333
			});
334
 
335
			$("#searchResult #searchResultContent .productListResult").html(result);
336
		}else{
337
			result = '0 to 0 of <span class="resultLimit"> 0 </span> <span class="style1">results</span>';
338
 
339
			$("#searchResult #searchResultContent .productListResult").html(result);
340
		}
341
	}
342
}
343
 
344
/*
345
 * Search result content
346
*/
347
function searchContentCallback(page_index, jq){
348
 
349
	// Show page content
350
	$('#searchResult #searchResultContent div.page:visible').hide();
351
	$('#searchResult #searchResultContent div.page:eq(' + page_index + ')').show(); 
352
 
353
	x = arrSearchPaginationResult[page_index][0];
354
	y = arrSearchPaginationResult[page_index][1];
355
	z = $('#searchResult #searchResultContent div.page .productItem').length; 
356
 
357
	result = x + ' to ' + y + ' of <span class="resultLimit">' + z + '</span> <span class="style1">results</span>';
358
 
359
	$("#searchResult #searchResultContent .productListResult").html(result);
360
 
361
	return false;
362
}
363
 
364
/*
365
 * Remove last active tab state
366
*/
367
function removeLastActiveState(){
368
	if($('#tabButton a#activeTab').length == 1){
369
 
370
		$('#tabButton div').each(function(){
371
			if($("a", this).attr("id") == "activeTab"){
372
				$("a", this).attr("id", "");
373
			}
374
		});
375
 
376
	}
377
}
378
 
379
/*
380
 * Make active tab
381
*/
382
function activeTab(id){
383
	$("#" + id + " a").attr("id","activeTab");
384
}
385
 
386
/*
387
 * Hide tab content
388
*/
389
function hideShowTabContent(id, state){	
390
	if(state == "hide"){
391
		$("#" + id).hide();
392
	}else if(state == "show"){
393
		$("#" + id).show();
394
	}
395
 
396
	if(id == "multifacetedSearch"){
397
		if(state == "hide"){
398
			$("#productCat .top .left").css("background", "#fff");
399
			$("#productCat .bottom .left").css("background", "url(images/product-detail-bottom-left.jpg) no-repeat");
400
			$("#productCat .middle .content").css("background-image", "none");
401
 
402
			$("#productList").css("width", "100%");
403
			$("#productList").css("margin-left", "0");
404
 
405
			$("#productList #productListCenter .floatLeft").css("margin-left", "70px");
406
			$("#productList #productListCenter .floatRight").css("margin-right", "70px");
407
		}else if(state == "show"){
408
			$("#productCat .top .left").css("background", "#efeff0");
409
			$("#productCat .bottom .left").css("background", "url(images/product-cat-bottom-left.jpg) no-repeat");
410
			$("#productCat .middle .content").css("background", "#ffffff url(images/grey-ver-bar.gif) repeat-y");
411
 
412
			$("#productList").css("width", "562px");
413
			$("#productList").css("margin-left", "1px");
414
 
415
			$("#productList #productListCenter .floatLeft").css("margin-left", "16px");
416
			$("#productList #productListCenter .floatRight").css("margin-right", "16px");
417
		}
418
	}
419
}
420
 
421
 
422
/*
423
 * Show browse content
424
*/
425
function showBrowse(){
426
	removeLastActiveState();
427
	activeTab("catTab1");
428
 
429
	hideShowTabContent("multifacetedSearch", "show");
430
	hideShowTabContent("browseContent", "show");
431
 
432
	hideShowTabContent("otherTabContent", "hide");
433
 
434
	// Ajax call to fecth data in page class
435
 
436
 
437
	initBrowsePagination();
438
}
439
 
440
/*
441
 * Show best sellers
442
*/
443
function showBestSellers(){
444
	removeLastActiveState();
445
	activeTab("catTab2");
446
 
447
	hideShowTabContent("otherTabContent", "show");
448
	setContentHeading("best sellers");
449
 
450
	hideShowTabContent("multifacetedSearch", "hide");
451
	hideShowTabContent("browseContent", "hide");
452
 
453
	// Ajax call to fecth data in page class
454
	alert("Ajax call to get best sellers");
455
 
456
          jQuery.ajax({
457
               url: "../best-sellers",
458
               type: "GET",
459
               contentType: "text/html",
460
               cache: false,
461
               success: function(html){
462
                    if(html!=1){
463
			alert(html);
464
			document.getElementById('productListCenter2').innerHTML = html;
465
                    }else{
466
                         alert("Sorry! Unexpected Error. Try again!");
467
                    }
468
               }
469
          });
470
 
471
 
472
 
473
 
474
 
475
	initOtherPagination();
476
}
477
 
478
/*
479
 * Show latest arrivals
480
*/
481
function showLatestArrivals(){
482
	removeLastActiveState();
483
	activeTab("catTab3");
484
 
485
	hideShowTabContent("otherTabContent", "show");
486
	setContentHeading("latest arrivals");
487
 
488
	hideShowTabContent("multifacetedSearch", "hide");
489
	hideShowTabContent("browseContent", "hide");
490
 
491
	// Ajax call to fecth data in page class
492
 
493
	initOtherPagination();
494
}
495
 
496
/*
497
 * Show best deals
498
*/
499
function showBestDeals(){
500
	removeLastActiveState();
501
	activeTab("catTab4");
502
 
503
	hideShowTabContent("otherTabContent", "show");
504
	setContentHeading("best deals");
505
 
506
	hideShowTabContent("multifacetedSearch", "hide");
507
	hideShowTabContent("browseContent", "hide");	
508
 
509
	// Ajax call to fecth data in page class
510
 
511
	initOtherPagination();
512
}
513
 
514
/*
515
 * Set content heading on tab click
516
*/
517
function setContentHeading(str){
518
	if($("#otherTabContent:visible").length == 1){
519
		$("#otherTabContent .productListHeading").text(str);
520
	}
521
}