Skip to content

Commit

Permalink
test: bg
Browse files Browse the repository at this point in the history
  • Loading branch information
thephez committed Oct 8, 2024
1 parent 92cf8f3 commit 071dbc3
Showing 1 changed file with 52 additions and 10 deletions.
62 changes: 52 additions & 10 deletions _static/js/pydata-search-close.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,13 @@ var addEventListenerForSearchKeyboard = () => {
var setupSearchButtons = () => {
addEventListenerForSearchKeyboard();

// Wait until DOM is fully loaded
document.addEventListener('DOMContentLoaded', () => {
const searchElement = document.querySelector('readthedocs-search');

// Select the specific background div within the 'readthedocs-search' element
const background = searchElement.shadowRoot.querySelector('div[role="search"] > div.background');
if (background) {
background.addEventListener('click', hideSearch);
}
});
// const searchElement = document.querySelector('readthedocs-search');
//
// // Select the specific background div within the 'readthedocs-search' element
// const background = searchElement.shadowRoot.querySelector('div.background');
// if (background) {
// background.addEventListener('click', hideSearch);
// }

// Add event listeners to elements with class "search-button__button"
const searchButtons = document.querySelectorAll('.search-button__button');
Expand All @@ -103,8 +100,39 @@ var setupSearchButtons = () => {
});


document.addEventListener(
"readthedocs-addons-data-ready",
function (event) {
const data = event.detail.data();
console.log(data)
}
);
};

const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
if (mutation.addedNodes.length > 0) {
const searchElement = document.querySelector('readthedocs-search');
if (searchElement) {
console.log('Found the search element!');
observer.disconnect(); // Stop observing once the element is found
// Add your shadow DOM query logic here
// Vanilla JS for shadowRoot-based background click listener
const searchElement = document.querySelector('readthedocs-search'); // Adjust this to target the correct search element
console.log(searchElement)
if (searchElement && searchElement.shadowRoot) {
const background = searchElement.shadowRoot.querySelector('div > div.background');
if (background) {
background.addEventListener('click', function() {
hidePydataSearch();
});
}
}
}
}
});
});

// Custom code to manage closing the RtD search dialog properly
$(document).ready(function(){
$(".search__cross").click(function(){
Expand All @@ -118,6 +146,20 @@ $(document).ready(function(){
console.log("Close by search-button__overlay");
hidePydataSearch();
});

customElements.whenDefined('readthedocs-search').then(() => {
const searchElement = document.querySelector('readthedocs-search');
if (searchElement) {
console.log('Found the search element!');
// Add your shadow DOM query logic here
} else {
console.log('Search element not found');
}
});

observer.observe(document.body, { childList: true, subtree: true });
});

$(setupSearchButtons);


0 comments on commit 071dbc3

Please sign in to comment.