Subversion Repositories SmartDukaan

Rev

Rev 11006 | Rev 11184 | 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
  {
32
    debugger;
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
    {
148
      debugger;
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;
156
        if(cpage % 3 ==0){
157
          showmore = 'block';
158
        }
159
        else{
160
          showmore = 'none';
161
          document.getElementById("showmorebutton").style.display='none';
162
        }
163
        if (total <= cpage) {
164
          showmore = 'none';
165
          nextpageload = false;
166
          document.getElementById("showmorebutton").style.display='none';
167
        }
168
        var str = document.URL;
169
        nextpageload = true;
170
        if(str.indexOf("page") !== -1){
171
        data = spliturl(str);
172
        newdata= data[1].split("&");
173
        var a = newdata.length;
174
        for(var i=0;i< a ;i++){
175
        if(newdata[i].indexOf('page') != -1){
176
        newdata[i]='page='+(parseInt(newdata[i].split('=')[1])+1)}
177
        }
178
        var url = data[2]+'?'+newdata.join("&");
179
        window.history.replaceState("",document.title, url);}
180
        else{
181
        window.history.replaceState("",document.title, window.location.href+"&page=2"); 
182
        }
183
      }
184
      else
185
      { 
186
        document.getElementById("showmorebutton").style.display='none';}
187
    });
188
 
189
  }
190
 
191
var startscroll = 0;
192
document.addEventListener("scroll", function (event) {
11006 lgm 193
  var x = (document.documentElement && document.documentElement.scrollTop) || document.body.scrollTop;
10582 lgm 194
      var maxY = document.documentElement.scrollHeight - document.documentElement.clientHeight;
195
        // when user reaches end of the page
196
 
197
        if(x>startscroll)
198
        {
199
          startscroll = x;
200
        }
201
        else if(maxY==x)
202
        {
203
            startscroll=0;
204
            window.scrollTo(0,0);
205
            return false;
206
        }
207
        else
208
        {
209
 
210
          return false;
211
        }
212
    if (getDocHeight() <= getScrollXY()[1] + window.innerHeight + 300) {
213
      debugger;
214
      if(((document.getElementById('page').innerHTML%3) != 0) && nextpageload==true){
215
        debugger;
216
        //console.log(x);
217
        //console.log(getScrollXY()[1] + window.innerHeight + 300);
218
        total = document.getElementById('count').value;
219
        cpage = document.getElementById('page').innerHTML;
220
        nextpageload=false;
221
        data = spliturl(document.URL);
222
        var a = data[1].split('&');
223
          for(var i=0;i< a.length ;i++){
224
            if(a[i].indexOf('q') != -1){
225
              newdata=a[i].split('=');
226
              break;
227
            }
228
          }
229
          if (total <= cpage) {
230
            showmore = 'none';
231
            nextpageload = false;
232
          }else{
233
          showMore(decodeURIComponent(newdata[1]));}
234
        }
235
      else{
236
        if(showmore === 'block'){
237
          document.getElementById('showmorebutton').style.display = 'block';
238
        }     
239
      }
240
    }
241
});
242
function toggleListview(e){
243
 
244
  var a = document.getElementsByClassName('pd-list-hldr')[0];
245
  if(a.className == 'pd-list-hldr clearfix'){
246
  a.className += ' grid';
247
  e.currentTarget.className = 'list-icon';
248
  }else{
249
    a.className = 'pd-list-hldr clearfix';
250
    e.currentTarget.className = '';
251
  }
252
 
253
}
254
 
255
function fireSort(e){
256
  debugger;
257
  var attrval = e.target.getAttribute('data-val');
258
  //var path = window.location.pathname;
259
  var path = document.URL;
260
  if(path.indexOf('fq') != -1){
261
    if(path.indexOf('sortedBy') == -1){
262
    window.location = document.URL.split('?')[0]+'?sortedBy='+attrval+'&'+document.URL.split('?').pop();
263
    }else{
264
      var npath = document.URL.split('?')[1].split('&');
265
      npath.slice(1);
266
      window.location = document.URL.split('?')[0]+'?sortedBy='+attrval+'&' +npath.slice(1).join('&');;
267
    }
268
  }else{
269
  var val = path.split("&sortedBy=")[0];
270
  //var npath = path.split('?')[0];
271
  window.location = val+'&sortedBy='+attrval;
272
  }
273
}
274
 
275
var fq = new Array();
276
var i=0;
277
 
278
function filter(e){
279
  debugger;
280
  var id = e.currentTarget;
281
  var key = id.getAttribute('data-key');
282
  var value = id.getAttribute('data-value');
283
 
284
  if(e.currentTarget.className != 'opt selected'){
285
    e.currentTarget.className += ' selected' ;
286
    fq[i] = (key+':'+value);
287
    i++;
288
  }else{
289
    e.currentTarget.className = 'opt';
290
    var ind = fq.indexOf(key+':'+value);
291
    fq.splice(ind,1);
292
  }
293
  e.stopPropagation();
294
}
295
 
