Subversion Repositories SmartDukaan

Rev

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