mirror of
				https://gitlab.crans.org/bde/nk20
				synced 2025-11-04 01:12:08 +01:00 
			
		
		
		
	Moved js code to the external conso file
This commit is contained in:
		@@ -258,3 +258,39 @@ function consume (source, source_alias, dest, quantity, amount, reason, type, ca
 | 
				
			|||||||
      })
 | 
					      })
 | 
				
			||||||
    })
 | 
					    })
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const searchbar = document.getElementById("search-input")
 | 
				
			||||||
 | 
					const search_results = document.getElementById("search-results")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var old_pattern = null;
 | 
				
			||||||
 | 
					var firstMatch = null;
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Updates the button search tab
 | 
				
			||||||
 | 
					 * @param force Forces the update even if the pattern didn't change
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					function updateSearch(force = false) {
 | 
				
			||||||
 | 
					  let pattern = searchbar.value
 | 
				
			||||||
 | 
					  if (pattern === "")
 | 
				
			||||||
 | 
					    firstMatch = null;
 | 
				
			||||||
 | 
					  if ((pattern === old_pattern || pattern === "") && !force)
 | 
				
			||||||
 | 
					    return;
 | 
				
			||||||
 | 
					  firstMatch = null;
 | 
				
			||||||
 | 
					  const re = new RegExp(pattern, "i");
 | 
				
			||||||
 | 
					  Array.from(search_results.children).forEach(function(b) {
 | 
				
			||||||
 | 
					    if (re.test(b.innerText)) {
 | 
				
			||||||
 | 
					      b.hidden = false;
 | 
				
			||||||
 | 
					      if (firstMatch === null) {
 | 
				
			||||||
 | 
					        firstMatch = b;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    } else
 | 
				
			||||||
 | 
					      b.hidden = true;
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					searchbar.addEventListener("input", function (e) {
 | 
				
			||||||
 | 
					  debounce(updateSearch)()
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					searchbar.addEventListener("keyup", function (e) {
 | 
				
			||||||
 | 
					  if (firstMatch && e.key === "Enter")
 | 
				
			||||||
 | 
					    firstMatch.click()
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -211,41 +211,5 @@ SPDX-License-Identifier: GPL-3.0-or-later
 | 
				
			|||||||
                });
 | 
					                });
 | 
				
			||||||
            {% endif %}
 | 
					            {% endif %}
 | 
				
			||||||
        {% endfor %}
 | 
					        {% endfor %}
 | 
				
			||||||
 | 
					 | 
				
			||||||
        const searchbar = document.getElementById("search-input")
 | 
					 | 
				
			||||||
        const search_results = document.getElementById("search-results")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        var old_pattern = null;
 | 
					 | 
				
			||||||
        var firstMatch = null;
 | 
					 | 
				
			||||||
        /**
 | 
					 | 
				
			||||||
         * Updates the button search tab
 | 
					 | 
				
			||||||
         * @param force Forces the update even if the pattern didn't change
 | 
					 | 
				
			||||||
         */
 | 
					 | 
				
			||||||
        function updateSearch(force = false) {
 | 
					 | 
				
			||||||
            let pattern = searchbar.value
 | 
					 | 
				
			||||||
            if (pattern === "")
 | 
					 | 
				
			||||||
                firstMatch = null;
 | 
					 | 
				
			||||||
            if ((pattern === old_pattern || pattern === "") && !force)
 | 
					 | 
				
			||||||
                return;
 | 
					 | 
				
			||||||
            firstMatch = null;
 | 
					 | 
				
			||||||
            const re = new RegExp(pattern, "i");
 | 
					 | 
				
			||||||
            Array.from(search_results.children).forEach(function(b) {
 | 
					 | 
				
			||||||
                if (re.test(b.innerText)) {
 | 
					 | 
				
			||||||
                    b.hidden = false;
 | 
					 | 
				
			||||||
                    if (firstMatch === null) {
 | 
					 | 
				
			||||||
                        firstMatch = b;
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                } else
 | 
					 | 
				
			||||||
                    b.hidden = true;
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        searchbar.addEventListener("input", function (e) {
 | 
					 | 
				
			||||||
            debounce(updateSearch)()
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
        searchbar.addEventListener("keyup", function (e) {
 | 
					 | 
				
			||||||
            if (firstMatch && e.key === "Enter")
 | 
					 | 
				
			||||||
                firstMatch.click()
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
    </script>
 | 
					    </script>
 | 
				
			||||||
{% endblock %}
 | 
					{% endblock %}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user