@@ -24,85 +24,4 @@ <h3>Community</h3>
2424 </ a >
2525</ section >
2626
27- < script >
28- ( function ( ) {
29-
30- var element = document . querySelector ( "#crates" ) ;
31- let tags = document . querySelectorAll ( ".filter-tag" ) ;
32- var filter_element = document . querySelector ( ".filters" ) ;
33- var filters = [ ] ;
34- [ ] . forEach . call ( tags , function ( tag ) {
35- filters . push ( tag . dataset . keyword )
36- } ) ;
37- // Dedup
38- filters = [ ...new Set ( filters ) ] . sort ( function ( a , b ) {
39- return a . localeCompare ( b ) ;
40- } ) ;
41- enabled_filters = [ ]
42-
43- function build_filters ( ) {
44- filter_element . innerHTML = "" ;
45- filters . forEach ( ( filter ) => {
46- var filter_el = document . createElement ( "DIV" ) ;
47- filter_el . classList . add ( "tag" ) ;
48- filter_el . classList . add ( "filter-tag" ) ;
49- filter_el . dataset . keyword = filter ;
50- filter_el . innerText = filter ;
51- filter_element . appendChild ( filter_el ) ;
52- } ) ;
53- }
54-
55- function filter_entries ( ) {
56- // Get all filterable elements
57- let elements = document . querySelectorAll ( "#crates .crate" ) ;
58- [ ] . forEach . call ( elements , function ( el ) {
59- let keywords = el . dataset . keywords . split ( " " ) ;
60- let is_active = keywords . some ( r => enabled_filters . indexOf ( r ) >= 0 ) ;
61- if ( enabled_filters . length == 0 ) {
62- el . style . display = "block" ;
63- } else {
64- if ( ! is_active ) {
65- el . style . display = "none" ;
66- } else {
67- el . style . display = "block" ;
68- }
69- }
70- } ) ;
71- }
72-
73- function toggle_filter ( keyword ) {
74- let tags_with_keyword = document . querySelectorAll ( `[data-keyword="${ keyword } "]` ) ;
75- let index = enabled_filters . indexOf ( keyword ) ;
76- if ( index > - 1 ) {
77- console . log ( "toggling off tag" ) ;
78- // exists, toggle off
79- enabled_filters . splice ( index , 1 ) ;
80- [ ] . forEach . call ( tags_with_keyword , function ( el ) {
81- el . classList . remove ( "toggled" ) ;
82- } ) ;
83- } else {
84- console . log ( "toggling on tag" ) ;
85- // doesn't yet exist, push
86- enabled_filters . push ( keyword ) ;
87- // toggle style for all tags
88- [ ] . forEach . call ( tags_with_keyword , function ( el ) {
89- el . classList . add ( "toggled" ) ;
90- } ) ;
91- }
92- filter_entries ( ) ;
93- }
94-
95- build_filters ( ) ;
96-
97- tags = document . querySelectorAll ( ".filter-tag" ) ;
98- [ ] . forEach . call ( tags , function ( tag ) {
99- tag . addEventListener ( "click" , ( ev ) => {
100- let keyword = tag . dataset . keyword ;
101- toggle_filter ( keyword ) ;
102- } ) ;
103- } ) ;
104-
105- } ) ( ) ;
106- </ script >
107-
10827{% endblock content %}
0 commit comments