Subversion Repositories SmartDukaan

Rev

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