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 %}tag:{% endif %}{{ current | replace("~", "/") | 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" %}tag: {% endif %}{{ branch[0] }}</option> 6{% endif %} 7{% endfor %} 8<!--<option value="new">[CREATE NEW BRANCH]</option>--> 9</select> 10<input id="repo-path-bar" value="{{ subpath }}"> 11<script> 12branchSelect = document.getElementById("branch-selection"); 13 14branchSelect.addEventListener("change", function() { 15if(branchSelect.value == "new") { 16document.getElementById("new-branch").showModal(); 17} else { 18const PREFIX = "ref-"; 19if(branchSelect.value.startsWith(PREFIX)) { 20branch = branchSelect.value.slice(PREFIX.length); 21} 22var http = new XMLHttpRequest(); 23http.open("HEAD", "/{{ username }}/{{ repository }}/tree/" + branch + "/{{ subpath }}", false); 24http.send(); 25if(http.status == 404) { 26location.href = "/{{ username }}/{{ repository }}/tree/" + branch; 27} else { 28location.href = "/{{ username }}/{{ repository }}/tree/" + branch + "/{{ subpath }}"; 29} 30} 31}); 32 33path = document.getElementById("repo-path-bar"); 34 35path.addEventListener("change", function() { 36location.href = "/{{ username }}/{{ repository }}/tree/{{ current }}" + path.value; 37}); 38</script>