Subversion Repositories SmartDukaan

Rev

Rev 11719 | Blame | Compare with Previous | Last modification | View Log | RSS feed

var pheight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
if(document.getElementById('appendlist') != undefined){
    document.getElementById('appendlist').style.minHeight = pheight - 216 +'px';  
}


if(document.getElementsByClassName('cart-cont')[0] != undefined){
 document.getElementsByClassName('cart-cont')[0].style.minHeight = (screen.height - 235) +'px'; 
}

if((document.URL.indexOf('fq') != -1) || (document.URL.indexOf('minPrice') != -1)){
  document.getElementsByClassName('filter')[0].className +=' filter-selected';
}

if(document.URL.indexOf('sortedBy') != -1){
  document.getElementsByClassName('sort')[0].className +=' selected';
}

var minVal, 
    maxVal;
    
var ominVal = document.getElementById('minprice').innerHTML;
var omaxVal = document.getElementById('maxprice').innerHTML;
  
function spliturl(url)
{
 fullpath = url.substring(0, (url.indexOf("?") == -1) ? url.length : url.indexOf("?"));
 params =fullpath.split('<?=base_url()?>');
 getparams = url.split('?');
 var output = new Array();
 output[0] = params[1]; //data controller to parameters
 output[1] = getparams[1];//get input
 output[2]=fullpath; //full url expcept get input
 return output;
}
var showmore;
var nextpageload = true;
function showMoreProducts()
        {
                var cpage =document.getElementById('page').innerHTML;
                var url = document.URL;
                if(!cpage){cpage=2;} else {cpage = parseInt(cpage) +1;}
                var data = spliturl(document.URL);
                var cat = data[2].split('/');
                cat = cat.pop();
                if(url.indexOf('sortedBy') != -1){
                        var a = data[1].split('&');
                        for(var i=0;i< a.length ;i++){
                                if(a[i].indexOf('sortedBy') != -1){
                                        sort=a[i].split('=')[1];
                                        var newUrl = base_url+'products/getProductList/'+cat+'/'+cpage+'/'+sort+'/null/null';
                                }
                        }
                        if(url.indexOf('fq') != -1){
                                var filterq = new Array();
                                var j = 0;
                                for(var i=0;i< a.length ;i++){
                                        if(a[i].indexOf('fq') != -1){
                                                filterq[j]=a[i].split('=')[1];
                                                j++;
                                        }
                                }
                                filterq = filterq.join('&fq=');
                                if(url.indexOf('minPrice') != -1 && url.indexOf('maxPrice') != -1){
                                        var a = data[1].split('&');
                                        var price = new Array();
                                        var j=0;
                                        for(var i=0;i< a.length ;i++){
                                                if(a[i].indexOf('minPrice') != -1){
                                                        price[j]=a[i].split('=')[1];
                                                        j++;
                                                }
                                                if(a[i].indexOf('maxPrice') != -1){
                                                        price[j]=a[i].split('=')[1];
                                                        j++;
                                                }
                                        }
                                        price = price.join('&');
                                        var newUrl = base_url+'products/getProductList/'+cat+'/'+cpage+'/'+sort+'/'+encodeURIComponent(filterq)+'/'+price;
                                }else{
                                        var newUrl = base_url+'products/getProductList/'+cat+'/'+cpage+'/'+sort+'/'+encodeURIComponent(filterq)+'/null';
                                }
                        }
                        else if(url.indexOf('minPrice') != -1 && url.indexOf('maxPrice') != -1){
                                var a = data[1].split('&');
                                var price = new Array();
                                var j=0;
                                for(var i=0;i< a.length ;i++){
                                        if(a[i].indexOf('minPrice') != -1){
                                                price[j]=a[i].split('=')[1];
                                                j++;
                                        }
                                        if(a[i].indexOf('maxPrice') != -1){
                                                price[j]=a[i].split('=')[1];
                                                j++;
                                        }
                                }
                                price = price.join('&');
                                var newUrl = base_url+'products/getProductList/'+cat+'/'+cpage+'/'+sort+'/null/'+price;
                        }
                }
                else{
                        if(url.indexOf('fq') != -1){
                                var a = data[1].split('&');
                                var filterq = new Array();
                                var j = 0;
                                for(var i=0;i< a.length ;i++){
                                        if(a[i].indexOf('fq') != -1){
                                                filterq[j]=a[i].split('=')[1];
                                                j++;
                                        }
                                }
                                filterq = filterq.join('&fq=');
                                if(url.indexOf('minPrice') != -1 && url.indexOf('maxPrice') != -1){
                                        var a = data[1].split('&');
                                        var price = new Array();
                                        var j=0;
                                        for(var i=0;i< a.length ;i++){
                                                if(a[i].indexOf('minPrice') != -1){
                                                        price[j]=a[i].split('=')[1];
                                                        j++;
                                                }
                                                if(a[i].indexOf('maxPrice') != -1){
                                                        price[j]=a[i].split('=')[1];
                                                        j++;
                                                }
                                        }
                                        price = price.join('&');
                                        var newUrl = base_url+'products/getProductList/'+cat+'/'+cpage+'/null'+'/'+encodeURIComponent(filterq)+'/'+price;
                                }else{
                                        var newUrl = base_url+'products/getProductList/'+cat+'/'+cpage+'/null'+'/'+encodeURIComponent(filterq)+'/null';
                                }
                        }else if(url.indexOf('minPrice') != -1 && url.indexOf('maxPrice') != -1){
                                var a = data[1].split('&');
                                var price = new Array();
                                var j=0;
                                for(var i=0;i< a.length ;i++){
                                        if(a[i].indexOf('minPrice') != -1){
                                                price[j]=a[i].split('=')[1];
                                                j++;
                                        }
                                        if(a[i].indexOf('maxPrice') != -1){
                                                price[j]=a[i].split('=')[1];
                                                j++;
                                        }
                                }
                                price = price.join('&');
                                var newUrl = base_url+'products/getProductList/'+cat+'/'+cpage+'/null'+'/null/'+price;
                        }
                        else{
                                var newUrl = base_url+'products/getProductList/'+cat+'/'+cpage+'/null'+'/null/null';
                        }
                }
                microAjax(newUrl, function(res)
                {
                        if(res!='')
                        {
                                var appenddata =document.getElementById("appendlist");
                                var total = document.getElementById('count').value;
                                appenddata.innerHTML= appenddata.innerHTML +  res;
                                document.getElementById('page').innerHTML =  cpage;
                                if(!isOperaMini){
                                if (cpage % 3 == 0) {
                                  showmore = "block";
                                } else {
                                  showmore = "none";
                                  document.getElementById("showmorebutton").style.display = "none";
                                }
                                }
                                if (parseInt(total) <= parseInt(cpage)) {
                                        showmore = 'none';
                                        nextpageload = false;
                                        document.getElementById("showmorebutton").style.display='none';
                                }
                                var str = document.URL;
                                nextpageload = true;
                                if(str.indexOf("page") !== -1){
                                data = spliturl(str);
                                newdata= data[1].split("&");
                                var a = newdata.length;
                                for(var i=0;i< a ;i++){
                                if(newdata[i].indexOf('page') != -1){
                                  newdata[i]='page='+(parseInt(newdata[i].split('=')[1])+1);
                                  }
                                }
                                var url = data[2]+'?'+newdata.join("&");
                                window.history.replaceState("",document.title, url);}
                                else{
                                        if(str.indexOf('sortedBy') != -1 || str.indexOf('fq') != -1 || str.indexOf('minPrice') != -1){
                                                window.history.replaceState("",document.title, window.location.href+"&page=2");         
                                        }
                                        else{
                                                window.history.replaceState("",document.title, window.location.href+"?page=2");
                                        }       
                                }
                        }
                        else
                        {       addCookie('shopMoreUrl' , window.location.href, 1);
                                document.getElementById("showmorebutton").style.display='none';}
                });

        }

