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.
This commit is contained in:
parent
9094592198
commit
dc30facf3e
39
util.js
39
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 ("<li>" + tag + "</li>");
|
||||
}
|
||||
}
|
||||
$('#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")) {
|
||||
|
|
Loading…
Reference in a new issue