Bug 1918758 - Stop shipping toolkit/components/pictureinpicture in Fenix, r=mconley.
[gecko.git] / docs / _static / sphinx_design.js
blob260460bbcd898125d199c5a58a1ef65fa39426d4
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/. */
5 (function () {
6   "use strict";
8   var dropdownClassName = "sd-dropdown";
10   function getDropdownElement() {
11     var dropdownId = window.location.hash;
12     if (!dropdownId) {
13       return false;
14     }
16     var dropdownElement = document.getElementById(dropdownId.substring(1));
17     if (
18       !dropdownElement ||
19       !dropdownElement.classList.contains(dropdownClassName)
20     ) {
21       return false;
22     }
24     return dropdownElement;
25   }
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       }
36       var aTag = document.createElement("a");
37       aTag.setAttribute("href", "#" + dropdowns[i].id);
38       aTag.classList.add("dropdown-link");
39       aTag.innerHTML = "ΒΆ";
41       var summaryElement =
42         dropdowns[i].getElementsByClassName("sd-summary-title")[0];
43       summaryElement.insertBefore(
44         aTag,
45         summaryElement.getElementsByClassName("docutils")[0]
46       );
47     }
48   }
50   function scrollToDropdown() {
51     var dropdownElement = getDropdownElement();
52     if (dropdownElement) {
53       dropdownElement.open = true;
54       dropdownElement.scrollIntoView(true);
55     }
56   }
58   // Initialize dropdown link
59   window.addEventListener("DOMContentLoaded", () => {
60     if (document.getElementsByClassName(dropdownClassName).length) {
61       setupDropdownLink();
62       window.onhashchange = scrollToDropdown;
63     }
64   });
66   // Scroll to and open the dropdown direct links
67   window.onload = () => {
68     if (document.getElementsByClassName(dropdownClassName).length) {
69       scrollToDropdown();
70     }
71   };
72 })();