Created
December 8, 2016 22:02
-
-
Save nerestaren/3599693ca9239e22990e1477dc248a8c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function filtra(tipus, criteri) { | |
var valor = filtre[tipus][criteri].val; | |
if (criteri == 'Tot') { | |
Object.keys(filtre[tipus]).forEach(function(c) { | |
if (filtre[tipus][c].val == valor) { | |
filtre[tipus][c].val = !valor; | |
$(filtre[tipus][c].btn).toggleClass('off', !filtre[tipus][c].val); | |
} | |
}); | |
} else { | |
filtre[tipus][criteri].val = !valor; | |
$(filtre[tipus][criteri].btn).toggleClass('off', !filtre[tipus][criteri].val); | |
if (filtre[tipus]['Tot'].val == true && Object.keys(filtre[tipus]).some(function(c) { | |
return c != 'Tot' && filtre[tipus][c].val == false; | |
})) { | |
filtre[tipus]['Tot'].val = !valor; | |
$(filtre[tipus]['Tot'].btn).toggleClass('off', !filtre[tipus]['Tot'].val); | |
} else if (filtre[tipus]['Tot'].val == false && Object.keys(filtre[tipus]).every(function(c) { | |
return c == 'Tot' || filtre[tipus][c].val == true; | |
})) { | |
filtre[tipus]['Tot'].val = !valor; | |
$(filtre[tipus]['Tot'].btn).toggleClass('off', !filtre[tipus]['Tot'].val); | |
} | |
/*if (filtre[tipus]['Tot'].val == !valor && Object.keys(filtre[tipus]).every(function(c) { | |
return c == 'Tot' || filtre[tipus][c].val == !valor; | |
})) { | |
$(filtre[tipus]['Tot'].btn).toggleClass('off'); | |
filtre[tipus]['Tot'].val = !valor; | |
}*/ | |
} | |
animes.forEach(function(anime) { | |
if (valor) { | |
// Ocultam | |
if (anime.shown) { | |
// L'hem d'ocultar? | |
if (anime.generes.every(function(g) { | |
return filtre['generes'][g].val == false; | |
}) || filtre['diaEmissio'][anime.diaEmissio].val == false) { | |
anime.shown = false; | |
$(anime.el).toggleClass('hidden', !anime.shown); | |
} | |
} | |
} else { | |
// Mostram | |
if (!anime.shown) { | |
// L'hem de mostrar? | |
if ((filtre['generes']['Tot'].val || anime.generes.some(function(g) { | |
return filtre['generes'][g].val != false; | |
})) && filtre['diaEmissio'][anime.diaEmissio].val == true) { | |
anime.shown = true; | |
$(anime.el).toggleClass('hidden', !anime.shown); | |
} | |
} | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment