Subversion Repositories SmartDukaan

Rev

Rev 11094 | Rev 11120 | 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)){
7
  document.getElementsByClassName('filter')[0].className +=' selected';
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){
280
	var id = e.currentTarget;
281
	var key = id.getAttribute('data-key');
282
	var value = id.getAttribute('data-value');
283
 
284
	if(e.currentTarget.className != 'opt selected'){
285
    e.currentTarget.className += ' selected' ;
286
    fq[i] = (key+':'+value);
287
    i++;
288
  }else{
289
    e.currentTarget.className = 'opt';
290
    var ind = fq.indexOf(key+':'+value);
291
    if(ind != -1){
292
    	fq.splice(ind,1);
293
    	i--;
294
    }
295
    var itemStore = items.indexOf(value);
296
    if(itemStore != -1){
297
    	items.splice(itemStore,1);
298
    }
299
  }
300
  e.stopPropagation();
301
}
302
 
303
function applyFilter(e){
304
 
305
  minVal = document.getElementById('exTO').innerHTML;
306
  maxVal = document.getElementById('exFR').innerHTML;
307
	if(items.length > 0){
308
		for(j=0;j<items.length;j++){
309
			if(document.getElementById(items[j]).className == 'opt selected'){
310
				var name = document.getElementById(items[j]);
311
				name = name.getAttribute('data-key')+':'+name.getAttribute('data-value');
312
				fq[i] = name;
313
				i++;
314
			}
315
		}
316
	}
317
	if(fq.length > 0){
318
		var filters = fq.join('&fq=');
319
		var url = document.URL;
320
		if(url.indexOf('sortedBy') != -1){
11119 lgm 321
			// var url = spliturl(url);
322
			// var sort = url[1];
323
			// sort = sort.split('&');
324
			// sort = sort[0];
325
			// if((ominVal != minVal) || (omaxVal != maxVal)){
326
			  // var newUrl = url[2]+'?'+sort+'&fq='+filters+'&minPrice='+minVal+'&maxPrice='+maxVal ;
327
			// }else{
328
			// var newUrl = url[2]+'?'+sort+'&fq='+filters;
329
			// }
10582 lgm 330
		}
331
		else if(url.indexOf('sortedBy') == -1){
332
			url = spliturl(url);
333
			url = url[2];
334
			if((ominVal != minVal) || (omaxVal != maxVal)){
335
			  var newUrl = url+'?fq='+filters+'&minPrice='+minVal+'&maxPrice='+maxVal ;
336
			}else{
337
			var newUrl = url+'?fq='+filters;
338
			}
339
		}
340
		window.location.href = newUrl;
341
	}else {
342
		 if((ominVal != minVal) || (omaxVal != maxVal)){
343
	  		var url = document.URL;
344
    		if(url.indexOf('sortedBy') != -1){
345
      		var url = spliturl(url);
346
      		var sort = url[1];
347
      		sort = sort.split('&');
348
      		sort = sort[0];
349
      		var newUrl = url[2]+'?'+sort+'&minPrice='+minVal+'&maxPrice='+maxVal;
350
      		}else{
351
      		  var url = document.URL;
352
      		  url = spliturl(url);
353
	  		  var newUrl = url[2]+'?minPrice='+minVal+'&maxPrice='+maxVal;
354
	  		}
355
		}
356
		 else{
357
		 	newUrl = document.URL;
358
		 	newUrl = spliturl(newUrl);
359
		 	newUrl = newUrl.pop();
360
		 }
361
		 window.location.href = newUrl;
362
	}
363
	e.stopPropagation();
364
}
365
 
366
function clearfilter(e){
367
	minVal = document.getElementById('exTO').innerHTML;
368
  	maxVal = document.getElementById('exFR').innerHTML;
369
	if(items.length>0){
370
	 	items.length = 0;
371
	 }
372
	var selected = document.getElementsByClassName('selected');
373
	if(selected.length >0){
374
		for (var i = 0; i < selected.length;) {
375
			selected[i].setAttribute('class','opt');
376
		}
377
		var url = document.URL;
378
		url = spliturl(url);
379
		if(document.URL.indexOf('sortedBy') == -1){
380
			if((ominVal != minVal) || (omaxVal != maxVal)){
381
				var newUrl = url[2]+'?minPrice='+minVal+'&maxPrice='+maxVal;
382
			}
383
			else{
384
				e.stopPropagation();
385
				return false;
386
			}
387
			window.location.href = newUrl;
388
		}
389
		else if(url[1].indexOf('sortedBy') != -1){
390
			var a = url[1].split('&');
391
			for(var i=0;i< a.length ;i++){
392
				if(a[i].indexOf('sortedBy') != -1){
393
					sort=a[i];
394
				}
395
			}
396
			if((ominVal != minVal) || (omaxVal != maxVal)){
397
				var newUrl = url[2]+'?'+sort+'&minPrice='+minVal+'&maxPrice='+maxVal ;
398
			}
399
			else{
400
				var newUrl = url[2]+'?'+sort;
401
			}
402
			window.location.href = newUrl;
403
		}
404
	}
405
	e.stopPropagation();
406
}