path-bar.html
HTML document, ASCII text
1<select id="branch-selection" style="flex: 0 1 auto;"> 2<option value="ref-{{ current }}" selected>{% if "tag:" in current %}{% trans %}tag:{% endtrans %} {% endif %}{{ current | replace("~", "/") | lstrip("/") | replace("tag:", " ") }}</option> 3{% for branch in branches %} 4{% if branch[0] != current | replace("~", "/") | replace("tag:", " ") %} 5<option value="ref-{% if branch[1] == 'tag' %}tag:{% endif %}{{ branch[0] | replace('/', '~') }}">{% if branch[1] == "tag" %}{% trans %}tag:{% endtrans %} {% endif %}{{ branch[0] }}</option> 6{% endif %} 7{% endfor %} 8</select> 9<input id="repo-path-bar" value="{{ subpath }}"> 10<script> 11branchSelect = document.getElementById("branch-selection"); 12 13branchSelect.addEventListener("change", function() { 14if(branchSelect.value == "new") { 15document.getElementById("new-branch").showModal(); 16} else { 17const PREFIX = "ref-"; 18if(branchSelect.value.startsWith(PREFIX)) { 19branch = branchSelect.value.slice(PREFIX.length); 20} 21var http = new XMLHttpRequest(); 22http.open("HEAD", "/{{ username }}/{{ repository }}/tree/" + branch + "/{{ subpath }}", false); 23http.send(); 24if(http.status == 404) { 25location.href = "/{{ username }}/{{ repository }}/tree/" + branch; 26} else { 27location.href = "/{{ username }}/{{ repository }}/tree/" + branch + "/{{ subpath }}"; 28} 29} 30}); 31 32path = document.getElementById("repo-path-bar"); 33 34path.addEventListener("change", function() { 35location.href = "/{{ username }}/{{ repository }}/tree/{{ current }}" + path.value; 36}); 37</script>