Subversion Repositories SmartDukaan

Rev

Rev 11719 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
11289 lgm 1
var pheight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
2
if(document.getElementById('appendlist') != undefined){
3
    document.getElementById('appendlist').style.minHeight = pheight - 216 +'px';  
4
}
11094 lgm 5
 
11289 lgm 6
 
11119 lgm 7
if(document.getElementsByClassName('cart-cont')[0] != undefined){
8
 document.getElementsByClassName('cart-cont')[0].style.minHeight = (screen.height - 235) +'px'; 
9
}
11094 lgm 10
 
11119 lgm 11
if((document.URL.indexOf('fq') != -1) || (document.URL.indexOf('minPrice') != -1)){
11160 lgm 12
  document.getElementsByClassName('filter')[0].className +=' filter-selected';
11119 lgm 13
}
14
 
15
if(document.URL.indexOf('sortedBy') != -1){
16
  document.getElementsByClassName('sort')[0].className +=' selected';
17
}
18
 
10582 lgm 19
var minVal, 
20
    maxVal;
21
 
22
var ominVal = document.getElementById('minprice').innerHTML;
23
var omaxVal = document.getElementById('maxprice').innerHTML;
24
 
25
function spliturl(url)
26
{
27
 fullpath = url.substring(0, (url.indexOf("?") == -1) ? url.length : url.indexOf("?"));
28
 params =fullpath.split('<?=base_url()?>');
29
 getparams = url.split('?');
30
 var output = new Array();
31
 output[0] = params[1]; //data controller to parameters
32
 output[1] = getparams[1];//get input
33
 output[2]=fullpath; //full url expcept get input
34
 return output;
35
}
36
var showmore;
37
var nextpageload = true;
38
function showMoreProducts()
39
	{
40
		var cpage =document.getElementById('page').innerHTML;
41
		var url = document.URL;
42
		if(!cpage){cpage=2;} else {cpage = parseInt(cpage) +1;}
43
		var data = spliturl(document.URL);
44
		var cat = data[2].split('/');
45
		cat = cat.pop();
46
		if(url.indexOf('sortedBy') != -1){
47
			var a = data[1].split('&');
48
			for(var i=0;i< a.length ;i++){
49
				if(a[i].indexOf('sortedBy') != -1){
50
					sort=a[i].split('=')[1];
51
					var newUrl = base_url+'products/getProductList/'+cat+'/'+cpage+'/'+sort+'/null/null';
52
				}
53
			}
54
			if(url.indexOf('fq') != -1){
55
				var filterq = new Array();
56
				var j = 0;
57
				for(var i=0;i< a.length ;i++){
58
					if(a[i].indexOf('fq') != -1){
59
						filterq[j]=a[i].split('=')[1];
60
						j++;
61
					}
62
				}
63
				filterq = filterq.join('&fq=');
64
				if(url.indexOf('minPrice') != -1 && url.indexOf('maxPrice') != -1){
65
					var a = data[1].split('&');
66
					var price = new Array();
67
					var j=0;
68
					for(var i=0;i< a.length ;i++){
69
						if(a[i].indexOf('minPrice') != -1){
70
							price[j]=a[i].split('=')[1];
71
							j++;
72
						}
73
						if(a[i].indexOf('maxPrice') != -1){
74
							price[j]=a[i].split('=')[1];
75
							j++;
76
						}
77
					}
78
					price = price.join('&');
79
					var newUrl = base_url+'products/getProductList/'+cat+'/'+cpage+'/'+sort+'/'+encodeURIComponent(filterq)+'/'+price;
80
				}else{
81
					var newUrl = base_url+'products/getProductList/'+cat+'/'+cpage+'/'+sort+'/'+encodeURIComponent(filterq)+'/null';
82
				}
83
			}
84
			else if(url.indexOf('minPrice') != -1 && url.indexOf('maxPrice') != -1){
85
				var a = data[1].split('&');
86
				var price = new Array();
87
				var j=0;
88
				for(var i=0;i< a.length ;i++){
89
					if(a[i].indexOf('minPrice') != -1){
90
						price[j]=a[i].split('=')[1];
91
						j++;
92
					}
93
					if(a[i].indexOf('maxPrice') != -1){
94
						price[j]=a[i].split('=')[1];
95
						j++;
96
					}
97
				}
98
				price = price.join('&');
99
				var newUrl = base_url+'products/getProductList/'+cat+'/'+cpage+'/'+sort+'/null/'+price;
100
			}
101
		}
102
		else{
103
			if(url.indexOf('fq') != -1){
104
				var a = data[1].split('&');
105
				var filterq = new Array();
106
				var j = 0;
107
				for(var i=0;i< a.length ;i++){
108
					if(a[i].indexOf('fq') != -1){
109
						filterq[j]=a[i].split('=')[1];
110
						j++;
111
					}
112
				}
113
				filterq = filterq.join('&fq=');
114
				if(url.indexOf('minPrice') != -1 && url.indexOf('maxPrice') != -1){
115
					var a = data[1].split('&');
116
					var price = new Array();
117
					var j=0;
118
					for(var i=0;i< a.length ;i++){
119
						if(a[i].indexOf('minPrice') != -1){
120
							price[j]=a[i].split('=')[1];
121
							j++;
122
						}
123
						if(a[i].indexOf('maxPrice') != -1){
124
							price[j]=a[i].split('=')[1];
125
							j++;
126
						}
127
					}
128
					price = price.join('&');
129
					var newUrl = base_url+'products/getProductList/'+cat+'/'+cpage+'/null'+'/'+encodeURIComponent(filterq)+'/'+price;
130
				}else{
131
					var newUrl = base_url+'products/getProductList/'+cat+'/'+cpage+'/null'+'/'+encodeURIComponent(filterq)+'/null';
132
				}
133
			}else if(url.indexOf('minPrice') != -1 && url.indexOf('maxPrice') != -1){
134
				var a = data[1].split('&');
135
				var price = new Array();
136
				var j=0;
137
				for(var i=0;i< a.length ;i++){
138
					if(a[i].indexOf('minPrice') != -1){
139
						price[j]=a[i].split('=')[1];
140
						j++;
141
					}
142
					if(a[i].indexOf('maxPrice') != -1){
143
						price[j]=a[i].split('=')[1];
144
						j++;
145
					}
146
				}
147
				price = price.join('&');
148
				var newUrl = base_url+'products/getProductList/'+cat+'/'+cpage+'/null'+'/null/'+price;
149
			}
150
			else{
151
				var newUrl = base_url+'products/getProductList/'+cat+'/'+cpage+'/null'+'/null/null';
152
			}
153
		}
154
		microAjax(newUrl, function(res)
155
		{
156
			if(res!='')
157
			{
158
				var appenddata =document.getElementById("appendlist");
159
				var total = document.getElementById('count').value;
160
				appenddata.innerHTML= appenddata.innerHTML +  res;
161
				document.getElementById('page').innerHTML =  cpage;
11710 lgm 162
				if(!isOperaMini){
163
			        if (cpage % 3 == 0) {
164
			          showmore = "block";
165
			        } else {
166
			          showmore = "none";
167
			          document.getElementById("showmorebutton").style.display = "none";
168
			        }
10582 lgm 169
				}
170
				if (parseInt(total) <= parseInt(cpage)) {
171
					showmore = 'none';
172
					nextpageload = false;
173
					document.getElementById("showmorebutton").style.display='none';
174
				}
175
				var str = document.URL;
176
				nextpageload = true;
177
				if(str.indexOf("page") !== -1){
178
				data = spliturl(str);
179
				newdata= data[1].split("&");
180
				var a = newdata.length;
181
				for(var i=0;i< a ;i++){
182
				if(newdata[i].indexOf('page') != -1){
183
				  newdata[i]='page='+(parseInt(newdata[i].split('=')[1])+1);
184
				  }
185
				}
186
				var url = data[2]+'?'+newdata.join("&");
187
				window.history.replaceState("",document.title, url);}
188
				else{
189
					if(str.indexOf('sortedBy') != -1 || str.indexOf('fq') != -1 || str.indexOf('minPrice') != -1){
190
						window.history.replaceState("",document.title, window.location.href+"&page=2");		
191
					}
192
					else{
193
						window.history.replaceState("",document.title, window.location.href+"?page=2");
194
					}	
195
				}
196
			}
197
			else
198
			{	addCookie('shopMoreUrl' , window.location.href, 1);
199
				document.getElementById("showmorebutton").style.display='none';}
200
		});
201
 
202
	}
203
 
11710 lgm 204
var isOperaMini = (navigator.userAgent.indexOf('Opera Mini') > -1);
205
if(isOperaMini){
11719 lgm 206
  total = document.getElementById('count').value;
207
  cpage = document.getElementById('page').innerHTML;
208
  if (parseInt(total) <= parseInt(cpage)) {
209
  	document.getElementById("showmorebutton").style.display = "none";
210
  }else{
211
  	document.getElementById("showmorebutton").style.display = "block";
212
  }
11710 lgm 213
}
10582 lgm 214
var startscroll = 0;
11006 lgm 215
var ua = navigator.userAgent.toLowerCase();
10582 lgm 216
document.addEventListener("scroll", function (event) {
217
if(document.getElementsByClassName('refine-mask')[0].style.display == 'none' || document.getElementsByClassName('refine-mask')[0].style.display == ''){  
11006 lgm 218
	var x = (document.documentElement && document.documentElement.scrollTop) || document.body.scrollTop;  
10582 lgm 219
    	var maxY = document.documentElement.scrollHeight - document.documentElement.clientHeight;
220
    		// when user reaches end of the page
221
    		if(x>startscroll)
222
    		{
223
    			startscroll = x;
224
    		}
225
    		else if(maxY==x)
226
    		{
227
    				startscroll=0;
228
    				window.scrollTo(0,0);
229
    				return false;
230
    		}
231
    		else
232
    		{
233
 
234
    			return false;
235
    		}
236
    if (getDocHeight() <= getScrollXY()[1] + window.innerHeight + 300) {
237
    	if(((document.getElementById('page').innerHTML%3) != 0) && nextpageload==true){
238
    		total = document.getElementById('count').value;
239
        	cpage = document.getElementById('page').innerHTML;
240
        	nextpageload=false;
241
    		if (parseInt(total) <= parseInt(cpage)) {
242
            showmore = 'none';
243
            nextpageload = false;
244
          	}else{
245
          		showMoreProducts();}
246
        	}
247
      		else{
248
    			if(showmore === 'block'){
249
    				document.getElementById('showmorebutton').style.display = 'block';
250
    			} 		
251
    		}
252
    	}
253
}});
254
function toggleListview(e){
255
 
256
  var a = document.getElementsByClassName('pd-list-hldr')[0];
257
  if(a.className == 'pd-list-hldr clearfix'){
258
  a.className += ' grid';
259
  e.currentTarget.className = 'list-icon';
260
  }else{
261
    a.className = 'pd-list-hldr clearfix';
262
    e.currentTarget.className = '';
263
  }
264
 
265
}
266
 
267
function fireSort(e){
268
  var attrval = e.target.getAttribute('data-val');
269
  //var path = window.location.pathname;
270
  var path = document.URL;
11119 lgm 271
  if((path.indexOf('fq') != -1) || (path.indexOf('minPrice') != -1)){
10582 lgm 272
    if(path.indexOf('sortedBy') == -1){
273
    window.location = document.URL.split('?')[0]+'?sortedBy='+attrval+'&'+document.URL.split('?').pop();
274
    }else{
275
      var npath = document.URL.split('?')[1].split('&');
276
      npath.slice(1);
277
      window.location = document.URL.split('?')[0]+'?sortedBy='+attrval+'&' +npath.slice(1).join('&');;
278
    }
279
  }else{
280
  //var val = path.split("/").pop();
281
  var npath = path.split('?')[0];
282
  window.location = npath+'?sortedBy='+attrval;
283
  }
284
}
285
 
286
 
287
 
288
var fq = new Array();
289
var i=0;
290
 
291
function filter(e){
11325 lgm 292
 
10582 lgm 293
	var id = e.currentTarget;
294
	var key = id.getAttribute('data-key');
295
	var value = id.getAttribute('data-value');
296
 
297
	if(e.currentTarget.className != 'opt selected'){
298
    e.currentTarget.className += ' selected' ;
299
    fq[i] = (key+':'+value);
300
    i++;
301
  }else{
302
    e.currentTarget.className = 'opt';
303
    var ind = fq.indexOf(key+':'+value);
304
    if(ind != -1){
305
    	fq.splice(ind,1);
306
    	i--;
307
    }
308
    var itemStore = items.indexOf(value);
309
    if(itemStore != -1){
310
    	items.splice(itemStore,1);
311
    }
312
  }
313
  e.stopPropagation();
314
}
315
 
