@@ -8,6 +8,7 @@ var nodemcu = nodemcu || {};
8
8
9
9
$ ( document ) . ready ( function ( ) {
10
10
addToc ( ) ;
11
+ fixSearch ( ) ;
11
12
hideNavigationForAllButSelectedLanguage ( ) ;
12
13
addLanguageSelectorToRtdFlyOutMenu ( ) ;
13
14
replaceRelativeLinksWithStaticGitHubUrl ( ) ;
@@ -43,6 +44,34 @@ var nodemcu = nodemcu || {};
43
44
}
44
45
}
45
46
47
+ /*
48
+ * RTD messes up MkDocs' search feature by tinkering with the search box defined in the theme, see
49
+ * https://github.com/rtfd/readthedocs.org/issues/1088. This function sets up a DOM4 MutationObserver
50
+ * to react to changes to the search form (triggered by RTD on doc ready). It then reverts everything
51
+ * the RTD JS code modified.
52
+ */
53
+ function fixSearch ( ) {
54
+ var target = document . getElementById ( 'rtd-search-form' ) ;
55
+ var config = { attributes : true , childList : true } ;
56
+
57
+ var observer = new MutationObserver ( function ( mutations ) {
58
+ // if it isn't disconnected it'll loop infinitely because the observed element is modified
59
+ observer . disconnect ( ) ;
60
+ var form = $ ( '#rtd-search-form' ) ;
61
+ form . empty ( ) ;
62
+ form . attr ( 'action' , 'https://' + window . location . hostname + '/en/' + determineSelectedBranch ( ) + '/search.html' ) ;
63
+ $ ( '<input>' ) . attr ( {
64
+ type : "text" ,
65
+ name : "q" ,
66
+ placeholder : "Search docs"
67
+ } ) . appendTo ( form ) ;
68
+ } ) ;
69
+
70
+ if ( window . location . origin . indexOf ( 'readthedocs' ) > - 1 ) {
71
+ observer . observe ( target , config ) ;
72
+ }
73
+ }
74
+
46
75
function hideNavigationForAllButSelectedLanguage ( ) {
47
76
var selectedLanguageCode = determineSelectedLanguageCode ( ) ;
48
77
var selectedLanguageName = languageCodeToNameMap [ selectedLanguageCode ] ;
0 commit comments