var isOperaMini = (navigator.userAgent.indexOf('Opera Mini') > -1);
if(isOperaMini){
  total = document.getElementById('count').value;
  cpage = document.getElementById('page').innerHTML;
  if (parseInt(total) <= parseInt(cpage)) {
        document.getElementById("showmorebutton").style.display = "none";
  }else{
        document.getElementById("showmorebutton").style.display = "block";
  }
}
var startscroll = 0;
var ua = navigator.userAgent.toLowerCase();
document.addEventListener("scroll", function (event) {
if(document.getElementsByClassName('refine-mask')[0].style.display == 'none' || document.getElementsByClassName('refine-mask')[0].style.display == ''){  
        var x = (document.documentElement && document.documentElement.scrollTop) || document.body.scrollTop;  
        var maxY = document.documentElement.scrollHeight - document.documentElement.clientHeight;
                // when user reaches end of the page
                if(x>startscroll)
                {
                        startscroll = x;
                }
                else if(maxY==x)
                {
                                startscroll=0;
                                window.scrollTo(0,0);
                                return false;
                }
                else
                {
                        
                        return false;
                }
    if (getDocHeight() <= getScrollXY()[1] + window.innerHeight + 300) {
        if(((document.getElementById('page').innerHTML%3) != 0) && nextpageload==true){
                total = document.getElementById('count').value;
                cpage = document.getElementById('page').innerHTML;
                nextpageload=false;
                if (parseInt(total) <= parseInt(cpage)) {
            showmore = 'none';
            nextpageload = false;
                }else{
                        showMoreProducts();}
                }
                else{
                        if(showmore === 'block'){
                                document.getElementById('showmorebutton').style.display = 'block';
                        }               
                }
        }
}});
function toggleListview(e){
  
  var a = document.getElementsByClassName('pd-list-hldr')[0];
  if(a.className == 'pd-list-hldr clearfix'){
  a.className += ' grid';
  e.currentTarget.className = 'list-icon';
  }else{
    a.className = 'pd-list-hldr clearfix';
    e.currentTarget.className = '';
  }
  
}

function fireSort(e){
  var attrval = e.target.getAttribute('data-val');
  //var path = window.location.pathname;
  var path = document.URL;
  if((path.indexOf('fq') != -1) || (path.indexOf('minPrice') != -1)){
    if(path.indexOf('sortedBy') == -1){
    window.location = document.URL.split('?')[0]+'?sortedBy='+attrval+'&'+document.URL.split('?').pop();
    }else{
      var npath = document.URL.split('?')[1].split('&');
      npath.slice(1);
      window.location = document.URL.split('?')[0]+'?sortedBy='+attrval+'&' +npath.slice(1).join('&');;
    }
  }else{
  //var val = path.split("/").pop();
  var npath = path.split('?')[0];
  window.location = npath+'?sortedBy='+attrval;
  }
}



var fq = new Array();
var i=0;

function filter(e){
        
        var id = e.currentTarget;
        var key = id.getAttribute('data-key');
        var value = id.getAttribute('data-value');
        
        if(e.currentTarget.className != 'opt selected'){
    e.currentTarget.className += ' selected' ;
    fq[i] = (key+':'+value);
    i++;
  }else{
    e.currentTarget.className = 'opt';
    var ind = fq.indexOf(key+':'+value);
    if(ind != -1){
        fq.splice(ind,1);
        i--;
    }
    var itemStore = items.indexOf(value);
    if(itemStore != -1){
        items.splice(itemStore,1);
    }
  }
  e.stopPropagation();
}

function applyFilter(e){
  
  minVal = document.getElementById('exTO').innerHTML;
  maxVal = document.getElementById('exFR').innerHTML;
        if(items.length > 0){
                
                for(j=0;j<items.length;j++){
                        if(document.getElementById(items[j]).className == 'opt selected'){
                                var name = document.getElementById(items[j]);
                                name = name.getAttribute('data-key')+':'+name.getAttribute('data-value');
                                fq[i] = name;
                                i++;
                        }
                }
        }
        if(fq.length > 0){
                var filters = fq.join('&fq=');
                var url = document.URL;
                if(url.indexOf('sortedBy') != -1){
                        var url = spliturl(url);
                        var sort = url[1];
                        sort = sort.split('&');
                        sort = sort[0];
                        if((ominVal != minVal) || (omaxVal != maxVal)){
                          var newUrl = url[2]+'?'+sort+'&fq='+filters+'&minPrice='+minVal+'&maxPrice='+maxVal ;
                        }else{
                        var newUrl = url[2]+'?'+sort+'&fq='+filters;
                        }
                }
                else if(url.indexOf('sortedBy') == -1){
                        url = spliturl(url);
                        url = url[2];
                        if((ominVal != minVal) || (omaxVal != maxVal)){
                          var newUrl = url+'?fq='+filters+'&minPrice='+minVal+'&maxPrice='+maxVal ;
                        }else{
                        var newUrl = url+'?fq='+filters;
                        }
                }
                window.location.href = newUrl;
        }else {
                 if((ominVal != minVal) || (omaxVal != maxVal)){
                        var url = document.URL;
                if(url.indexOf('sortedBy') != -1){
                var url = spliturl(url);
                var sort = url[1];
                sort = sort.split('&');
                sort = sort[0];
                var newUrl = url[2]+'?'+sort+'&minPrice='+minVal+'&maxPrice='+maxVal;
                }else{
                  var url = document.URL;
                  url = spliturl(url);
                          var newUrl = url[2]+'?minPrice='+minVal+'&maxPrice='+maxVal;
                        }
                }
                 else{
                        newUrl = document.URL;
                        newUrl = spliturl(newUrl);
                        newUrl = newUrl.pop();
                 }
                 window.location.href = newUrl;
        }
        e.stopPropagation();
}

function clearfilter(e){
         minVal = document.getElementById('exTO').innerHTML;
        maxVal = document.getElementById('exFR').innerHTML;
        if(items.length>0){
                items.length = 0;
         }
        var selected = document.getElementsByClassName('selected');
        if(selected.length >0){
                for (var i = 0; i < selected.length;) {
                        selected[i].setAttribute('class','opt');
                }
                var url = document.URL;
                url = spliturl(url);
                if(document.URL.indexOf('sortedBy') == -1){
                        // if((ominVal != minVal) || (omaxVal != maxVal)){
                        //      var newUrl = url[2]+'?minPrice='+minVal+'&maxPrice='+maxVal;
                        // }
                        // else{
                                var newUrl = url[2];
                                e.stopPropagation();
                        //}
                        window.location.href = newUrl;
                }
                else if(url[1].indexOf('sortedBy') != -1){
                        var a = url[1].split('&');
                        for(var i=0;i< a.length ;i++){
                                if(a[i].indexOf('sortedBy') != -1){
                                        sort=a[i];
                                }
                        }
                        // if((ominVal != minVal) || (omaxVal != maxVal)){
                                // var newUrl = url[2]+'?'+sort+'&minPrice='+minVal+'&maxPrice='+maxVal ;
                        // }
                        // else{
                                var newUrl = url[2]+'?'+sort;
                        //}
                        window.location.href = newUrl;
                }
        }
        e.stopPropagation();
}