From dc30facf3e0cc5133f4a153c4734eb6dac05b184 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lucas?= Date: Mon, 1 Jul 2013 18:14:37 +0200 Subject: [PATCH] ugly way update to filters to update the list of tags when you start filtering. re #46 The tags are also correcly sorted. TODO : update the click event when adding new li. --- util.js | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/util.js b/util.js index 3ae7758..ea984e8 100644 --- a/util.js +++ b/util.js @@ -111,6 +111,21 @@ function navigateTo (url) { } } +function getTagList () { + var tagList = {}; + $(".se").each (function(){ + if ($(this).parents (".filtered").length > 0) return; + var taglist = $(this).text(); + + var tagarray = taglist.split (",") + for (i in tagarray) { + var tag = tagarray [i].replace(/^\s+/g,'').replace(/\s+$/g,''); + tagList [tag] = 1; + } + }); + return tagList; +} + function doFilter () { $(".books").removeClass("filtered"); if (jQuery.isEmptyObject(filterList)) return; @@ -134,6 +149,27 @@ function doFilter () { } if (toBeFiltered) $(this).parents (".books").addClass ("filtered"); }); + var tagList = getTagList (); + $("#filter ul li").each (function () { + var text = $(this).text (); + if (isDefined (tagList [text]) || $(this).attr ('class')) { + tagList [text] = 0; + } else { + tagList [text] = -1; + } + }); + for (var tag in tagList) { + var tagValue = tagList [tag]; + if (tagValue == -1) { + $("#filter ul li:contains('" + tag + "')").remove(); + } + if (tagValue == 1) { + $("#filter ul").append ("
  • " + tag + "
  • "); + } + } + $('#filter ul li').sortElements(function(a, b){ + return $(a).text() > $(b).text() ? 1 : -1; + }); } function updatePage (data) { @@ -171,6 +207,9 @@ function updatePage (data) { } } }); + $('#filter ul li').sortElements(function(a, b){ + return $(a).text() > $(b).text() ? 1 : -1; + }); $("li").click(function(){ var filter = $(this).text (); switch ($(this).attr("class")) {