Subversion Repositories SmartDukaan

Rev

Rev 11006 | Rev 11119 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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