Subversion Repositories SmartDukaan

Rev

Rev 11899 | Go to most recent revision | Details | Last modification | View Log | RSS feed

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