Close menu upon click inside

This commit is contained in:
Hendrik Kleinwaechter
2023-07-14 15:02:19 +02:00
parent d7e53ed8dc
commit 5662b42eb5
2 changed files with 22 additions and 0 deletions

11
website/assets/script.js Normal file
View File

@@ -0,0 +1,11 @@
document.addEventListener('DOMContentLoaded', function() {
var menuItems = document.querySelector('.menu-items');
menuItems.addEventListener('click', function(event) {
if (event.target.tagName === 'SPAN') {
var checkboxes = document.querySelectorAll('#toggle-menu');
checkboxes.forEach(function(checkbox) {
checkbox.checked = false;
});
}
});
});

View File

@@ -40,6 +40,7 @@ class ModifyBuild
text = remove_section_table_of_contents(text) text = remove_section_table_of_contents(text)
text = mark_menu_as_selected_if_on_page(text, extract_file_from_path(filename)) text = mark_menu_as_selected_if_on_page(text, extract_file_from_path(filename))
text = add_canonical_for_duplicates(text, extract_file_from_path(filename)) text = add_canonical_for_duplicates(text, extract_file_from_path(filename))
text = include_javascript(text)
File.open(filename, "w") {|file| file.puts text } File.open(filename, "w") {|file| file.puts text }
end end
@@ -367,6 +368,16 @@ class ModifyBuild
doc.to_html doc.to_html
end end
def include_javascript(text)
doc = build_doc(text)
head = doc.css("head")[0]
js_tag_html = %Q{
<script type="text/javascript" src="script.js"></script>
}
head.inner_html = "#{head.inner_html} #{js_tag_html}"
doc.to_html
end
def build_doc(text) def build_doc(text)
Nokogiri::HTML(text) Nokogiri::HTML(text)
end end