Skip to content

Commit

Permalink
jquery: Add search suggestions based on Algolia's DocSearch
Browse files Browse the repository at this point in the history
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 #416
  • Loading branch information
Sylvain Pace authored and mgol committed Sep 5, 2018
1 parent 2611376 commit 495f31a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
19 changes: 19 additions & 0 deletions themes/jquery/css/docsearch.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* Custom DocSeach CSS to adapt the generic one * See https://community.algolia.com/docsearch/styling.html for more info */
nav#main .searchform {
text-shadow: none;
}

.searchform label {
width: 100%;
display: block;
}

.algolia-autocomplete {
width: 99%;
}

@media only screen and (max-width: 480px) {
.ds-dropdown-menu {
min-width: 100% !important;
}
}
7 changes: 6 additions & 1 deletion themes/jquery/footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
</footer>

<?php wp_footer(); ?>

<!-- at the end of the BODY -->
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.js" onload="docsearch({apiKey: '3cfde9aca378c8aab554d5bf1b23489b',
indexName: 'jquery',
inputSelector: 'input[name=\'s\']',
debug: true // Set debug to true if you want to inspect the dropdown
})" async></script>
</body>
</html>
3 changes: 3 additions & 0 deletions themes/jquery/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@

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

<?php
if ( is_singular() && get_option( 'thread_comments' ) )
Expand Down

0 comments on commit 495f31a

Please sign in to comment.