Subversion Repositories SmartDukaan

Rev

Rev 11289 | Rev 11710 | 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;
165
				if(cpage % 3 ==0){
166
					showmore = 'block';
167
				}
168
				else{
169
					showmore = 'none';
170
					document.getElementById("showmorebutton").style.display='none';
171
				}
172
				if (parseInt(total) <= parseInt(cpage)) {
173
					showmore = 'none';
174
					nextpageload = false;
175
					document.getElementById("showmorebutton").style.display='none';
176
				}
177
				var str = document.URL;
178
				nextpageload = true;
179
				if(str.indexOf("page") !== -1){
180
				data = spliturl(str);
181
				newdata= data[1].split("&");
182
				var a = newdata.length;
183
				for(var i=0;i< a ;i++){
184
				if(newdata[i].indexOf('page') != -1){
185
				  newdata[i]='page='+(parseInt(newdata[i].split('=')[1])+1);
186
				  }
187
				}
188
				var url = data[2]+'?'+newdata.join("&");
189
				window.history.replaceState("",document.title, url);}
190
				else{
191
					if(str.indexOf('sortedBy') != -1 || str.indexOf('fq') != -1 || str.indexOf('minPrice') != -1){
192
						window.history.replaceState("",document.title, window.location.href+"&page=2");		
193
					}
194
					else{
195
						window.history.replaceState("",document.title, window.location.href+"?page=2");
196
					}	
197
				}
198
			}
199
			else
200
			{	addCookie('shopMoreUrl' , window.location.href, 1);
201
				document.getElementById("showmorebutton").style.display='none';}
202
		});
203
 
204
	}
205
 
206
var startscroll = 0;
11006 lgm 207
var ua = navigator.userAgent.toLowerCase();
10582 lgm 208
document.addEventListener("scroll", function (event) {
209
if(document.getElementsByClassName('refine-mask')[0].style.display == 'none' || document.getElementsByClassName('refine-mask')[0].style.display == ''){  
11006 lgm 210
	var x = (document.documentElement && document.documentElement.scrollTop) || document.body.scrollTop;  
10582 lgm 211
    	var maxY = document.documentElement.scrollHeight - document.documentElement.clientHeight;
212
    		// when user reaches end of the page
213
    		if(x>startscroll)
214
    		{
215
    			startscroll = x;
216
    		}
217
    		else if(maxY==x)
218
    		{
219
    				startscroll=0;
220
    				window.scrollTo(0,0);
221
    				return false;
222
    		}
223
    		else
224
    		{
225
 
226
    			return false;
227
    		}
228
    if (getDocHeight() <= getScrollXY()[1] + window.innerHeight + 300) {
229
    	if(((document.getElementById('page').innerHTML%3) != 0) && nextpageload==true){
230
    		//console.log(x);
231
    		total = document.getElementById('count').value;
232
        	cpage = document.getElementById('page').innerHTML;
233
        	nextpageload=false;
234
    		if (parseInt(total) <= parseInt(cpage)) {
235
            showmore = 'none';
236
            nextpageload = false;
237
          	}else{
238
          		showMoreProducts();}
239
        	}
240
      		else{
241
    			if(showmore === 'block'){
242
    				document.getElementById('showmorebutton').style.display = 'block';
243
    			} 		
244
    		}
245
    	}
246
}});
247
function toggleListview(e){
248
 
249
  var a = document.getElementsByClassName('pd-list-hldr')[0];
250
  if(a.className == 'pd-list-hldr clearfix'){
251
  a.className += ' grid';
252
  e.currentTarget.className = 'list-icon';
253
  }else{
254
    a.className = 'pd-list-hldr clearfix';
255
    e.currentTarget.className = '';
256
  }
257
 
258
}
259
 
260
function fireSort(e){
261
  var attrval = e.target.getAttribute('data-val');
262
  //var path = window.location.pathname;
263
  var path = document.URL;
11119 lgm 264
  if((path.indexOf('fq') != -1) || (path.indexOf('minPrice') != -1)){
10582 lgm 265
    if(path.indexOf('sortedBy') == -1){
266
    window.location = document.URL.split('?')[0]+'?sortedBy='+attrval+'&'+document.URL.split('?').pop();
267
    }else{
268
      var npath = document.URL.split('?')[1].split('&');
269
      npath.slice(1);
270
      window.location = document.URL.split('?')[0]+'?sortedBy='+attrval+'&' +npath.slice(1).join('&');;
271
    }
272
  }else{
273
  //var val = path.split("/").pop();
274
  var npath = path.split('?')[0];
275
  window.location = npath+'?sortedBy='+attrval;
276
  }
277
}
278
 
279
 
280
 
281
var fq = new Array();
282
var i=0;
283
 
