Subversion Repositories SmartDukaan

Rev

Rev 11006 | Go to most recent revision | Details | 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;
192
document.addEventListener("scroll", function (event) {
193
if(document.getElementsByClassName('refine-mask')[0].style.display == 'none' || document.getElementsByClassName('refine-mask')[0].style.display == ''){  
194
	var x = document.body.scrollTop;  
195
    	var maxY = document.documentElement.scrollHeight - document.documentElement.clientHeight;
196
    		// when user reaches end of the page
197
    		if(x>startscroll)
198
    		{
199
    			startscroll = x;
200
    		}
201
    		else if(maxY==x)
202
    		{
203
    				startscroll=0;
204
    				window.scrollTo(0,0);
205
    				return false;
206
    		}
207
    		else
208
    		{
209
 
210
    			return false;
211
    		}
212
    if (getDocHeight() <= getScrollXY()[1] + window.innerHeight + 300) {
213
    	debugger;
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
  debugger;
247
  var attrval = e.target.getAttribute('data-val');
248
  //var path = window.location.pathname;
249
  var path = document.URL;
250
  if(path.indexOf('fq') != -1){
251
    if(path.indexOf('sortedBy') == -1){
252
    window.location = document.URL.split('?')[0]+'?sortedBy='+attrval+'&'+document.URL.split('?').pop();
253
    }else{
254
      var npath = document.URL.split('?')[1].split('&');
255
      npath.slice(1);
256
      window.location = document.URL.split('?')[0]+'?sortedBy='+attrval+'&' +npath.slice(1).join('&');;
257
    }
258
  }else{
259
  //var val = path.split("/").pop();
260
  var npath = path.split('?')[0];
261
  window.location = npath+'?sortedBy='+attrval;
262
  }
263
}
264
 
265
 
266
 
267
var fq = new Array();
268
var i=0;
269
 
270
function filter(e){
271
	debugger;
272
	var id = e.currentTarget;
273
	var key = id.getAttribute('data-key');
274
	var value = id.getAttribute('data-value');
275
 
276
	if(e.currentTarget.className != 'opt selected'){
277
    e.currentTarget.className += ' selected' ;
278
    fq[i] = (key+':'+value);
279
    i++;
280
  }else{
281
    e.currentTarget.className = 'opt';
282
    var ind = fq.indexOf(key+':'+value);
283
    if(ind != -1){
284
    	fq.splice(ind,1);
285
    	i--;
286
    }
287
    var itemStore = items.indexOf(value);
288
    if(itemStore != -1){
289
    	items.splice(itemStore,1);
290
    }
291
  }
292
  e.stopPropagation();
293
}
294
 
295
function applyFilter(e){
296
 
297
  minVal = document.getElementById('exTO').innerHTML;
298
  maxVal = document.getElementById('exFR').innerHTML;
299
	debugger;
300
	if(items.length > 0){
301
		for(j=0;j<items.length;j++){
302
			if(document.getElementById(items[j]).className == 'opt selected'){
303
				var name = document.getElementById(items[j]);
304
				name = name.getAttribute('data-key')+':'+name.getAttribute('data-value');
305
				fq[i] = name;
306
				i++;
307
			}
308
		}
309
	}
310
	if(fq.length > 0){
311
		var filters = fq.join('&fq=');
312
		var url = document.URL;
313
		if(url.indexOf('sortedBy') != -1){
314
			var url = spliturl(url);
315
			var sort = url[1];
316
			sort = sort.split('&');
317
			sort = sort[0];
318
			if((ominVal != minVal) || (omaxVal != maxVal)){
319
			  var newUrl = url[2]+'?'+sort+'&fq='+filters+'&minPrice='+minVal+'&maxPrice='+maxVal ;
320
			}else{
321
			var newUrl = url[2]+'?'+sort+'&fq='+filters;
322
			}
323
		}
324
		else if(url.indexOf('sortedBy') == -1){
325
			url = spliturl(url);
326
			url = url[2];
327
			if((ominVal != minVal) || (omaxVal != maxVal)){
328
			  var newUrl = url+'?fq='+filters+'&minPrice='+minVal+'&maxPrice='+maxVal ;
329
			}else{
330
			var newUrl = url+'?fq='+filters;
331
			}
332
		}
333
		window.location.href = newUrl;
334
	}else {
335
		 if((ominVal != minVal) || (omaxVal != maxVal)){
336
	  		var url = document.URL;
337
    		if(url.indexOf('sortedBy') != -1){
338
      		var url = spliturl(url);
339
      		var sort = url[1];
340
      		sort = sort.split('&');
341
      		sort = sort[0];
342
      		var newUrl = url[2]+'?'+sort+'&minPrice='+minVal+'&maxPrice='+maxVal;
343
      		}else{
344
      		  var url = document.URL;
345
      		  url = spliturl(url);
346
	  		  var newUrl = url[2]+'?minPrice='+minVal+'&maxPrice='+maxVal;
347
	  		}
348
		}
349
		 else{
350
		 	newUrl = document.URL;
351
		 	newUrl = spliturl(newUrl);
352
		 	newUrl = newUrl.pop();
353
		 }
354
		 window.location.href = newUrl;
355
	}
356
	e.stopPropagation();
357
}
358
 
359
function clearfilter(e){
360
	debugger;
361
	minVal = document.getElementById('exTO').innerHTML;
362
  	maxVal = document.getElementById('exFR').innerHTML;
363
	if(items.length>0){
364
	 	items.length = 0;
365
	 }
366
	var selected = document.getElementsByClassName('selected');
367
	if(selected.length >0){
368
		for (var i = 0; i < selected.length;) {
369
			selected[i].setAttribute('class','opt');
370
		}
371
		var url = document.URL;
372
		url = spliturl(url);
373
		if(document.URL.indexOf('sortedBy') == -1){
374
			if((ominVal != minVal) || (omaxVal != maxVal)){
375
				var newUrl = url[2]+'?minPrice='+minVal+'&maxPrice='+maxVal;
376
			}
377
			else{
378
				e.stopPropagation();
379
				return false;
380
			}
381
			window.location.href = newUrl;
382
		}
383
		else if(url[1].indexOf('sortedBy') != -1){
384
			var a = url[1].split('&');
385
			for(var i=0;i< a.length ;i++){
386
				if(a[i].indexOf('sortedBy') != -1){
387
					sort=a[i];
388
				}
389
			}
390
			if((ominVal != minVal) || (omaxVal != maxVal)){
391
				var newUrl = url[2]+'?'+sort+'&minPrice='+minVal+'&maxPrice='+maxVal ;
392
			}
393
			else{
394
				var newUrl = url[2]+'?'+sort;
395
			}
396
			window.location.href = newUrl;
397
		}
398
	}
399
	e.stopPropagation();
400
}