Skip to content

Commit

Permalink
With RTD the JS search seems no longer necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelstoer authored and vsky committed Feb 24, 2018
1 parent a0ea61f commit 7e89c34
Showing 1 changed file with 0 additions and 29 deletions.
29 changes: 0 additions & 29 deletions docs/js/extra.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ var nodemcu = nodemcu || {};

$(document).ready(function () {
addToc();
fixSearch();
hideNavigationForAllButSelectedLanguage();
addLanguageSelectorToRtdFlyOutMenu();
replaceRelativeLinksWithStaticGitHubUrl();
Expand Down Expand Up @@ -45,34 +44,6 @@ var nodemcu = nodemcu || {};
}
}

/*
* RTD messes up MkDocs' search feature by tinkering with the search box defined in the theme, see
* https://github.com/rtfd/readthedocs.org/issues/1088. This function sets up a DOM4 MutationObserver
* to react to changes to the search form (triggered by RTD on doc ready). It then reverts everything
* the RTD JS code modified.
*/
function fixSearch() {
var target = document.getElementById('rtd-search-form');
var config = {attributes: true, childList: true};

var observer = new MutationObserver(function(mutations) {
// if it isn't disconnected it'll loop infinitely because the observed element is modified
observer.disconnect();
var form = $('#rtd-search-form');
form.empty();
form.attr('action', 'https://' + window.location.hostname + '/en/' + determineSelectedBranch() + '/search.html');
$('<input>').attr({
type: "text",
name: "q",
placeholder: "Search docs"
}).appendTo(form);
});

if (window.location.origin.indexOf('readthedocs') > -1) {
observer.observe(target, config);
}
}

function hideNavigationForAllButSelectedLanguage() {
var selectedLanguageCode = determineSelectedLanguageCode();
var selectedLanguageName = languageCodeToNameMap[selectedLanguageCode];
Expand Down

0 comments on commit 7e89c34

Please sign in to comment.