Subversion Repositories SmartDukaan

Rev

Rev 1035 | Rev 3830 | Go to most recent revision | Details | Compare with Previous | 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;
1048 chandransh 12
	var arrBrowsePaginationResult = [];
878 rajveer 13
	arrBrowsePaginationResult.push([0, 0]);
14
 
1048 chandransh 15
	var arrOtherPaginationResult = [];
878 rajveer 16
	arrOtherPaginationResult.push([0, 0]);
17
 
1048 chandransh 18
	var arrSearchPaginationResult = [];
878 rajveer 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
1048 chandransh 34
	if($("#currentFilters:visible").length === 0){
878 rajveer 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
 
929 rajveer 70
			//alert("Sort by Price");
878 rajveer 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
 
929 rajveer 77
			//alert("Sort by Relevance");
878 rajveer 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(){
1048 chandransh 92
		var id = $(this).attr("id");
93
		var v = $("#" + id).text();
878 rajveer 94
 
929 rajveer 95
		//alert("Selected id:  " + id + "\nValue: " + v);
878 rajveer 96
	});
97
 
98
	// Data Connectivity
99
	$("#filterByDataConnectivity .filterOption a").click(function(){
1048 chandransh 100
		var v =  $(this).text();
929 rajveer 101
		//alert("Value: " + v);
878 rajveer 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
131
*/
132
function browseContentCallback(page_index, jq){
133
 
134
	// Show page content
135
	$('#browseContent #productListCenter1 div.page:visible').hide();
136
	$('#browseContent #productListCenter1 div.page:eq(' + page_index + ')').show(); 
137
 
138
	x = arrBrowsePaginationResult[page_index][0];
139
	y = arrBrowsePaginationResult[page_index][1];
140
	z = $('#browseContent #productListCenter1 div.page .productItem').length; 
141
 
142
	result = x + ' to ' + y + ' of <span class="resultLimit">' + z + '</span> <span class="style1">results</span>';
143
 
144
	$("#browseContent .productListResult").html(result);
145
 
146
	return false;
147
}
148
 
149
/*
150
 * Browse content
151
*/
152
function otherTabContentCallback(page_index, jq){
153
 
154
	// Show page content
155
	$('#otherTabContent #productListCenter2 div.page:visible').hide();
156
	$('#otherTabContent #productListCenter2 div.page:eq(' + page_index + ')').show(); 
157
 
158
	x = arrOtherPaginationResult[page_index][0];
159
	y = arrOtherPaginationResult[page_index][1];
160
	z = $('#otherTabContent #productListCenter2 div.page .productItem').length; 
161
 
162
	result = x + ' to ' + y + ' of <span class="resultLimit">' + z + '</span> ' + $("#otherTabContent .productListHeading").text();
163
 
164
	$("#otherTabContent .productListResult").html(result);
165
 
166
	return false;
167
}
168
 
169
/*
170
 * Search Result content pagination
171
*/
172
function initSearchResultPagination(){
929 rajveer 173
	//alert('initSearchResultPagination');  
878 rajveer 174
	if($('#searchResult:visible').length == 1){
175
		// Total page length
176
		totalPages = $('#searchResult #searchResultContent div.page').length;	
177
 
178
		if(totalPages > 0){
179
			defaultPaginationLen = 6;	// Length of pages to show in pagination
180
 
181
			// Whether to show ellipse or not, if yes then how many
182
			edgePaginationLen = (totalPages >= defaultPaginationLen) ? 1 : 0;
183
 
184
			// Number of pages to display in pagination
185
			numOfPageDisplay = (totalPages >= defaultPaginationLen) ? defaultPaginationLen : totalPages;	
186
 
187
			// Select current page in pagination
188
			curPageSelection = 0;
189
 
190
			$("#searchResult #searchResultContent .pagination1").pagination(totalPages, {
191
				num_display_entries : numOfPageDisplay,
192
				num_edge_entries	: edgePaginationLen,
193
				current_page 		: curPageSelection,
194
				items_per_page		: 1,
1048 chandransh 195
				callback		: searchContentCallback,
196
				link_to			: 'javascript: void(0);'
878 rajveer 197
			});
198
 
199
			// Show result no
200
			curPageItemNo = $('#searchResult #searchResultContent div.page:eq(0) .productItem').length;
201
 
202
			x = 1;
203
			y = curPageItemNo;
204
			z = $('#searchResult #searchResultContent div.page .productItem').length;
205
			result = x + ' to ' + y + ' of <span class="resultLimit">' + z + '</span> <span class="style1">results</span>';
206
 
207
			len = arrSearchPaginationResult.length;
208
			for(var i=0; i<len; i++){
209
				arrSearchPaginationResult.pop();
210
			}
211
 
212
			$('#searchResult #searchResultContent div.page').each(function(){
213
				arrSearchPaginationResult.push([x, y]);
214
 
215
				x = y + 1;
216
				y = x + ($('.productItem', this).length - 1);
217
			});
218
 
219
			$("#searchResult #searchResultContent .productListResult").html(result);
220
		}else{
221
			result = '0 to 0 of <span class="resultLimit"> 0 </span> <span class="style1">results</span>';
222
 
223
			$("#searchResult #searchResultContent .productListResult").html(result);
224
		}
225
	}
226
}
227
 
228
/*
229
 * Search result content
230
*/
231
function searchContentCallback(page_index, jq){
232
 
233
	// Show page content
234
	$('#searchResult #searchResultContent div.page:visible').hide();
235
	$('#searchResult #searchResultContent div.page:eq(' + page_index + ')').show(); 
236
 
237
	x = arrSearchPaginationResult[page_index][0];
238
	y = arrSearchPaginationResult[page_index][1];
239
	z = $('#searchResult #searchResultContent div.page .productItem').length; 
240
 
241
	result = x + ' to ' + y + ' of <span class="resultLimit">' + z + '</span> <span class="style1">results</span>';
242
 
243
	$("#searchResult #searchResultContent .productListResult").html(result);
244
 
245
	return false;
246
}
247
 
248
/*
249
 * Remove last active tab state
250
*/
251
function removeLastActiveState(){
252
	if($('#tabButton a#activeTab').length == 1){
253
 
254
		$('#tabButton div').each(function(){
255
			if($("a", this).attr("id") == "activeTab"){
256
				$("a", this).attr("id", "");
257
			}
258
		});
259
 
260
	}
261
}
262
 
263
/*
264
 * Make active tab
265
*/
266
function activeTab(id){
267
	$("#" + id + " a").attr("class","category-tabs activeTab");
268
}
269
 
270
/*
271
 * Hide tab content
272
*/
273
function hideShowTabContent(id, state){	
274
	if(state == "hide"){
275
		$("#" + id).hide();
276
	}else if(state == "show"){
277
		$("#" + id).show();
278
	}
279
 
280
	if(id == "multifacetedSearch"){
281
		if(state == "hide"){
282
			$("#productCat .top .left").css("background", "#fff");
283
			$("#productCat .bottom .left").css("background", "url(/images/product-detail-bottom-left.jpg) no-repeat");
284
			$("#productCat .middle .content").css("background-image", "none");
285
 
286
			$("#productList").css("width", "100%");
287
			$("#productList").css("margin-left", "0");
288
 
289
			$("#productList #productListCenter .floatLeft").css("margin-left", "70px");
290
			$("#productList #productListCenter .floatRight").css("margin-right", "70px");
291
		}else if(state == "show"){
292
			$("#productCat .top .left").css("background", "#efeff0");
293
			$("#productCat .bottom .left").css("background", "url(/images/product-cat-bottom-left.jpg) no-repeat");
294
			$("#productCat .middle .content").css("background", "#ffffff url(/images/grey-ver-bar.gif) repeat-y");
295
 
296
			$("#productList").css("width", "562px");
297
			$("#productList").css("margin-left", "1px");
298
 
299
			$("#productList #productListCenter .floatLeft").css("margin-left", "16px");
300
			$("#productList #productListCenter .floatRight").css("margin-right", "16px");
301
		}
302
	}
303
}
304
 
305
/*
306
 * Set content heading on tab click
307
*/
308
function setContentHeading(str){
309
	if($("#otherTabContent:visible").length == 1){
310
		$("#otherTabContent .productListHeading").text(str);
311
	}
312
}