Subversion Repositories SmartDukaan

Rev

Rev 11845 | Go to most recent revision | Details | Compare with Previous | 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);
11899 anikendra 42
 
11845 anikendra 43
		var newUrl = base_url+'privatedeals/getProductList/'+cpage;
44
		microAjax(newUrl, function(res)
45
		{
46
			if(res!='')
47
			{
48
				var appenddata =document.getElementById("appendlist");
49
				var total = document.getElementById('count').value;
50
				appenddata.innerHTML= appenddata.innerHTML +  res;
51
				document.getElementById('page').innerHTML =  cpage;
52
				if(!isOperaMini){
53
			        if (cpage % 3 == 0) {
54
			          showmore = "block";
55
			        } else {
56
			          showmore = "none";
57
			          document.getElementById("showmorebutton").style.display = "none";
58
			        }
59
				}
60
				if (parseInt(total) <= parseInt(cpage)) {
61
					showmore = 'none';
62
					nextpageload = false;
63
					document.getElementById("showmorebutton").style.display='none';
64
				}
65
				var str = document.URL;
66
				nextpageload = true;
67
				if(str.indexOf("page") !== -1){
68
				data = spliturl(str);
69
				newdata= data[1].split("&");
70
				var a = newdata.length;
71
				for(var i=0;i< a ;i++){
72
				if(newdata[i].indexOf('page') != -1){
73
				  newdata[i]='page='+(parseInt(newdata[i].split('=')[1])+1);
74
				  }
75
				}
76
				var url = data[2]+'?'+newdata.join("&");
77
				window.history.replaceState("",document.title, url);}
78
				else{
79
					if(str.indexOf('sortedBy') != -1 || str.indexOf('fq') != -1 || str.indexOf('minPrice') != -1){
80
						window.history.replaceState("",document.title, window.location.href+"&page=2");		
81
					}
82
					else{
83
						window.history.replaceState("",document.title, window.location.href+"?page=2");
84
					}	
85
				}
86
			}
87
			else
88
			{	addCookie('shopMoreUrl' , window.location.href, 1);
89
				document.getElementById("showmorebutton").style.display='none';}
90
		});
91
 
92
	}
93
 
94
var isOperaMini = (navigator.userAgent.indexOf('Opera Mini') > -1);
95
if(isOperaMini){
96
  total = document.getElementById('count').value;
97
  cpage = document.getElementById('page').innerHTML;
98
  if (parseInt(total) <= parseInt(cpage)) {
99
  	document.getElementById("showmorebutton").style.display = "none";
100
  }else{
101
  	document.getElementById("showmorebutton").style.display = "block";
102
  }
103
}
104
var startscroll = 0;
105
var ua = navigator.userAgent.toLowerCase();
106
document.addEventListener("scroll", function (event) {
107
//if(document.getElementsByClassName('refine-mask')[0].style.display == 'none' || document.getElementsByClassName('refine-mask')[0].style.display == ''){  
108
	var x = (document.documentElement && document.documentElement.scrollTop) || document.body.scrollTop;  
109
    	var maxY = document.documentElement.scrollHeight - document.documentElement.clientHeight;
110
    		// when user reaches end of the page
111
    		if(x>startscroll)
112
    		{
113
    			startscroll = x;
114
    		}
115
    		else if(maxY==x)
116
    		{
117
    				startscroll=0;
118
    				window.scrollTo(0,0);
119
    				return false;
120
    		}
121
    		else
122
    		{
123
 
124
    			return false;
125
    		}
126
    if (getDocHeight() <= getScrollXY()[1] + window.innerHeight + 300) {
127
    	if(((document.getElementById('page').innerHTML%3) != 0) && nextpageload==true){
128
    		//console.log(x);
129
    		total = document.getElementById('count').value;
130
        	cpage = document.getElementById('page').innerHTML;
131
        	nextpageload=false;
132
    		if (parseInt(total) <= parseInt(cpage)) {
133
            showmore = 'none';
134
            nextpageload = false;
135
          	}else{
136
          		showMoreProducts();}
137
        	}
138
      		else{
139
    			if(showmore === 'block'){
140
    				document.getElementById('showmorebutton').style.display = 'block';
141
    			} 		
142
    		}
143
    	}
144
	//}
145
});
146
function toggleListview(e){
147
 
148
  var a = document.getElementsByClassName('pd-list-hldr')[0];
149
  if(a.className == 'pd-list-hldr clearfix'){
150
  a.className += ' grid';
151
  e.currentTarget.className = 'list-icon';
152
  }else{
153
    a.className = 'pd-list-hldr clearfix';
154
    e.currentTarget.className = '';
155
  }
156
 
157
}
158
 
159
function fireSort(e){
160
  var attrval = e.target.getAttribute('data-val');
161
  //var path = window.location.pathname;
162
  var path = document.URL;
163
  if((path.indexOf('fq') != -1) || (path.indexOf('minPrice') != -1)){
164
    if(path.indexOf('sortedBy') == -1){
165
    window.location = document.URL.split('?')[0]+'?sortedBy='+attrval+'&'+document.URL.split('?').pop();
166
    }else{
167
      var npath = document.URL.split('?')[1].split('&');
168
      npath.slice(1);
169
      window.location = document.URL.split('?')[0]+'?sortedBy='+attrval+'&' +npath.slice(1).join('&');;
170
    }
171
  }else{
172
  //var val = path.split("/").pop();
173
  var npath = path.split('?')[0];
174
  window.location = npath+'?sortedBy='+attrval;
175
  }
176
}
177
 
