Subversion Repositories SmartDukaan

Rev

Rev 3830 | Rev 6866 | 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
	// Filter by heading slideup and slidedown
40
	filterByOptionSlide();
41
 
42
	// Filter by values selection
43
	filterByValues();
44
 
45
	// Sort Search Results
46
	sortSearchResult();
47
 
48
	// Align properly new icon in search result pages for a product
49
	var newIconLeft = $("#searchResult #productListCenter .productItem .productImg img").css("left");
50
	$("#searchResult #productListCenter .productItem .productImg .newIcon").css("left", newIconLeft);
51
});
52
 
53
/*
54
 *  sort search results
55
*/
56
function sortSearchResult(){
57
	$("#sortBy a").click(function(){
58
		id = $(this).attr("id");
59
 
60
		if(id == "sortByPrice"){
61
			$(this).removeClass('active').addClass('active');
62
			$("#sortByRelevance").removeClass('active');
63
			// Ajax call to fecth data in page class
64
 
65
		}else if(id == "sortByRelevance"){
66
			$(this).removeClass('active').addClass('active');
67
			$("#sortByPrice").removeClass('active');
68
			// Ajax call to fecth data in page class
69
		}
70
	});
71
}
72
 
73
/*
74
 *  Filter by values selection
75
*/
76
function filterByValues(){
77
 
78
	// Talk time
79
	$("#filterByTalkTime .filterOption a").click(function(){
1048 chandransh 80
		var id = $(this).attr("id");
81
		var v = $("#" + id).text();
878 rajveer 82
	});
83
 
84
	// Data Connectivity
85
	$("#filterByDataConnectivity .filterOption a").click(function(){
1048 chandransh 86
		var v =  $(this).text();
878 rajveer 87
	});
88
 
89
	// Note for price slider value see priceSlider.js
90
}
91
 
92
/*
93
 * Filter by heading slideup and slidedown
94
*/
95
function filterByOptionSlide(){
96
	$("#filterBy .filterHeading").click(function(){
97
 
98
		// Image angle change
99
		if($(this).parent().find(".filterArrow").length == 1){
100
			$(this).parent().find(".filterArrow").removeClass('filterArrow').addClass('filterArrowRotate');
101
		}else if($(this).parent().find(".filterArrowRotate").length == 1){
102
			$(this).parent().find(".filterArrowRotate").removeClass('filterArrowRotate').addClass('filterArrow');
103
		}
104
 
105
		// Content slideup and slide down
106
		if($(this).parent().find(".filterOption").length == 1){
107
			$(this).parent().find(".filterOption").slideToggle();
108
		}else{
109
			$(this).parent().find("#priceSlider").slideToggle();
110
		}
111
	});
112
}
113
 
114
/*
115
 * Browse content
116
*/
117
function browseContentCallback(page_index, jq){
118
 
119
	// Show page content
120
	$('#browseContent #productListCenter1 div.page:visible').hide();
121
	$('#browseContent #productListCenter1 div.page:eq(' + page_index + ')').show(); 
122
 
123
	x = arrBrowsePaginationResult[page_index][0];
124
	y = arrBrowsePaginationResult[page_index][1];
125
	z = $('#browseContent #productListCenter1 div.page .productItem').length; 
126
 
127
	result = x + ' to ' + y + ' of <span class="resultLimit">' + z + '</span> <span class="style1">results</span>';
128
 
129
	$("#browseContent .productListResult").html(result);
130
 
131
	return false;
132
}
133
 
134
/*
135
 * Browse content
136
*/
137
function otherTabContentCallback(page_index, jq){
138
 
139
	// Show page content
140
	$('#otherTabContent #productListCenter2 div.page:visible').hide();
141
	$('#otherTabContent #productListCenter2 div.page:eq(' + page_index + ')').show(); 
142
 
143
	x = arrOtherPaginationResult[page_index][0];
144
	y = arrOtherPaginationResult[page_index][1];
145
	z = $('#otherTabContent #productListCenter2 div.page .productItem').length; 
146
 
147
	result = x + ' to ' + y + ' of <span class="resultLimit">' + z + '</span> ' + $("#otherTabContent .productListHeading").text();
148
 
149
	$("#otherTabContent .productListResult").html(result);
150
 
151
	return false;
152
}
153
 