284
function filter(e){
11325 lgm 285
 
10582 lgm 286
	var id = e.currentTarget;
287
	var key = id.getAttribute('data-key');
288
	var value = id.getAttribute('data-value');
289
 
290
	if(e.currentTarget.className != 'opt selected'){
291
    e.currentTarget.className += ' selected' ;
292
    fq[i] = (key+':'+value);
293
    i++;
294
  }else{
295
    e.currentTarget.className = 'opt';
296
    var ind = fq.indexOf(key+':'+value);
297
    if(ind != -1){
298
    	fq.splice(ind,1);
299
    	i--;
300
    }
301
    var itemStore = items.indexOf(value);
302
    if(itemStore != -1){
303
    	items.splice(itemStore,1);
304
    }
305
  }
306
  e.stopPropagation();
307
}
308
 
309
function applyFilter(e){
11325 lgm 310
 
10582 lgm 311
  minVal = document.getElementById('exTO').innerHTML;
312
  maxVal = document.getElementById('exFR').innerHTML;
313
	if(items.length > 0){
11325 lgm 314
 
10582 lgm 315
		for(j=0;j<items.length;j++){
316
			if(document.getElementById(items[j]).className == 'opt selected'){
317
				var name = document.getElementById(items[j]);
318
				name = name.getAttribute('data-key')+':'+name.getAttribute('data-value');
319
				fq[i] = name;
320
				i++;
321
			}
322
		}
323
	}
324
	if(fq.length > 0){
325
		var filters = fq.join('&fq=');
326
		var url = document.URL;
327
		if(url.indexOf('sortedBy') != -1){
11120 lgm 328
			var url = spliturl(url);
329
			var sort = url[1];
330
			sort = sort.split('&');
331
			sort = sort[0];
332
			if((ominVal != minVal) || (omaxVal != maxVal)){
333
			  var newUrl = url[2]+'?'+sort+'&fq='+filters+'&minPrice='+minVal+'&maxPrice='+maxVal ;
334
			}else{
335
			var newUrl = url[2]+'?'+sort+'&fq='+filters;
336
			}
10582 lgm 337
		}
338
		else if(url.indexOf('sortedBy') == -1){
339
			url = spliturl(url);
340
			url = url[2];
341
			if((ominVal != minVal) || (omaxVal != maxVal)){
342
			  var newUrl = url+'?fq='+filters+'&minPrice='+minVal+'&maxPrice='+maxVal ;
343
			}else{
344
			var newUrl = url+'?fq='+filters;
345
			}
346
		}
347
		window.location.href = newUrl;
348
	}else {
349
		 if((ominVal != minVal) || (omaxVal != maxVal)){
350
	  		var url = document.URL;
351
    		if(url.indexOf('sortedBy') != -1){
352
      		var url = spliturl(url);
353
      		var sort = url[1];
354
      		sort = sort.split('&');
355
      		sort = sort[0];
356
      		var newUrl = url[2]+'?'+sort+'&minPrice='+minVal+'&maxPrice='+maxVal;
357
      		}else{
358
      		  var url = document.URL;
359
      		  url = spliturl(url);
360
	  		  var newUrl = url[2]+'?minPrice='+minVal+'&maxPrice='+maxVal;
361
	  		}
362
		}
363
		 else{
364
		 	newUrl = document.URL;
365
		 	newUrl = spliturl(newUrl);
366
		 	newUrl = newUrl.pop();
367
		 }
368
		 window.location.href = newUrl;
369
	}
370
	e.stopPropagation();
371
}
372
 
373
function clearfilter(e){
11160 lgm 374
	 minVal = document.getElementById('exTO').innerHTML;
10582 lgm 375
  	maxVal = document.getElementById('exFR').innerHTML;
376
	if(items.length>0){
377
	 	items.length = 0;
378
	 }
379
	var selected = document.getElementsByClassName('selected');
380
	if(selected.length >0){
381
		for (var i = 0; i < selected.length;) {
382
			selected[i].setAttribute('class','opt');
383
		}
384
		var url = document.URL;
385
		url = spliturl(url);
386
		if(document.URL.indexOf('sortedBy') == -1){
11160 lgm 387
			// if((ominVal != minVal) || (omaxVal != maxVal)){
388
			// 	var newUrl = url[2]+'?minPrice='+minVal+'&maxPrice='+maxVal;
389
			// }
390
			// else{
391
				var newUrl = url[2];
10582 lgm 392
				e.stopPropagation();
11160 lgm 393
			//}
10582 lgm 394
			window.location.href = newUrl;
395
		}
396
		else if(url[1].indexOf('sortedBy') != -1){
397
			var a = url[1].split('&');
398
			for(var i=0;i< a.length ;i++){
399
				if(a[i].indexOf('sortedBy') != -1){
400
					sort=a[i];
401
				}
402
			}
11160 lgm 403
			// if((ominVal != minVal) || (omaxVal != maxVal)){
404
				// var newUrl = url[2]+'?'+sort+'&minPrice='+minVal+'&maxPrice='+maxVal ;
405
			// }
406
			// else{
10582 lgm 407
				var newUrl = url[2]+'?'+sort;
11160 lgm 408
			//}
10582 lgm 409
			window.location.href = newUrl;
410
		}
411
	}
412
	e.stopPropagation();
413
}