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