316
function applyFilter(e){
11325 lgm 317
 
10582 lgm 318
  minVal = document.getElementById('exTO').innerHTML;
319
  maxVal = document.getElementById('exFR').innerHTML;
320
	if(items.length > 0){
11325 lgm 321
 
10582 lgm 322
		for(j=0;j<items.length;j++){
323
			if(document.getElementById(items[j]).className == 'opt selected'){
324
				var name = document.getElementById(items[j]);
325
				name = name.getAttribute('data-key')+':'+name.getAttribute('data-value');
326
				fq[i] = name;
327
				i++;
328
			}
329
		}
330
	}
331
	if(fq.length > 0){
332
		var filters = fq.join('&fq=');
333
		var url = document.URL;
334
		if(url.indexOf('sortedBy') != -1){
11120 lgm 335
			var url = spliturl(url);
336
			var sort = url[1];
337
			sort = sort.split('&');
338
			sort = sort[0];
339
			if((ominVal != minVal) || (omaxVal != maxVal)){
340
			  var newUrl = url[2]+'?'+sort+'&fq='+filters+'&minPrice='+minVal+'&maxPrice='+maxVal ;
341
			}else{
342
			var newUrl = url[2]+'?'+sort+'&fq='+filters;
343
			}
10582 lgm 344
		}
345
		else if(url.indexOf('sortedBy') == -1){
346
			url = spliturl(url);
347
			url = url[2];
348
			if((ominVal != minVal) || (omaxVal != maxVal)){
349
			  var newUrl = url+'?fq='+filters+'&minPrice='+minVal+'&maxPrice='+maxVal ;
350
			}else{
351
			var newUrl = url+'?fq='+filters;
352
			}
353
		}
354
		window.location.href = newUrl;
355
	}else {
356
		 if((ominVal != minVal) || (omaxVal != maxVal)){
357
	  		var url = document.URL;
358
    		if(url.indexOf('sortedBy') != -1){
359
      		var url = spliturl(url);
360
      		var sort = url[1];
361
      		sort = sort.split('&');
362
      		sort = sort[0];
363
      		var newUrl = url[2]+'?'+sort+'&minPrice='+minVal+'&maxPrice='+maxVal;
364
      		}else{
365
      		  var url = document.URL;
366
      		  url = spliturl(url);
367
	  		  var newUrl = url[2]+'?minPrice='+minVal+'&maxPrice='+maxVal;
368
	  		}
369
		}
370
		 else{
371
		 	newUrl = document.URL;
372
		 	newUrl = spliturl(newUrl);
373
		 	newUrl = newUrl.pop();
374
		 }
375
		 window.location.href = newUrl;
376
	}
377
	e.stopPropagation();
378
}
379
 
380
function clearfilter(e){
11160 lgm 381
	 minVal = document.getElementById('exTO').innerHTML;
10582 lgm 382
  	maxVal = document.getElementById('exFR').innerHTML;
383
	if(items.length>0){
384
	 	items.length = 0;
385
	 }
386
	var selected = document.getElementsByClassName('selected');
387
	if(selected.length >0){
388
		for (var i = 0; i < selected.length;) {
389
			selected[i].setAttribute('class','opt');
390
		}
391
		var url = document.URL;
392
		url = spliturl(url);
393
		if(document.URL.indexOf('sortedBy') == -1){
11160 lgm 394
			// if((ominVal != minVal) || (omaxVal != maxVal)){
395
			// 	var newUrl = url[2]+'?minPrice='+minVal+'&maxPrice='+maxVal;
396
			// }
397
			// else{
398
				var newUrl = url[2];
10582 lgm 399
				e.stopPropagation();
11160 lgm 400
			//}
10582 lgm 401
			window.location.href = newUrl;
402
		}
403
		else if(url[1].indexOf('sortedBy') != -1){
404
			var a = url[1].split('&');
405
			for(var i=0;i< a.length ;i++){
406
				if(a[i].indexOf('sortedBy') != -1){
407
					sort=a[i];
408
				}
409
			}
11160 lgm 410
			// if((ominVal != minVal) || (omaxVal != maxVal)){
411
				// var newUrl = url[2]+'?'+sort+'&minPrice='+minVal+'&maxPrice='+maxVal ;
412
			// }
413
			// else{
10582 lgm 414
				var newUrl = url[2]+'?'+sort;
11160 lgm 415
			//}
10582 lgm 416
			window.location.href = newUrl;
417
		}
418
	}
419
	e.stopPropagation();
420
}