Skip to content
This repository was archived by the owner on Apr 8, 2025. It is now read-only.

Commit b580d23

Browse files
authored
Don't override innerHTML (#85)
When overriding the innerHTML we are losing all events subscribers. This is breaking a lot of plugins, most recently sphinx-tabs.
1 parent 6b01963 commit b580d23

File tree

4 files changed

+50
-43
lines changed

4 files changed

+50
-43
lines changed

docs/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
sphinx==3.5.1
22
sphinx-prompt==1.1.0
3-
sphinx-tabs==1.1.10
3+
sphinx-tabs==2.0.1
44
sphinx-rtd-theme==0.4.3
55
sphinx-notfound-page==0.3
66
sphinx-js==3.1

sphinx_search/static/js/rtd_sphinx_search.js

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -610,24 +610,26 @@ const fetchAndGenerateResults = (search_url, projectName) => {
610610
* @return {String} initial html structure
611611
*/
612612
const generateAndReturnInitialHtml = () => {
613-
let initialHtml =
614-
'<div class="search__outer__wrapper search__backdrop"> \
615-
<div class="search__outer"> \
616-
<div class="search__cross" title="Close"> \
617-
<!--?xml version="1.0" encoding="UTF-8"?--> \
618-
<svg class="search__cross__img" width="15px" height="15px" enable-background="new 0 0 612 612" version="1.1" viewBox="0 0 612 612" xml:space="preserve" xmlns="http://www.w3.org/2000/svg"> \
619-
<polygon points="612 36.004 576.52 0.603 306 270.61 35.478 0.603 0 36.004 270.52 306.01 0 576 35.478 611.4 306 341.41 576.52 611.4 612 576 341.46 306.01"></polygon> \
620-
</svg> \
621-
</div> \
622-
<input class="search__outer__input" placeholder="Search ..."> \
623-
<span class="bar"></span> \
613+
let innerHTML =
614+
'<div class="search__outer"> \
615+
<div class="search__cross" title="Close"> \
616+
<!--?xml version="1.0" encoding="UTF-8"?--> \
617+
<svg class="search__cross__img" width="15px" height="15px" enable-background="new 0 0 612 612" version="1.1" viewBox="0 0 612 612" xml:space="preserve" xmlns="http://www.w3.org/2000/svg"> \
618+
<polygon points="612 36.004 576.52 0.603 306 270.61 35.478 0.603 0 36.004 270.52 306.01 0 576 35.478 611.4 306 341.41 576.52 611.4 612 576 341.46 306.01"></polygon> \
619+
</svg> \
624620
</div> \
625-
<div class="rtd__search__credits"> \
626-
Search by <a href="https://readthedocs.org/">Read the Docs</a> & <a href="https://readthedocs-sphinx-search.readthedocs.io/en/latest/">readthedocs-sphinx-search</a> \
627-
<div> \
621+
<input class="search__outer__input" placeholder="Search ..."> \
622+
<span class="bar"></span> \
623+
</div> \
624+
<div class="rtd__search__credits"> \
625+
Search by <a href="https://readthedocs.org/">Read the Docs</a> & <a href="https://readthedocs-sphinx-search.readthedocs.io/en/latest/">readthedocs-sphinx-search</a> \
628626
</div>';
629627

630-
return initialHtml;
628+
let div = createDomNode("div", {
629+
class: "search__outer__wrapper search__backdrop",
630+
});
631+
div.innerHTML = innerHTML;
632+
return div;
631633
};
632634

633635
/**
@@ -688,7 +690,7 @@ const removeSearchModal = () => {
688690
$(".search__outer__wrapper").fadeOut(ANIMATION_TIME);
689691
};
690692

691-
window.addEventListener("DOMContentLoaded", evt => {
693+
window.addEventListener("DOMContentLoaded", () => {
692694
// only add event listeners if READTHEDOCS_DATA global
693695
// variable is found.
694696
if (window.hasOwnProperty("READTHEDOCS_DATA")) {
@@ -698,7 +700,7 @@ window.addEventListener("DOMContentLoaded", evt => {
698700
const api_host = '/_';
699701

700702
let initialHtml = generateAndReturnInitialHtml();
701-
document.body.innerHTML += initialHtml;
703+
document.body.appendChild(initialHtml);
702704

703705
let search_outer_wrapper = document.querySelector(
704706
".search__outer__wrapper"

0 commit comments

Comments
 (0)