Subversion Repositories SmartDukaan

Rev

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