Skip to content

Commit ee58534

Browse files
committed
Updated the doxygen-custom-page-injector.js script
1 parent 4697af5 commit ee58534

2 files changed

Lines changed: 96 additions & 24 deletions

File tree

docs/doxygen-custom-page-injector.js

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Created by basicx-StrgV //
33
// https://github.com/basicx-StrgV/ //
44
//--------------------------------------------------//
5-
// Version: 1.0.3 //
5+
// Version: 1.0.4 //
66
//--------------------------------------------------//
77
document.addEventListener("DOMContentLoaded", () => {
88
// Get the injection wrapper element and nav to value
@@ -41,18 +41,51 @@ document.addEventListener("DOMContentLoaded", () => {
4141
// Proceed if the new document is loaded
4242
document.addEventListener("DOMContentLoaded", () => {
4343
try {
44-
// Check if a value for nav to is provided
45-
if (navToValue !== null && navTo !== null) {
46-
// Wrap the original navTo function from doxygen into custom function
47-
let originalNavToFunc = navTo;
48-
navTo = (o, root, hash, relpath) => {
49-
// Ignore the root value and parse or nav to value instead
50-
originalNavToFunc(o, navToValue, hash, relpath);
51-
};
44+
if (navToValue != null && navToValue.trim() != "") {
45+
// Get doxygen nav content
46+
let navContent = document.getElementById("nav-tree-contents");
47+
48+
if (navContent == null) {
49+
// Log error if content could not be found
50+
console.error(
51+
"[doxygen-custom-page-injector.js] The navigation can not be set to the current page, because the doxygen nav content could not be located"
52+
);
53+
} else {
54+
// Add event to check the nav content to remove the default nav and initiate the correct nav,
55+
// after the default nav was loaded
56+
let customNavInserted = false;
57+
navContent.addEventListener("DOMNodeInserted", (event) => {
58+
if (
59+
customNavInserted == false &&
60+
event.relatedNode == navContent
61+
) {
62+
// Clean up of the nac default content
63+
for (let i = 0; i < navContent.children.length; i++) {
64+
// Remove elements from the nav content, that are initalized with the nav
65+
if (navContent.children[i].id != "nav-sync") {
66+
navContent.removeChild(navContent.children[i]);
67+
}
68+
}
69+
70+
// Set the flag that indicates that the custom nav was inserted
71+
customNavInserted = true;
72+
73+
// Initiate custom nav tree
74+
// (The "initNavTree(...)" function comes from the folowing doxygen script: "navtree.js")
75+
initNavTree(navToValue, "");
76+
}
77+
});
78+
}
79+
} else {
80+
console.error(
81+
"[doxygen-custom-page-injector.js] The navigation can not be set to the current page, bacause no 'nav-to' value provided."
82+
);
83+
return;
5284
}
53-
} catch {
85+
} catch (e) {
5486
console.log(
55-
"[doxygen-custom-page-injector.js] Setting the correct nav item does not work with doxygen 1.10.0 or higher"
87+
"[doxygen-custom-page-injector.js] An error occured while trying to set the doxygeen nav:",
88+
e
5689
);
5790
}
5891

@@ -62,7 +95,10 @@ document.addEventListener("DOMContentLoaded", () => {
6295
// Exit if no content div was found and display error message
6396
if (contentContainer == null) {
6497
document.body.innerHTML = "";
65-
document.body.innerText = "Failed to load custom page";
98+
document.body.innerText = "Failed to load custom page.";
99+
console.error(
100+
"[doxygen-custom-page-injector.js] Failed to inject custom html content, because the doxygen content container could not be found."
101+
);
66102
return;
67103
}
68104

doxygen/js/doxygen-custom-page-injector.js

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Created by basicx-StrgV //
33
// https://github.com/basicx-StrgV/ //
44
//--------------------------------------------------//
5-
// Version: 1.0.3 //
5+
// Version: 1.0.4 //
66
//--------------------------------------------------//
77
document.addEventListener("DOMContentLoaded", () => {
88
// Get the injection wrapper element and nav to value
@@ -41,18 +41,51 @@ document.addEventListener("DOMContentLoaded", () => {
4141
// Proceed if the new document is loaded
4242
document.addEventListener("DOMContentLoaded", () => {
4343
try {
44-
// Check if a value for nav to is provided
45-
if (navToValue !== null && navTo !== null) {
46-
// Wrap the original navTo function from doxygen into custom function
47-
let originalNavToFunc = navTo;
48-
navTo = (o, root, hash, relpath) => {
49-
// Ignore the root value and parse or nav to value instead
50-
originalNavToFunc(o, navToValue, hash, relpath);
51-
};
44+
if (navToValue != null && navToValue.trim() != "") {
45+
// Get doxygen nav content
46+
let navContent = document.getElementById("nav-tree-contents");
47+
48+
if (navContent == null) {
49+
// Log error if content could not be found
50+
console.error(
51+
"[doxygen-custom-page-injector.js] The navigation can not be set to the current page, because the doxygen nav content could not be located"
52+
);
53+
} else {
54+
// Add event to check the nav content to remove the default nav and initiate the correct nav,
55+
// after the default nav was loaded
56+
let customNavInserted = false;
57+
navContent.addEventListener("DOMNodeInserted", (event) => {
58+
if (
59+
customNavInserted == false &&
60+
event.relatedNode == navContent
61+
) {
62+
// Clean up of the nac default content
63+
for (let i = 0; i < navContent.children.length; i++) {
64+
// Remove elements from the nav content, that are initalized with the nav
65+
if (navContent.children[i].id != "nav-sync") {
66+
navContent.removeChild(navContent.children[i]);
67+
}
68+
}
69+
70+
// Set the flag that indicates that the custom nav was inserted
71+
customNavInserted = true;
72+
73+
// Initiate custom nav tree
74+
// (The "initNavTree(...)" function comes from the folowing doxygen script: "navtree.js")
75+
initNavTree(navToValue, "");
76+
}
77+
});
78+
}
79+
} else {
80+
console.error(
81+
"[doxygen-custom-page-injector.js] The navigation can not be set to the current page, bacause no 'nav-to' value provided."
82+
);
83+
return;
5284
}
53-
} catch {
85+
} catch (e) {
5486
console.log(
55-
"[doxygen-custom-page-injector.js] Setting the correct nav item does not work with doxygen 1.10.0 or higher"
87+
"[doxygen-custom-page-injector.js] An error occured while trying to set the doxygeen nav:",
88+
e
5689
);
5790
}
5891

@@ -62,7 +95,10 @@ document.addEventListener("DOMContentLoaded", () => {
6295
// Exit if no content div was found and display error message
6396
if (contentContainer == null) {
6497
document.body.innerHTML = "";
65-
document.body.innerText = "Failed to load custom page";
98+
document.body.innerText = "Failed to load custom page.";
99+
console.error(
100+
"[doxygen-custom-page-injector.js] Failed to inject custom html content, because the doxygen content container could not be found."
101+
);
66102
return;
67103
}
68104

0 commit comments

Comments
 (0)