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