154
/*
155
 * Search Result content pagination
156
*/
157
function initSearchResultPagination(){
158
	if($('#searchResult:visible').length == 1){
159
		// Total page length
160
		totalPages = $('#searchResult #searchResultContent div.page').length;	
161
 
162
		if(totalPages > 0){
163
			defaultPaginationLen = 6;	// Length of pages to show in pagination
164
 
165
			// Whether to show ellipse or not, if yes then how many
166
			edgePaginationLen = (totalPages >= defaultPaginationLen) ? 1 : 0;
167
 
168
			// Number of pages to display in pagination
169
			numOfPageDisplay = (totalPages >= defaultPaginationLen) ? defaultPaginationLen : totalPages;	
170
 
171
			// Select current page in pagination
172
			curPageSelection = 0;
173
 
174
			$("#searchResult #searchResultContent .pagination1").pagination(totalPages, {
175
				num_display_entries : numOfPageDisplay,
176
				num_edge_entries	: edgePaginationLen,
177
				current_page 		: curPageSelection,
178
				items_per_page		: 1,
1048 chandransh 179
				callback		: searchContentCallback,
180
				link_to			: 'javascript: void(0);'
878 rajveer 181
			});
182
 
183
			// Show result no
184
			curPageItemNo = $('#searchResult #searchResultContent div.page:eq(0) .productItem').length;
185
 
186
			x = 1;
187
			y = curPageItemNo;
188
			z = $('#searchResult #searchResultContent div.page .productItem').length;
189
			result = x + ' to ' + y + ' of <span class="resultLimit">' + z + '</span> <span class="style1">results</span>';
190
 
191
			len = arrSearchPaginationResult.length;
192
			for(var i=0; i<len; i++){
193
				arrSearchPaginationResult.pop();
194
			}
195
 
196
			$('#searchResult #searchResultContent div.page').each(function(){
197
				arrSearchPaginationResult.push([x, y]);
198
 
199
				x = y + 1;
200
				y = x + ($('.productItem', this).length - 1);
201
			});
202
 
203
			$("#searchResult #searchResultContent .productListResult").html(result);
204
		}else{
205
			result = '0 to 0 of <span class="resultLimit"> 0 </span> <span class="style1">results</span>';
206
 
207
			$("#searchResult #searchResultContent .productListResult").html(result);
208
		}
209
	}
210
}
211
 
212
/*
213
 * Search result content
214
*/
215
function searchContentCallback(page_index, jq){
216
 
217
	// Show page content
218
	$('#searchResult #searchResultContent div.page:visible').hide();
219
	$('#searchResult #searchResultContent div.page:eq(' + page_index + ')').show(); 
220
 
221
	x = arrSearchPaginationResult[page_index][0];
222
	y = arrSearchPaginationResult[page_index][1];
223
	z = $('#searchResult #searchResultContent div.page .productItem').length; 
224
 
225
	result = x + ' to ' + y + ' of <span class="resultLimit">' + z + '</span> <span class="style1">results</span>';
226
 
227
	$("#searchResult #searchResultContent .productListResult").html(result);
228
 
229
	return false;
230
}
231
 
232
/*
233
 * Remove last active tab state
234
*/
235
function removeLastActiveState(){
236
	if($('#tabButton a#activeTab').length == 1){
237
 
238
		$('#tabButton div').each(function(){
239
			if($("a", this).attr("id") == "activeTab"){
240
				$("a", this).attr("id", "");
241
			}
242
		});
243
 
244
	}
245
}
246
 
247
/*
248
 * Make active tab
249
*/
250
function activeTab(id){
251
	$("#" + id + " a").attr("class","category-tabs activeTab");
252
}
253
 
254
/*
255
 * Hide tab content
256
*/
257
function hideShowTabContent(id, state){	
258
	if(state == "hide"){
259
		$("#" + id).hide();
260
	}else if(state == "show"){
261
		$("#" + id).show();
262
	}
263
 
264
	if(id == "multifacetedSearch"){
265
		if(state == "hide"){
266
			$("#productCat .top .left").css("background", "#fff");
267
			$("#productCat .bottom .left").css("background", "url(/images/product-detail-bottom-left.jpg) no-repeat");
268
			$("#productCat .middle .content").css("background-image", "none");
269
 
270
			$("#productList").css("width", "100%");
271
			$("#productList").css("margin-left", "0");
272
 
273
			$("#productList #productListCenter .floatLeft").css("margin-left", "70px");
274
			$("#productList #productListCenter .floatRight").css("margin-right", "70px");
275
		}else if(state == "show"){
276
			$("#productCat .top .left").css("background", "#efeff0");
277
			$("#productCat .bottom .left").css("background", "url(/images/product-cat-bottom-left.jpg) no-repeat");
278
			$("#productCat .middle .content").css("background", "#ffffff url(/images/grey-ver-bar.gif) repeat-y");
279
 
3830 chandransh 280
			$("#productList").css("width", "515px");
878 rajveer 281
			$("#productList").css("margin-left", "1px");
282
 
283
			$("#productList #productListCenter .floatLeft").css("margin-left", "16px");
284
			$("#productList #productListCenter .floatRight").css("margin-right", "16px");
285
		}
286
	}
287
}
288
 
289
/*
290
 * Set content heading on tab click
291
*/
292
function setContentHeading(str){
293
	if($("#otherTabContent:visible").length == 1){
294
		$("#otherTabContent .productListHeading").text(str);
295
	}
296
}