Skip to content

Commit 1bcd53d

Browse files
authored
Add a doc for how to integrate search without other customization (#11984)
We had a user asking about this, so pulled it from the Mkdocs example to the high-level Addons docs. <!-- readthedocs-preview docs start --> --- :books: Documentation previews :books: - User's documentation (`docs`): https://docs--11984.org.readthedocs.build/en/11984/ <!-- readthedocs-preview docs end --> <!-- readthedocs-preview dev start --> - Developer's documentation (`dev`): https://dev--11984.org.readthedocs.build/en/11984/ <!-- readthedocs-preview dev end -->
1 parent 2859ec8 commit 1bcd53d

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

docs/user/addons.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,32 @@ Individual configuration options for each addon are available in :guilabel:`Sett
4343
#. In the left bar, go to :guilabel:`Addons`.
4444
#. Configure each Addon individually.
4545

46+
Integrating with Addons
47+
-----------------------
48+
49+
Integrate with Search as you type
50+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
51+
52+
To configure your site to use :doc:`Read the Docs search </server-side-search/index>` instead of the default search, adapt the following block of JavaScript to your own site:
53+
54+
.. code-block:: js
55+
:caption: javascript/readthedocs.js
56+
57+
// TODO: Change me if needed
58+
const selector = "input[type='search']";
59+
60+
document.addEventListener("DOMContentLoaded", function(event) {
61+
// Trigger Read the Docs' search addon instead of the default search
62+
document.querySelector(selector).addEventListener("click", (e) => {
63+
const event = new CustomEvent("readthedocs-search-show");
64+
document.dispatchEvent(event);
65+
});
66+
});
67+
68+
.. note:: Depending on the tool you are using,
69+
you may need to change the selector to match the search input field.
70+
You will also need to ensure that the JavaScript file is included in your documentation build.
71+
4672
Addons data and customization
4773
-----------------------------
4874

0 commit comments

Comments
 (0)