Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

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