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
11163 lgm 1
if((document.URL.indexOf('fq') != -1) || (document.URL.indexOf('minPrice') != -1)){
2
  document.getElementsByClassName('filter')[0].className +=' filter-selected';
3
}
4
 
5
if(document.URL.indexOf('sortedBy') != -1){
6
  document.getElementsByClassName('sort')[0].className +=' selected';
7
}
10582 lgm 8
var minVal, 
9
    maxVal;
10
 
11
var ominVal = document.getElementById('minprice').innerHTML;
12
var omaxVal = document.getElementById('maxprice').innerHTML;
13
 
14
function spliturl(url)
15
{
16
 fullpath = url.substring(0, (url.indexOf("?") == -1) ? url.length : url.indexOf("?"));
17
 params =fullpath.split('<?=base_url()?>');
18
 //console.log(params[1]);
19
 getparams = url.split('?');
20
 //console.log(getparams[1]);
21
 var output = new Array();
22
 output[0] = params[1]; //data controller to parameters
23
 output[1] = getparams[1];//get input
24
 output[2]=fullpath; //full url expcept get input
25
 console.log(output);
26
 return output;
27
}
28
var showmore;
29
var nextpageload = true;
30
function showMore(name)
31
  {
11325 lgm 32
 
10582 lgm 33
    var cpage =document.getElementById('page').innerHTML;
34
    var url = document.URL;
35
    if(!cpage){cpage=2;} else {cpage = parseInt(cpage) +1;}
36
      if(url.indexOf('sortedBy') != -1){
37
          var a = data[1].split('&');
38
          for(var i=0;i< a.length ;i++){
39
            if(a[i].indexOf('sortedBy') != -1){
40
              sort=a[i].split('=')[1];
41
              var newUrl = base_url+'search/getSearchList/'+cpage+'/'+name+'/'+sort+'/null/null';
42
            }
43
          }
44
      if(url.indexOf('fq') != -1){
45
        var filterq = new Array();
46
        var j = 0;
47
        for(var i=0;i< a.length ;i++){
48
          if(a[i].indexOf('fq') != -1){
49
            filterq[j]=a[i].split('=')[1];
50
            j++;
51
          }
52
        }
53
        filterq = filterq.join('&fq=');
54
        if(url.indexOf('minPrice') && url.indexOf('maxPrice')){
55
          var a = data[1].split('&');
56
          var price = new Array();
57
          var j=0;
58
          for(var i=0;i< a.length ;i++){
59
            if(a[i].indexOf('minPrice') != -1){
60
              price[j]=a[i].split('=')[1];
61
              j++;
62
            }
63
            if(a[i].indexOf('maxPrice') != -1){
64
              price[j]=a[i].split('=')[1];
65
              j++;
66
            }
67
          }
68
          price = price.join('&');
69
          var newUrl = base_url+'search/getSearchList/'+cpage+'/'+name+'/'+sort+'/'+encodeURIComponent(filterq)+'/'+price;
70
        }else{
71
          var newUrl = base_url+'search/getSearchList/'+cpage+'/'+name+'/'+sort+'/'+encodeURIComponent(filterq)+'/null';
72
        }
73
      }
74
      else if(url.indexOf('minPrice') != -1 && url.indexOf('maxPrice') != -1){
75
        var a = data[1].split('&');
76
        var price = new Array();
77
        var j=0;
78
        for(var i=0;i< a.length ;i++){
79
          if(a[i].indexOf('minPrice') != -1){
80
            price[j]=a[i].split('=')[1];
81
            j++;
82
          }
83
          if(a[i].indexOf('maxPrice') != -1){
84
            price[j]=a[i].split('=')[1];
85
            j++;
86
          }
87
        }
88
        price = price.join('&');
89
        var newUrl = base_url+'search/getSearchList/'+cpage+'/'+name+'/'+sort+'/null/'+price;
90
      }
91
    }
92
    else{
93
        if(url.indexOf('fq') != -1){
94
          var a = data[1].split('&');
95
          var filterq = new Array();
96
          var j = 0;
97
          for(var i=0;i< a.length ;i++){
98
            if(a[i].indexOf('fq') != -1){
99
              filterq[j]=a[i].split('=')[1];
100
              j++;
101
            }
102
          }
103
          filterq = filterq.join('&fq=');
104
          var newUrl = base_url+'search/getSearchList/'+cpage+'/'+name+'/null'+'/'+encodeURIComponent(filterq);
105
          if(url.indexOf('minPrice') != -1 && url.indexOf('maxPrice') != -1){
106
            var a = data[1].split('&');
107
            var price = new Array();
108
            var j=0;
109
            for(var i=0;i< a.length ;i++){
110
              if(a[i].indexOf('minPrice') != -1){
111
                price[j]=a[i].split('=')[1];
112
                j++;
113
              }
114
              if(a[i].indexOf('maxPrice') != -1){
115
                price[j]=a[i].split('=')[1];
116
                j++;
117
              }
118
            }
119
            price = price.join('&');
120
            var newUrl = base_url+'search/getSearchList/'+cpage+'/'+name+'/null'+'/'+encodeURIComponent(filterq)+'/'+price;
121
          }else{
122
            var newUrl = base_url+'search/getSearchList/'+cpage+'/'+name+'/null'+'/'+encodeURIComponent(filterq)+'/null';
123
          }
124
        }else if(url.indexOf('minPrice') != -1 && url.indexOf('maxPrice') != -1){
125
            var a = data[1].split('&');
126
            var price = new Array();
127
            var j=0;
128
            for(var i=0;i< a.length ;i++){
129
              if(a[i].indexOf('minPrice') != -1){
130
                price[j]=a[i].split('=')[1];
131
                j++;
132
              }
133
              if(a[i].indexOf('maxPrice') != -1){
134
                price[j]=a[i].split('=')[1];
135
                j++;
136
              }
137
            }
138
            price = price.join('&');
139
            var newUrl = base_url+'search/getSearchList/'+cpage+'/'+name+'/null/null/'+price;
140
        }
141
        else{
142
          var newUrl = base_url+'search/getSearchList/'+cpage+'/'+name+'/null'+'/null/null';
143
        }
144
      }
145
 
146
    microAjax(newUrl, function(res)
147
    {
11325 lgm 148
 
10582 lgm 149
      //console.log(res);
150
      if(res!='')
151
      {
152
        var appenddata =document.getElementById("appendlist");
153
        var total = document.getElementById('count').value;
154
        appenddata.innerHTML= appenddata.innerHTML +  res;
155
        document.getElementById('page').innerHTML =  cpage;
11710 lgm 156
        if(!isOperaMini){
157
          if (cpage % 3 == 0) {
158
            showmore = "block";
159
          } else {
160
            showmore = "none";
161
            document.getElementById("showmorebutton").style.display = "none";
162
          }
10582 lgm 163
        }
11184 lgm 164
        if (parseInt(total) <= parseInt(cpage)) {
10582 lgm 165
          showmore = 'none';
166
          nextpageload = false;
167
          document.getElementById("showmorebutton").style.display='none';
168
        }
169
        var str = document.URL;
170
        nextpageload = true;
171
        if(str.indexOf("page") !== -1){
172
        data = spliturl(str);
173
        newdata= data[1].split("&");
174
        var a = newdata.length;
175
        for(var i=0;i< a ;i++){
176
        if(newdata[i].indexOf('page') != -1){
177
        newdata[i]='page='+(parseInt(newdata[i].split('=')[1])+1)}
178
        }
179
        var url = data[2]+'?'+newdata.join("&");
180
        window.history.replaceState("",document.title, url);}
181
        else{
182
        window.history.replaceState("",document.title, window.location.href+"&page=2"); 
183
        }
184
      }
185
      else
186
      { 
187
        document.getElementById("showmorebutton").style.display='none';}
188
    });
189
 
190
  }