296
function applyFilter(e){
297
  debugger;
298
  minVal = document.getElementById('exTO').innerHTML;
299
  maxVal = document.getElementById('exFR').innerHTML;
300
  if(items.length > 0){
301
    for(j=0;j<items.length;j++){
302
      if(document.getElementById(items[j]).className == 'opt selected'){
303
        var name = document.getElementById(items[j]);
304
        name = name.getAttribute('data-key')+':'+name.getAttribute('data-value');
305
        fq[i] = name;
306
        i++;
307
      }
308
    }
309
  }
310
  if(fq.length > 0){
311
    var filters = fq.join('&fq=');
312
    var url = document.URL;
313
    if(url.indexOf('sortedBy') != -1){
314
      var url = spliturl(url);
315
      url = url[1];
316
      url = url.split('&');
317
      for(i=0;i<url.length;i++){
318
        if(url[i].indexOf('q') != -1){
319
          var query = url[i];
320
          break;
321
        }
322
      }
323
      for(i=0;i<url.length;i++){
324
        if(url[i].indexOf('sortedBy') != -1){
325
          var sort = url[i];
326
          if((ominVal != minVal) || (omaxVal != maxVal)){
327
            var newUrl = base_url+'search?'+sort+'&'+query+'&minPrice='+minVal+'&maxPrice='+maxVal ;
328
          }else{
329
             var newUrl = base_url+'search?'+sort+'&'+query;
330
          }
331
        }
332
      }
333
       newUrl = newUrl+'&fq='+filters;
334
    }
335
    else{
336
      url = spliturl(url);
337
      query = url[1];
338
      if((ominVal != minVal) || (omaxVal != maxVal)){
339
            var newUrl = base_url+'search?'+sort+'&'+query+'&minPrice='+minVal+'&maxPrice='+maxVal+'&fq='+encodeURIComponent(filters);
340
          }else{
341
             var newUrl = base_url+'search?'+query+'&fq='+encodeURIComponent(filters);
342
          }
343
    }
344
    window.location.href = newUrl;
345
  }else{ 
346
    if((ominVal != minVal) || (omaxVal != maxVal)){
347
      var url = document.URL;
348
      var query = spliturl(url);
349
      query = query[1];
350
      query = query.split('&');
351
      for(i=0;i<query.length;i++){
352
        if(query[i].indexOf('q') != -1){
353
          query = query[i];
354
          break;
355
          }
356
        }
357
      if(url.indexOf('sortedBy') != -1){
358
        var url = spliturl(url);
359
        var sort = url[1];
360
        sort = sort.split('&');
361
        sort = sort[0];
362
        var newUrl = url[2]+'?'+sort+'&'+query+'&minPrice='+minVal+'&maxPrice='+maxVal;
363
      }else{
364
        var url = spliturl(url);
365
        var sort = url[1];
366
        var newUrl = url[2]+'?'+query+'&minPrice='+minVal+'&maxPrice='+maxVal;
367
      }
368
    }
369
    else{
370
      newUrl = document.URL;
371
     }
372
    window.location.href = newUrl;
373
  }
374
  e.stopPropagation();
375
 
376
}
377
 
378
function clearfilter(e){
379
  debugger;
380
  if(items.length>0){
381
    items.length = 0;
382
   }
383
  var selected = document.getElementsByClassName('selected');
384
  if(selected.length >0){
385
    for (var i = 0; i < selected.length;) {
386
      selected[i].setAttribute('class','');
387
    }
388
    var url = document.URL;
389
    url = spliturl(url);
390
    if(url[1].indexOf('sortedBy') == -1){
391
      var a = url[1].split('&');
392
      for(var i=0;i< a.length ;i++){
393
        if(a[i].indexOf('q') != -1){
394
          q=a[i];
395
          break;
396
        }
397
      }
398
      window.location.href = url[2]+'?'+q;
399
    }
400
    else if(url[1].indexOf('sortedBy') != -1){
401
      var a = url[1].split('&');
402
      for(var i=0;i< a.length ;i++){
403
        if(a[i].indexOf('sortedBy') != -1){
404
          sort=a[i];
405
        }
406
      }
407
      for(var i=0;i< a.length ;i++){
408
        if(a[i].indexOf('q') != -1){
409
          q=a[i];
410
          break;
411
        }
412
      }
413
      window.location.href = url[2]+'?'+q+'&'+sort;
414
    }
415
  }
416
  e.stopPropagation();
417
}
418
 
419