Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
878 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
	//alert('initBrowsePagination');
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
/*
212
function initOtherPagination(){
213
	//alert('initOtherPagination');
214
	// Total page length
215
	totalPages = $('#otherTabContent #productListCenter2 div.page').length;	
216
 
217
	if(totalPages > 0){
218
		defaultPaginationLen = 6;	// Length of pages to show in pagination
219
 
220
		// Whether to show ellipse or not, if yes then how many
221
		edgePaginationLen = (totalPages >= defaultPaginationLen) ? 1 : 0;
222
 
223
		// Number of pages to display in pagination
224
		numOfPageDisplay = (totalPages >= defaultPaginationLen) ? defaultPaginationLen : totalPages;	
225
 
226
		// Select current page in pagination
227
		curPageSelection = 0;
228
 
229
		$("#otherTabContent .pagination2").pagination(totalPages, {
230
			num_display_entries : numOfPageDisplay,
231
			num_edge_entries	: edgePaginationLen,
232
			current_page 		: curPageSelection,
233
			items_per_page		: 1,
234
			callback			: otherTabContentCallback,
235
			link_to				: 'javascript: void(0);'
236
		});
237
 
238
		// Show result no
239
		curPageItemNo = $('#otherTabContent #productListCenter2 div.page:eq(0) .productItem').length;
240
 
241
		x = 1;
242
		y = curPageItemNo;
243
		z = $('#otherTabContent #productListCenter2 div.page .productItem').length;
244
		result = x + ' to ' + y + ' of <span class="resultLimit">' + z + '</span> ' + $("#otherTabContent .productListHeading").text();
245
 
246
		len = arrOtherPaginationResult.length;
247
		for(var i=0; i<len; i++){
248
			arrOtherPaginationResult.pop();
249
		}
250
 
251
		$('#otherTabContent #productListCenter2 div.page').each(function(){
252
			arrOtherPaginationResult.push([x, y]);
253
 
254
			x = y + 1;
255
			y = x + ($('.productItem', this).length - 1);
256
		});
257
 
258
		$("#otherTabContent .productListResult").html(result);
259
	}else{
260
		result = '0 to 0 of <span class="resultLimit"> 0 </span> ' + $("#otherTabContent .productListHeading").text();
261
 
262
		$("#otherTabContent .productListResult").html(result);
263
	}
264
}
265
*/
266
/*
267
 * Browse content
268
*/
269
function otherTabContentCallback(page_index, jq){
270
 
271
	// Show page content
272
	$('#otherTabContent #productListCenter2 div.page:visible').hide();
273
	$('#otherTabContent #productListCenter2 div.page:eq(' + page_index + ')').show(); 
274
 
275
	x = arrOtherPaginationResult[page_index][0];
276
	y = arrOtherPaginationResult[page_index][1];
277
	z = $('#otherTabContent #productListCenter2 div.page .productItem').length; 
278
 
279
	result = x + ' to ' + y + ' of <span class="resultLimit">' + z + '</span> ' + $("#otherTabContent .productListHeading").text();
280
 
281
	$("#otherTabContent .productListResult").html(result);
282
 
283
	return false;
284
}
285
 
