Skip to content

Commit

Permalink
inkeep script update (#25)
Browse files Browse the repository at this point in the history
* update search ids

* update tag id info

---------

Co-authored-by: chdeskur <[email protected]>
  • Loading branch information
fern-support and chdeskur authored Nov 6, 2024
1 parent 41de661 commit 6490469
Showing 1 changed file with 14 additions and 26 deletions.
40 changes: 14 additions & 26 deletions fern/assets/inkeep.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
const searchButtonContainerIds = [
"fern-search-bar",
"fern-search-button",
"fern-search-bar"
];

// Define the base settings
const inkeepSettings = {
isOpen: true,
baseSettings: {
apiKey: "a58574ddc0e41c75990d1c0e890ad3c8725dc9e7c8ee3d3e",
integrationId: "clthv1rgg000sdjil26l2vg03",
Expand Down Expand Up @@ -34,26 +33,6 @@ const inkeepSettings = {
}
};

// Function to initialize search containers
function initializeSearchContainers() {
// Clone and replace search buttons to remove existing listeners
// Only process elements that exist
const clonedSearchButtonContainers = searchButtonContainerIds
.map((id) => {
const originalElement = document.getElementById(id);
if (!originalElement) {
console.log(`Search container ${id} not found, skipping...`);
return null;
}
const clonedElement = originalElement.cloneNode(true);
originalElement.parentNode.replaceChild(clonedElement, originalElement);
return clonedElement;
})
.filter(Boolean); // Remove null entries

return clonedSearchButtonContainers;
}

// Function to initialize Inkeep
function initializeInkeep() {
// Color mode sync settings
Expand Down Expand Up @@ -88,13 +67,23 @@ function initializeInkeep() {
},
},
});

// Get search containers after DOM is ready
const clonedSearchButtonContainers = initializeSearchContainers();

const clonedSearchButtonContainers = searchButtonContainerIds
.map((id) => {
const originalElement = document.getElementById(id);
if (!originalElement) {
console.log(`Search container ${id} not found, skipping...`);
return null;
}
originalElement.disabled = false;
return originalElement
}).filter(Boolean);

// Add click listeners to search buttons
clonedSearchButtonContainers.forEach((trigger) => {
console.log("adding trigger")
trigger.addEventListener("click", function () {
console.log("clicked")
inkeepSearchModal.render({
isOpen: true,
});
Expand All @@ -106,7 +95,6 @@ function initializeInkeep() {
"keydown",
(event) => {
if (
(event.metaKey || event.ctrlKey) &&
(event.key === "/")
) {
event.stopPropagation();
Expand Down

0 comments on commit 6490469

Please sign in to comment.