Skip to content

Commit 495f31a

Browse files
Sylvain Pacemgol
authored andcommitted
jquery: Add search suggestions based on Algolia's DocSearch
This commit adds DocSearch to the documentation website. It allows a user to have a learn-as-you-type experience by displaying results thanks to a dropdown in a live way. If there is no result, pressing enter will enable the legacy search. Fixes jquery/api.jquery.com#1104 Closes jquery#416
1 parent 2611376 commit 495f31a

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

themes/jquery/css/docsearch.css

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* Custom DocSeach CSS to adapt the generic one * See https://community.algolia.com/docsearch/styling.html for more info */
2+
nav#main .searchform {
3+
text-shadow: none;
4+
}
5+
6+
.searchform label {
7+
width: 100%;
8+
display: block;
9+
}
10+
11+
.algolia-autocomplete {
12+
width: 99%;
13+
}
14+
15+
@media only screen and (max-width: 480px) {
16+
.ds-dropdown-menu {
17+
min-width: 100% !important;
18+
}
19+
}

themes/jquery/footer.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@
3737
</footer>
3838

3939
<?php wp_footer(); ?>
40-
40+
<!-- at the end of the BODY -->
41+
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.js" onload="docsearch({apiKey: '3cfde9aca378c8aab554d5bf1b23489b',
42+
indexName: 'jquery',
43+
inputSelector: 'input[name=\'s\']',
44+
debug: true // Set debug to true if you want to inspect the dropdown
45+
})" async></script>
4146
</body>
4247
</html>

themes/jquery/header.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535

3636
<script src="https://use.typekit.net/wde1aof.js"></script>
3737
<script>try{Typekit.load();}catch(e){}</script>
38+
<!-- at the end of the HEAD -->
39+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.css" />
40+
<link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/css/docsearch.css">
3841

3942
<?php
4043
if ( is_singular() && get_option( 'thread_comments' ) )

0 commit comments

Comments
 (0)