Subversion Repositories SmartDukaan

Rev

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

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