286
/*
287
 * Search Result content pagination
288
*/
289
function initSearchResultPagination(){
290
	alert('initSearchResultPagination');  
291
	if($('#searchResult:visible').length == 1){
292
		// Total page length
293
		totalPages = $('#searchResult #searchResultContent div.page').length;	
294
 
295
		if(totalPages > 0){
296
			defaultPaginationLen = 6;	// Length of pages to show in pagination
297
 
298
			// Whether to show ellipse or not, if yes then how many
299
			edgePaginationLen = (totalPages >= defaultPaginationLen) ? 1 : 0;
300
 
301
			// Number of pages to display in pagination
302
			numOfPageDisplay = (totalPages >= defaultPaginationLen) ? defaultPaginationLen : totalPages;	
303
 
304
			// Select current page in pagination
305
			curPageSelection = 0;
306
 
307
			$("#searchResult #searchResultContent .pagination1").pagination(totalPages, {
308
				num_display_entries : numOfPageDisplay,
309
				num_edge_entries	: edgePaginationLen,
310
				current_page 		: curPageSelection,
311
				items_per_page		: 1,
312
				callback			: searchContentCallback,
313
				link_to				: 'javascript: void(0);'
314
			});
315
 
316
			// Show result no
317
			curPageItemNo = $('#searchResult #searchResultContent div.page:eq(0) .productItem').length;
318
 
319
			x = 1;
320
			y = curPageItemNo;
321
			z = $('#searchResult #searchResultContent div.page .productItem').length;
322
			result = x + ' to ' + y + ' of <span class="resultLimit">' + z + '</span> <span class="style1">results</span>';
323
 
324
			len = arrSearchPaginationResult.length;
325
			for(var i=0; i<len; i++){
326
				arrSearchPaginationResult.pop();
327
			}
328
 
329
			$('#searchResult #searchResultContent div.page').each(function(){
330
				arrSearchPaginationResult.push([x, y]);
331
 
332
				x = y + 1;
333
				y = x + ($('.productItem', this).length - 1);
334
			});
335
 
336
			$("#searchResult #searchResultContent .productListResult").html(result);
337
		}else{
338
			result = '0 to 0 of <span class="resultLimit"> 0 </span> <span class="style1">results</span>';
339
 
340
			$("#searchResult #searchResultContent .productListResult").html(result);
341
		}
342
	}
343
}
344
 
345
/*
346
 * Search result content
347
*/
348
function searchContentCallback(page_index, jq){
349
 
350
	// Show page content
351
	$('#searchResult #searchResultContent div.page:visible').hide();
352
	$('#searchResult #searchResultContent div.page:eq(' + page_index + ')').show(); 
353
 
354
	x = arrSearchPaginationResult[page_index][0];
355
	y = arrSearchPaginationResult[page_index][1];
356
	z = $('#searchResult #searchResultContent div.page .productItem').length; 
357
 
358
	result = x + ' to ' + y + ' of <span class="resultLimit">' + z + '</span> <span class="style1">results</span>';
359
 
360
	$("#searchResult #searchResultContent .productListResult").html(result);
361
 
362
	return false;
363
}
364
 
365
/*
366
 * Remove last active tab state
367
*/
368
function removeLastActiveState(){
369
	if($('#tabButton a#activeTab').length == 1){
370
 
371
		$('#tabButton div').each(function(){
372
			if($("a", this).attr("id") == "activeTab"){
373
				$("a", this).attr("id", "");
374
			}
375
		});
376
 
377
	}
378
}
379
 
380
/*
381
 * Make active tab
382
*/
383
function activeTab(id){
384
	$("#" + id + " a").attr("class","category-tabs activeTab");
385
}
386
 
387
/*
388
 * Hide tab content
389
*/
390
function hideShowTabContent(id, state){	
391
	if(state == "hide"){
392
		$("#" + id).hide();
393
	}else if(state == "show"){
394
		$("#" + id).show();
395
	}
396
 
397
	if(id == "multifacetedSearch"){
398
		if(state == "hide"){
399
			$("#productCat .top .left").css("background", "#fff");
400
			$("#productCat .bottom .left").css("background", "url(/images/product-detail-bottom-left.jpg) no-repeat");
401
			$("#productCat .middle .content").css("background-image", "none");
402
 
403
			$("#productList").css("width", "100%");
404
			$("#productList").css("margin-left", "0");
405
 
406
			$("#productList #productListCenter .floatLeft").css("margin-left", "70px");
407
			$("#productList #productListCenter .floatRight").css("margin-right", "70px");
408
		}else if(state == "show"){
409
			$("#productCat .top .left").css("background", "#efeff0");
410
			$("#productCat .bottom .left").css("background", "url(/images/product-cat-bottom-left.jpg) no-repeat");
411
			$("#productCat .middle .content").css("background", "#ffffff url(/images/grey-ver-bar.gif) repeat-y");
412
 
413
			$("#productList").css("width", "562px");
414
			$("#productList").css("margin-left", "1px");
415
 
416
			$("#productList #productListCenter .floatLeft").css("margin-left", "16px");
417
			$("#productList #productListCenter .floatRight").css("margin-right", "16px");
418
		}
419
	}
420
}
421
 