178
 
179
 
180
var fq = new Array();
181
var i=0;
182
 
183
function filter(e){
184
 
185
	var id = e.currentTarget;
186
	var key = id.getAttribute('data-key');
187
	var value = id.getAttribute('data-value');
188
 
189
	if(e.currentTarget.className != 'opt selected'){
190
    e.currentTarget.className += ' selected' ;
191
    fq[i] = (key+':'+value);
192
    i++;
193
  }else{
194
    e.currentTarget.className = 'opt';
195
    var ind = fq.indexOf(key+':'+value);
196
    if(ind != -1){
197
    	fq.splice(ind,1);
198
    	i--;
199
    }
200
    var itemStore = items.indexOf(value);
201
    if(itemStore != -1){
202
    	items.splice(itemStore,1);
203
    }
204
  }
205
  e.stopPropagation();
206
}
207
 
208
function applyFilter(e){
209
 
210
  minVal = document.getElementById('exTO').innerHTML;
211
  maxVal = document.getElementById('exFR').innerHTML;
212
	if(items.length > 0){
213
 
214
		for(j=0;j<items.length;j++){
215
			if(document.getElementById(items[j]).className == 'opt selected'){
216
				var name = document.getElementById(items[j]);
217
				name = name.getAttribute('data-key')+':'+name.getAttribute('data-value');
218
				fq[i] = name;
219
				i++;
220
			}
221
		}
222
	}
223
	if(fq.length > 0){
224
		var filters = fq.join('&fq=');
225
		var url = document.URL;
226
		if(url.indexOf('sortedBy') != -1){
227
			var url = spliturl(url);
228
			var sort = url[1];
229
			sort = sort.split('&');
230
			sort = sort[0];
231
			if((ominVal != minVal) || (omaxVal != maxVal)){
232
			  var newUrl = url[2]+'?'+sort+'&fq='+filters+'&minPrice='+minVal+'&maxPrice='+maxVal ;
233
			}else{
234
			var newUrl = url[2]+'?'+sort+'&fq='+filters;
235
			}
236
		}
237
		else if(url.indexOf('sortedBy') == -1){
238
			url = spliturl(url);
239
			url = url[2];
240
			if((ominVal != minVal) || (omaxVal != maxVal)){
241
			  var newUrl = url+'?fq='+filters+'&minPrice='+minVal+'&maxPrice='+maxVal ;
242
			}else{
243
			var newUrl = url+'?fq='+filters;
244
			}
245
		}
246
		window.location.href = newUrl;
247
	}else {
248
		 if((ominVal != minVal) || (omaxVal != maxVal)){
249
	  		var url = document.URL;
250
    		if(url.indexOf('sortedBy') != -1){
251
      		var url = spliturl(url);
252
      		var sort = url[1];
253
      		sort = sort.split('&');
254
      		sort = sort[0];
255
      		var newUrl = url[2]+'?'+sort+'&minPrice='+minVal+'&maxPrice='+maxVal;
256
      		}else{
257
      		  var url = document.URL;
258
      		  url = spliturl(url);
259
	  		  var newUrl = url[2]+'?minPrice='+minVal+'&maxPrice='+maxVal;
260
	  		}
261
		}
262
		 else{
263
		 	newUrl = document.URL;
264
		 	newUrl = spliturl(newUrl);
265
		 	newUrl = newUrl.pop();
266
		 }
267
		 window.location.href = newUrl;
268
	}
269
	e.stopPropagation();
270
}
271
 
272
function clearfilter(e){
273
	 minVal = document.getElementById('exTO').innerHTML;
274
  	maxVal = document.getElementById('exFR').innerHTML;
275
	if(items.length>0){
276
	 	items.length = 0;
277
	 }
278
	var selected = document.getElementsByClassName('selected');
279
	if(selected.length >0){
280
		for (var i = 0; i < selected.length;) {
281
			selected[i].setAttribute('class','opt');
282
		}
283
		var url = document.URL;
284
		url = spliturl(url);
285
		if(document.URL.indexOf('sortedBy') == -1){
286
			// if((ominVal != minVal) || (omaxVal != maxVal)){
287
			// 	var newUrl = url[2]+'?minPrice='+minVal+'&maxPrice='+maxVal;
288
			// }
289
			// else{
290
				var newUrl = url[2];
291
				e.stopPropagation();
292
			//}
293
			window.location.href = newUrl;
294
		}
295
		else if(url[1].indexOf('sortedBy') != -1){
296
			var a = url[1].split('&');
297
			for(var i=0;i< a.length ;i++){
298
				if(a[i].indexOf('sortedBy') != -1){
299
					sort=a[i];
300
				}
301
			}
302
			// if((ominVal != minVal) || (omaxVal != maxVal)){
303
				// var newUrl = url[2]+'?'+sort+'&minPrice='+minVal+'&maxPrice='+maxVal ;
304
			// }
305
			// else{
306
				var newUrl = url[2]+'?'+sort;
307
			//}
308
			window.location.href = newUrl;
309
		}
310
	}
311
	e.stopPropagation();
312
}