-
Notifications
You must be signed in to change notification settings - Fork 9
/
flipkart_seller_filter.js
83 lines (75 loc) · 3.09 KB
/
flipkart_seller_filter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
(function(){
function init(){
$(document).ready(function(){
if($('#browse-filter').length){
$('#facetList').append( '<div class="oneFacet">'+
'<div class="facetContainer">'+
'<div class="head line fk-uppercase">'+
'<div class="facet-title" title="Click to Collapse">'+
'<h2 class="unit line fk-font-15">Seller Filter</h2>'+
'</div>'+
'</div>'+
'<div id="sellerfilter">'+
'<input id="txtSellerFilter" type="text" style="width:100px;margin-right:10px;"/>'+
'<input id="btnSellerFilter" type="button" style="width:50px;" value="Filter" onclick="javascript:"/>'+
'</div>'+
'<div class="clearfix"></div>'+
'</div>'+
'</div>');
} else {
console.log('filter not found');
}
bindEvents();
});
}
function bindEvents(){
$('#btnSellerFilter').click(function(){
filter($('#txtSellerFilter').val());
});
}
function filter(seller){
var ajaxPool = [];
var ongoing = [];
$('.product-unit').find('.fk-product-thumb').each(function(){
var $self = $(this);
var href = $self.attr('href');
var data = {};
$self.css('opacity','0.5');
var ajaxIndex = ajaxPool;
var ajaxOptions = {
url: href,
type: "GET",
dataType: "html",
data: data,
success: function(resp){
ajaxPool[ajaxIndex] = false;
if($(resp).find('.seller-badge .seller-name').text().toLowerCase() == seller.toLowerCase()){
$self.css('opacity','1.0');
} else {
$self.css('opacity','0.1');
}
fireNextAjax();
},
error: function(){
ongoing[ajaxIndex] = false;
fireNextAjax();
}
};
ajaxPool.push(ajaxOptions);
});
for(var i=0;i<10;i+=1){
ongoing[i] = true;
$.ajax(ajaxPool[i]);
}
function fireNextAjax(){
for(var i=0;i<ajaxPool.length;i+=1){
if(!ongoing[i] && ajaxPool[i]){
ongoing[i] = true;
$.ajax(ajaxPool[i]);
break;
}
}
}
}
init();
})();