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