From 5b6918488c067d7b2bde431ccdb05c0fdf62e3ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lucas?= Date: Mon, 8 Jul 2013 18:02:37 +0200 Subject: [PATCH] Add a button to clear all filters. re #46 --- util.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/util.js b/util.js index e946c10..b9ac978 100644 --- a/util.js +++ b/util.js @@ -121,7 +121,10 @@ function getTagList () { function doFilter () { $(".books").removeClass("filtered"); - if (jQuery.isEmptyObject(filterList)) { return; } + if (jQuery.isEmptyObject(filterList)) { + updateFilters (); + return; + } $(".se").each (function(){ var taglist = ", " + $(this).text() + ", "; @@ -169,6 +172,8 @@ function updateFilters () { } } + $("#filter ul").append ("
  • _CLEAR_
  • "); + // Sort the list alphabetically $('#filter ul li').sortElements(function(a, b){ return $(a).text() > $(b).text() ? 1 : -1; @@ -178,6 +183,13 @@ function updateFilters () { function handleFilterEvents () { $("#filter ul").on ("click", "li", function(){ var filter = $(this).text (); + if (filter === "_CLEAR_") { + filterList = {}; + $("#filter ul li").removeClass ("filter-exclude"); + $("#filter ul li").removeClass ("filter-include"); + doFilter (); + return; + } switch ($(this).attr("class")) { case "filter-include" : $(this).attr("class", "filter-exclude");