11710 lgm 191
var isOperaMini = (navigator.userAgent.indexOf('Opera Mini') > -1);
192
if(isOperaMini){
193
  document.getElementById("showmorebutton").style.display = "block";
194
}
10582 lgm 195
var startscroll = 0;
196
document.addEventListener("scroll", function (event) {
11006 lgm 197
  var x = (document.documentElement && document.documentElement.scrollTop) || document.body.scrollTop;
10582 lgm 198
      var maxY = document.documentElement.scrollHeight - document.documentElement.clientHeight;
199
        // when user reaches end of the page
200
 
201
        if(x>startscroll)
202
        {
203
          startscroll = x;
204
        }
205
        else if(maxY==x)
206
        {
207
            startscroll=0;
208
            window.scrollTo(0,0);
209
            return false;
210
        }
211
        else
212
        {
213
 
214
          return false;
215
        }
216
    if (getDocHeight() <= getScrollXY()[1] + window.innerHeight + 300) {
11325 lgm 217
 
10582 lgm 218
      if(((document.getElementById('page').innerHTML%3) != 0) && nextpageload==true){
11325 lgm 219
 
10582 lgm 220
        //console.log(x);
221
        //console.log(getScrollXY()[1] + window.innerHeight + 300);
222
        total = document.getElementById('count').value;
223
        cpage = document.getElementById('page').innerHTML;
224
        nextpageload=false;
225
        data = spliturl(document.URL);
226
        var a = data[1].split('&');
227
          for(var i=0;i< a.length ;i++){
228
            if(a[i].indexOf('q') != -1){
229
              newdata=a[i].split('=');
230
              break;
231
            }
232
          }
11184 lgm 233
          if(parseInt(total) <= parseInt(cpage)) {
10582 lgm 234
            showmore = 'none';
235
            nextpageload = false;
236
          }else{
237
          showMore(decodeURIComponent(newdata[1]));}
238
        }
239
      else{
240
        if(showmore === 'block'){
241
          document.getElementById('showmorebutton').style.display = 'block';
242
        }     
243
      }
244
    }
245
});
246
function toggleListview(e){
247
 
248
  var a = document.getElementsByClassName('pd-list-hldr')[0];
249
  if(a.className == 'pd-list-hldr clearfix'){
250
  a.className += ' grid';
251
  e.currentTarget.className = 'list-icon';
252
  }else{
253
    a.className = 'pd-list-hldr clearfix';
254
    e.currentTarget.className = '';
255
  }
256
 
257
}
258
 
259
function fireSort(e){
11325 lgm 260
 
10582 lgm 261
  var attrval = e.target.getAttribute('data-val');
262
  //var path = window.location.pathname;
263
  var path = document.URL;
264
  if(path.indexOf('fq') != -1){
265
    if(path.indexOf('sortedBy') == -1){
266
    window.location = document.URL.split('?')[0]+'?sortedBy='+attrval+'&'+document.URL.split('?').pop();
267
    }else{
268
      var npath = document.URL.split('?')[1].split('&');
269
      npath.slice(1);
270
      window.location = document.URL.split('?')[0]+'?sortedBy='+attrval+'&' +npath.slice(1).join('&');;
271
    }
272
  }else{
273
  var val = path.split("&sortedBy=")[0];
274
  //var npath = path.split('?')[0];
275
  window.location = val+'&sortedBy='+attrval;
276
  }
277
}
278
 
279
var fq = new Array();
280
var i=0;
281
 
282
function filter(e){
11325 lgm 283
 
10582 lgm 284
  var id = e.currentTarget;
285
  var key = id.getAttribute('data-key');
286
  var value = id.getAttribute('data-value');
287
 
288
  if(e.currentTarget.className != 'opt selected'){
289
    e.currentTarget.className += ' selected' ;
290
    fq[i] = (key+':'+value);
291
    i++;
292
  }else{
293
    e.currentTarget.className = 'opt';
294
    var ind = fq.indexOf(key+':'+value);
295
    fq.splice(ind,1);
296
  }
297
  e.stopPropagation();
298
}
299
 
300
function applyFilter(e){
11325 lgm 301
 
10582 lgm 302
  minVal = document.getElementById('exTO').innerHTML;
303
  maxVal = document.getElementById('exFR').innerHTML;
304
  if(items.length > 0){
305
    for(j=0;j<items.length;j++){
306
      if(document.getElementById(items[j]).className == 'opt selected'){
307
        var name = document.getElementById(items[j]);
308
        name = name.getAttribute('data-key')+':'+name.getAttribute('data-value');
309
        fq[i] = name;
310
        i++;
311
      }
312
    }
313
  }
314
  if(fq.length > 0){
315
    var filters = fq.join('&fq=');
316
    var url = document.URL;
317
    if(url.indexOf('sortedBy') != -1){
318
      var url = spliturl(url);
319
      url = url[1];
320
      url = url.split('&');
321
      for(i=0;i<url.length;i++){
322
        if(url[i].indexOf('q') != -1){
323
          var query = url[i];
324
          break;
325
        }
326
      }
327
      for(i=0;i<url.length;i++){
328
        if(url[i].indexOf('sortedBy') != -1){
329
          var sort = url[i];
330
          if((ominVal != minVal) || (omaxVal != maxVal)){
331
            var newUrl = base_url+'search?'+sort+'&'+query+'&minPrice='+minVal+'&maxPrice='+maxVal ;
332
          }else{
333
             var newUrl = base_url+'search?'+sort+'&'+query;
334
          }
335
        }
336
      }
337
       newUrl = newUrl+'&fq='+filters;
338
    }
339
    else{
340
      url = spliturl(url);
341
      query = url[1];
342
      if((ominVal != minVal) || (omaxVal != maxVal)){
343
            var newUrl = base_url+'search?'+sort+'&'+query+'&minPrice='+minVal+'&maxPrice='+maxVal+'&fq='+encodeURIComponent(filters);
344
          }else{
345
             var newUrl = base_url+'search?'+query+'&fq='+encodeURIComponent(filters);
346
          }
347
    }
348
    window.location.href = newUrl;
349
  }else{ 
350
    if((ominVal != minVal) || (omaxVal != maxVal)){
351
      var url = document.URL;
352
      var query = spliturl(url);
353
      query = query[1];
354
      query = query.split('&');
355
      for(i=0;i<query.length;i++){
356
        if(query[i].indexOf('q') != -1){
357
          query = query[i];
358
          break;
359
          }
360
        }
361
      if(url.indexOf('sortedBy') != -1){
362
        var url = spliturl(url);
363
        var sort = url[1];
364
        sort = sort.split('&');
365
        sort = sort[0];
366
        var newUrl = url[2]+'?'+sort+'&'+query+'&minPrice='+minVal+'&maxPrice='+maxVal;
367
      }else{
368
        var url = spliturl(url);
369
        var sort = url[1];
370
        var newUrl = url[2]+'?'+query+'&minPrice='+minVal+'&maxPrice='+maxVal;
371
      }
372
    }
373
    else{
374
      newUrl = document.URL;
375
     }
376
    window.location.href = newUrl;
377
  }
378
  e.stopPropagation();
379
 
380
}
381
 
382
function clearfilter(e){
11325 lgm 383
 
10582 lgm 384
  if(items.length>0){
385
    items.length = 0;
386
   }
387
  var selected = document.getElementsByClassName('selected');
388
  if(selected.length >0){
389
    for (var i = 0; i < selected.length;) {
390
      selected[i].setAttribute('class','');
391
    }
392
    var url = document.URL;
393
    url = spliturl(url);
394
    if(url[1].indexOf('sortedBy') == -1){
395
      var a = url[1].split('&');
396
      for(var i=0;i< a.length ;i++){
397
        if(a[i].indexOf('q') != -1){
398
          q=a[i];
399
          break;
400
        }
401
      }
402
      window.location.href = url[2]+'?'+q;
403
    }
404
    else if(url[1].indexOf('sortedBy') != -1){
405
      var a = url[1].split('&');
406
      for(var i=0;i< a.length ;i++){
407
        if(a[i].indexOf('sortedBy') != -1){
408
          sort=a[i];
409
        }
410
      }
411
      for(var i=0;i< a.length ;i++){
412
        if(a[i].indexOf('q') != -1){
413
          q=a[i];
414
          break;
415
        }
416
      }
417
      window.location.href = url[2]+'?'+q+'&'+sort;
418
    }
419
  }
420
  e.stopPropagation();
421
}
422
 
423