sphinx_design.js (2055B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 (function () { 6 "use strict"; 7 8 var dropdownClassName = "sd-dropdown"; 9 10 function getDropdownElement() { 11 var dropdownId = window.location.hash; 12 if (!dropdownId) { 13 return false; 14 } 15 16 var dropdownElement = document.getElementById(dropdownId.substring(1)); 17 if ( 18 !dropdownElement || 19 !dropdownElement.classList.contains(dropdownClassName) 20 ) { 21 return false; 22 } 23 24 return dropdownElement; 25 } 26 27 function setupDropdownLink() { 28 var dropdowns = document.getElementsByClassName(dropdownClassName); 29 for (var i = 0; i < dropdowns.length; i++) { 30 for (var j = 0; j < dropdowns[i].classList.length; j++) { 31 if (dropdowns[i].classList[j].startsWith("anchor-id-")) { 32 dropdowns[i].id = dropdowns[i].classList[j].replace("anchor-id-", ""); 33 } 34 } 35 36 var aTag = document.createElement("a"); 37 aTag.setAttribute("href", "#" + dropdowns[i].id); 38 aTag.classList.add("dropdown-link"); 39 aTag.innerHTML = "ΒΆ"; 40 41 var summaryElement = 42 dropdowns[i].getElementsByClassName("sd-summary-title")[0]; 43 summaryElement.insertBefore( 44 aTag, 45 summaryElement.getElementsByClassName("docutils")[0] 46 ); 47 } 48 } 49 50 function scrollToDropdown() { 51 var dropdownElement = getDropdownElement(); 52 if (dropdownElement) { 53 dropdownElement.open = true; 54 dropdownElement.scrollIntoView(true); 55 } 56 } 57 58 // Initialize dropdown link 59 window.addEventListener("DOMContentLoaded", () => { 60 if (document.getElementsByClassName(dropdownClassName).length) { 61 setupDropdownLink(); 62 window.onhashchange = scrollToDropdown; 63 } 64 }); 65 66 // Scroll to and open the dropdown direct links 67 window.onload = () => { 68 if (document.getElementsByClassName(dropdownClassName).length) { 69 scrollToDropdown(); 70 } 71 }; 72 })();