Skip to content

Instantly share code, notes, and snippets.

@webdevstar
Last active January 19, 2019 11:42
Show Gist options
  • Save webdevstar/3d821615388b788b69edf087adc4fa3e to your computer and use it in GitHub Desktop.
Save webdevstar/3d821615388b788b69edf087adc4fa3e to your computer and use it in GitHub Desktop.
Filter Example: All Social site(Facebook, Linkedin, VK etc ) filter way...
var countries = [];
var methods = [];
$(document).ready(function(){
function filter (){
$(".wm-courses-popular-wrap").parent().hide();
$(".wm-courses-popular-wrap").toArray().forEach((item) => {
const hasCountry = countries.length > 0 ? countries.indexOf($(item).attr('country')) > -1 : true;
const hasMethod = methods.length > 0 ? methods.indexOf($(item).attr('method')) > -1 : true;
if (hasCountry && hasMethod) {
$(item).parent().css('display', 'list-item');
}
})
}
$("#country li input").click(function(){
var id = $(this).attr('id');
if(id == "type1"){
if($("#"+id).is(":checked")){
for(var i=2; i<=197; i++){
$("#type"+i).prop('checked', true);
countries.push($("#type"+i).attr('id'));
}
}
else {
for(var i=2; i<=197; i++){
$("#type"+i).prop('checked', false);
}
countries = [];
}
}
else {
$("#type1").prop('checked', false);
if($("#"+id).is(":checked")){
countries.push(id);
}
else {
countries.splice( countries.indexOf(id), 1 );
}
}
filter()
});
$("#method li input").click(function(){
var id = $(this).attr('id');
if(id == "method1"){
if($("#"+id).is(":checked")){
for(var i=2; i<=6; i++){
$("#method"+i).prop('checked', true);
methods.push($("#method"+i).attr('id'));
}
}
else {
for(var i=2; i<=6; i++){
$("#method"+i).prop('checked', false);
methods = [];
}
}
}
else {
$("#method1").prop('checked', false);
if($("#"+id).is(":checked")){
methods.push(id);
}
else {
methods.splice( methods.indexOf(id), 1 );
}
}
filter()
});
});
@kinddeveloper
Copy link

this filter way is very optimized solution.

@nodetop
Copy link

nodetop commented Oct 3, 2018

your code is very optimized and clean.

@filip1991903
Copy link

download

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment