]> begriffs open source - cmsis/blob - version.js
Update documentation for branch main
[cmsis] / version.js
1 //--- list of versions ---
2 const versions = {
3     "General": {
4         "main": "6.1.1-dev18",
5         "latest": "6.1.0",
6         "v6.0.0": "6.0.0"
7     },
8     "Core": {
9         "latest": "6.1.0",
10         "v6.0.0": "6.0.0"
11     },
12     "Core_A": {
13         "latest": "6.1.0",
14         "v6.0.0": "6.0.0"
15     },
16     "Driver": {
17         "latest": "2.10.0",
18         "v6.0.0": "2.9.0"
19     },
20     "RTOS2": {
21         "latest": "2.3.0"
22     }
23 }
24 //--- list of versions ---
25
26 const components = {
27   "CMSIS": "General",
28   "CMSIS-Core (Cortex-M)": "Core",
29   "CMSIS-Core (Cortex-A)": "Core_A",
30   "CMSIS-Driver": "Driver",
31   "CMSIS-RTOS2": "RTOS2"
32 }
33
34 var script = document.currentScript
35 if (script && script.src) {
36   var scriptUrl = new URL(script.src);
37   var docUrl = new URL(document.URL);
38   var baseUrl = new URL(scriptUrl)
39   baseUrl.pathname = baseUrl.pathname.split('/').slice(0,-1).join("/")
40
41   function urlForVersion(url, version) {
42       url = new URL(url);
43       pathname = url.pathname.replace(baseUrl.pathname, "");
44       parts = pathname.split("/");
45       parts[1] = version;
46       url.pathname = baseUrl.pathname + parts.join("/");
47       return url
48   }
49
50   function writeVersionDropdown(id) {
51       component = components[id]
52       currentVersion = document.currentScript.parentNode.innerText;
53       document.currentScript.parentNode.classList.add("dropdown");
54       document.currentScript.parentNode.innerText = "";
55       document.write('  <span onclick="myFunction()" class="dropbtn">'+currentVersion+'</span>');
56       document.write('  <div id="myDropdown" class="dropdown-content">');
57       for(var version in versions[component]) {
58           var label = versions[component][version];
59           if (label != version) {
60               label += " ("+version+")"
61           }
62           label = "Version " + label
63           document.write('    <a href="'+urlForVersion(docUrl, version)+'">'+label+'</a>');
64       }
65       document.write('  </div>');
66   };
67 } else {
68   function writeVersionDropdown(id) {}
69 }
70
71 /* When the user clicks on the button,
72 toggle between hiding and showing the dropdown content */
73 function myFunction() {
74   document.getElementById("myDropdown").classList.toggle("show");
75 }
76
77 // Close the dropdown menu if the user clicks outside of it
78 window.onclick = function(event) {
79   if (!event.target.matches('.dropbtn')) {
80     var dropdowns = document.getElementsByClassName("dropdown-content");
81     var i;
82     for (i = 0; i < dropdowns.length; i++) {
83       var openDropdown = dropdowns[i];
84       if (openDropdown.classList.contains('show')) {
85         openDropdown.classList.remove('show');
86       }
87     }
88   }
89 }