1/* API collapsing */
2document.addEventListener('DOMContentLoaded', (event) => {
3    document.querySelectorAll("dl.cpp").forEach(cppListing => {
4        const dt = cppListing.querySelector("dt");
5        let shouldBeExpanded = false;
6        if(dt.id == document.location.hash.substring(1))
7            shouldBeExpanded = true;
8        cppListing.classList.add(shouldBeExpanded ? "expanded" : "unexpanded");
9        const button = document.createElement("span");
10        button.classList.add("lv-api-expansion-button");
11        button.addEventListener("click", () => {
12            cppListing.classList.toggle("unexpanded");
13            cppListing.classList.toggle("expanded");
14        });
15
16        dt.insertBefore(button, dt.firstChild);
17    });
18
19    fetch('https://lvgl.io/home-banner.txt') // Replace with your URL
20  .then(response => {
21    // Check if the request was successful
22    if (!response.ok) {
23      throw new Error(`HTTP error! Status: ${response.status}`);
24    }
25    // Read the response as text
26    return response.text();
27  })
28  .then(data => {
29
30    const section = document.querySelector('.wy-nav-content-wrap');
31
32    //Add a div
33    const newDiv = document.createElement('div');
34    newDiv.style="background-image: linear-gradient(45deg, black, #5e5e5e); color: white; border-bottom: 4px solid #e10010; padding-inline:3em"
35    section.insertBefore(newDiv, section.firstChild);
36
37
38    //Add a p to the div
39    const newP = document.createElement('p');
40    newP.style="padding-block:12px; margin-block:0px;align-content: center;align-items: center;"
41    newP.innerHTML = data
42    newDiv.insertBefore(newP, newDiv.firstChild);
43
44    const children = newDiv.querySelectorAll('*');
45
46    // Iterate over each child
47    children.forEach(child => {
48        // Check if the child has an id
49        if (child.id) {
50            // Prepend 'docs-' to the id
51            child.id = 'docs-' + child.id;
52        }
53    })
54  }) .catch(error => {
55        console.error('Fetch error: ' + error.message);
56  });
57})
58