Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
10582 lgm 1
function toggleListview(e){
2
 
3
  var a = document.getElementsByClassName('pd-list-hldr')[0];
4
  if(a.className == 'pd-list-hldr clearfix'){
5
  a.className += ' grid';
6
  e.currentTarget.className = 'list-icon';
7
  }else{
8
    a.className = 'pd-list-hldr clearfix';
9
    e.currentTarget.className = '';
10
  }
11
 
12
}
13
var showmore;
14
var nextpageload = true;
15
function showMoreProducts()
16
	{
11325 lgm 17
 
10582 lgm 18
		var cpage =document.getElementById('page').innerHTML;
19
		var url = document.URL;
20
		if(!cpage){cpage=2;} else {cpage = parseInt(cpage) +1;}
21
		var data = spliturl(document.URL);
22
		var cat = data[2].split('/');
23
		cat = cat[cat.length-2];
24
		var newUrl = base_url+'products/getSpecialProductList/'+cat+'/'+cpage;
25
		microAjax(newUrl, function(res)
26
		{
11325 lgm 27
 
10582 lgm 28
			if(res!='')
29
			{
30
				var appenddata =document.getElementById("appendlist");
31
				var total = document.getElementById('count').value;
32
				appenddata.innerHTML= appenddata.innerHTML +  res;
33
				document.getElementById('page').innerHTML =  cpage;
11710 lgm 34
				if(!isOperaMini){
35
		          if (cpage % 3 == 0) {
36
		            showmore = "block";
37
		          } else {
38
		            showmore = "none";
39
		            document.getElementById("showmorebutton").style.display = "none";
40
		          }
41
		        }
10582 lgm 42
				if (parseInt(total) <= parseInt(cpage)) {
43
					showmore = 'none';
44
					nextpageload = false;
45
					document.getElementById("showmorebutton").style.display='none';
46
				}
47
				var str = document.URL;
48
				nextpageload = true;
49
				if(str.indexOf("page") !== -1){
11325 lgm 50
 
10582 lgm 51
				data = spliturl(str);
52
				newdata= data[1].split("&");
53
				var a = newdata.length;
54
				for(var i=0;i< a ;i++){
55
				if(newdata[i].indexOf('page') != -1){
56
				  newdata[i]='page='+(parseInt(newdata[i].split('=')[1])+1);
57
				  }
58
				}
59
				var url = data[2]+'?'+newdata.join("&");
60
				window.history.replaceState("",document.title, url);}
61
				else{
62
					if(str.indexOf('sortedBy') != -1 || str.indexOf('fq') != -1 || str.indexOf('minPrice') != -1){
63
						window.history.replaceState("",document.title, window.location.href+"&page=2");		
64
					}
65
					else{
66
						window.history.replaceState("",document.title, window.location.href+"?page=2");
67
					}	
68
				}
69
			}
70
			else
71
			{	
72
				document.getElementById("showmorebutton").style.display='none';}
73
		});
74
 
75
	}
11710 lgm 76
var isOperaMini = (navigator.userAgent.indexOf('Opera Mini') > -1);
77
if(isOperaMini){
78
  document.getElementById("showmorebutton").style.display = "block";
79
}
10582 lgm 80
var startscroll = 0;
10785 lgm 81
document.addEventListener("scroll", function (event) { 
10582 lgm 82
	var x = document.body.scrollTop;  
83
    	var maxY = document.documentElement.scrollHeight - document.documentElement.clientHeight;
84
    		// when user reaches end of the page
85
    		if(x>startscroll)
86
    		{
87
    			startscroll = x;
88
    		}
89
    		else if(maxY==x)
90
    		{
91
    				startscroll=0;
92
    				window.scrollTo(0,0);
93
    				return false;
94
    		}
95
    		else
96
    		{
97
 
98
    			return false;
99
    		}
100
    if (getDocHeight() <= getScrollXY()[1] + window.innerHeight + 300) {
11325 lgm 101
 
10582 lgm 102
    	if(((document.getElementById('page').innerHTML%3) != 0) && nextpageload==true){
103
    		//console.log(x);
104
    		total = document.getElementById('count').value;
105
        	cpage = document.getElementById('page').innerHTML;
106
        	nextpageload=false;
107
    		if (parseInt(total) <= parseInt(cpage)) {
108
            showmore = 'none';
109
            nextpageload = false;
110
          	}else{
111
          		showMoreProducts();}
112
        	}
113
      		else{
114
    			if(showmore === 'block'){
115
    				document.getElementById('showmorebutton').style.display = 'block';
116
    			} 		
117
    		}
118
    	}
10785 lgm 119
});