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