422
/*** Commented by ebizon 
423
/*
424
 * Show browse content
425
 
426
function showBrowse(){
427
	removeLastActiveState();
428
	activeTab("catTab1");
429
 
430
	hideShowTabContent("multifacetedSearch", "show");
431
	hideShowTabContent("browseContent", "show");
432
 
433
	hideShowTabContent("otherTabContent", "hide");
434
 
435
	// Ajax call to fecth data in page class
436
 
437
 
438
	//initBrowsePagination();
439
}
440
 
441
/*
442
 * Show best sellers
443
 
444
function showBestSellers(catId){
445
	removeLastActiveState();
446
	activeTab("catTab2");
447
 
448
	hideShowTabContent("otherTabContent", "show");
449
	setContentHeading("Best Sellers");
450
 
451
	hideShowTabContent("multifacetedSearch", "hide");
452
	hideShowTabContent("browseContent", "hide");
453
 
454
	// Ajax call to fecth data in page class
455
	alert("Ajax call to get best sellers");
456
 
457
          jQuery.ajax({
458
               url: "../best-sellers",
459
               type: "GET",
460
               data: "categoryid="+catId,
461
               contentType: "text/html",
462
               cache: false,
463
               success: function(html){
464
                    if(html!=1){
465
                    	alert(html);
466
                    	$('#productListCenter2').html(html);
467
                    }else{
468
                         alert("Sorry! Unexpected Error. Try again!");
469
                    }
470
               }
471
          });
472
 
473
 
474
 
475
 
476
 
477
	//initOtherPagination();
478
}
479
 
480
/*
481
 * Show latest arrivals
482
 
483
function showLatestArrivals(catId){
484
	removeLastActiveState();
485
	activeTab("catTab3");
486
 
487
	hideShowTabContent("otherTabContent", "show");
488
	setContentHeading("Latest Arrivals");
489
 
490
	hideShowTabContent("multifacetedSearch", "hide");
491
	hideShowTabContent("browseContent", "hide");
492
 
493
	// Ajax call to fecth data in page class
494
        alert("Ajax call to get best sellers");
495
 
496
          jQuery.ajax({
497
               url: "../latest-arrivals",
498
               type: "GET",
499
               data: "categoryid="+catId,
500
               contentType: "text/html",
501
               cache: false,
502
               success: function(html){
503
                    if(html!=1){
504
                        alert(html);
505
                        $('#productListCenter2').html(html);
506
                    }else{
507
                         alert("Sorry! Unexpected Error. Try again!");
508
                    }
509
               }
510
          });
511
 
512
	//initOtherPagination();
513
}
514
 
515
/*
516
 * Show best deals
517
 
518
function showBestDeals(catId){
519
	removeLastActiveState();
520
	activeTab("catTab4");
521
 
522
	hideShowTabContent("otherTabContent", "show");
523
	setContentHeading("Best Deals");
524
 
525
	hideShowTabContent("multifacetedSearch", "hide");
526
	hideShowTabContent("browseContent", "hide");	
527
 
528
	// Ajax call to fecth data in page class
529
        alert("Ajax call to get best sellers");
530
 
531
          jQuery.ajax({
532
               url: "../best-deals",
533
               type: "GET",
534
               data: "categoryid="+catId,
535
               contentType: "text/html",
536
               cache: false,
537
               success: function(html){
538
                    if(html!=1){
539
                        alert(html);
540
                        $('#productListCenter2').html(html);
541
                    }else{
542
                         alert("Sorry! Unexpected Error. Try again!");
543
                    }
544
               }
545
          });
546
 
547
	//initOtherPagination();
548
}
549
*/
550
/*
551
 * Set content heading on tab click
552
*/
553
function setContentHeading(str){
554
	if($("#otherTabContent:visible").length == 1){
555
		$("#otherTabContent .productListHeading").text(str);
556
	}
557
}