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
					
				
					 1 changed files with 39 additions and 0 deletions
				
			
		
							
								
								
									
										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 () { | function doFilter () { | ||||||
|     $(".books").removeClass("filtered"); |     $(".books").removeClass("filtered"); | ||||||
|     if (jQuery.isEmptyObject(filterList)) return; |     if (jQuery.isEmptyObject(filterList)) return; | ||||||
|  | @ -134,6 +149,27 @@ function doFilter () { | ||||||
|         } |         } | ||||||
|         if (toBeFiltered) $(this).parents (".books").addClass ("filtered"); |         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) { | 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(){ |         $("li").click(function(){ | ||||||
|             var filter = $(this).text (); |             var filter = $(this).text (); | ||||||
|             switch ($(this).attr("class")) { |             switch ($(this).attr("class")) { | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue