Subversion Repositories SmartDukaan

Rev

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

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