Subversion Repositories SmartDukaan

Rev

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