]> begriffs open source - cmsis-freertos/blob - version.js
Update documentation for branch main
[cmsis-freertos] / version.js
1 //--- list of versions ---
2 const versions = {
3     "main": "11.2.1-dev2",
4     "latest": "11.2.0",
5     "v11.1.0": "11.1.0",
6     "v11.0.1": "11.0.1",
7     "v10.5.1": "10.5.1"
8 }
9 //--- list of versions ---
10
11 var script = document.currentScript
12 if (script && script.src) {
13   var scriptUrl = new URL(script.src);
14   var docUrl = new URL(document.URL);
15   var baseUrl = new URL(scriptUrl)
16   baseUrl.pathname = baseUrl.pathname.split('/').slice(0,-1).join("/")
17
18   function urlForVersion(url, version) {
19       url = new URL(url);
20       pathname = url.pathname.replace(baseUrl.pathname, "");
21       parts = pathname.split("/");
22       parts[1] = version;
23       url.pathname = baseUrl.pathname + parts.join("/");
24       return url
25   }
26
27   function writeVersionDropdown() {
28       currentVersion = document.currentScript.parentNode.innerText;
29       document.currentScript.parentNode.classList.add("dropdown");
30       document.currentScript.parentNode.innerText = "";
31       document.write('  <span onclick="myFunction()" class="dropbtn">'+currentVersion+'</span>');
32       document.write('  <div id="myDropdown" class="dropdown-content">');
33       for(var version in versions) {
34           var label = versions[version];
35           if (label != version) {
36               label += " ("+version+")"
37           }
38           label = "Version " + label
39           document.write('    <a href="'+urlForVersion(docUrl, version)+'">'+label+'</a>');
40       }
41       document.write('  </div>');
42   };
43 } else {
44   function writeVersionDropdown() {}
45 }
46
47 /* When the user clicks on the button,
48 toggle between hiding and showing the dropdown content */
49 function myFunction() {
50   document.getElementById("myDropdown").classList.toggle("show");
51 }
52
53 // Close the dropdown menu if the user clicks outside of it
54 window.onclick = function(event) {
55   if (!event.target.matches('.dropbtn')) {
56     var dropdowns = document.getElementsByClassName("dropdown-content");
57     var i;
58     for (i = 0; i < dropdowns.length; i++) {
59       var openDropdown = dropdowns[i];
60       if (openDropdown.classList.contains('show')) {
61         openDropdown.classList.remove('show');
62       }
63     }
64   }
65 }