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