Fix the search widget on non-root pages (#2125)
diff --git a/lib/resources/script.js b/lib/resources/script.js
index 152476f..f5dba29 100644
--- a/lib/resources/script.js
+++ b/lib/resources/script.js
@@ -100,6 +100,8 @@
'constructor' : 4
};
+ var baseHref = $('body').data('base-href');
+
function findMatches(q) {
var allMatches = []; // list of matches
@@ -226,7 +228,7 @@
if (suggestion.length > 0) {
var href = suggestion.data("href");
if (href != null) {
- window.location = href;
+ window.location = baseHref + href;
}
}
}
@@ -235,14 +237,12 @@
typeaheadElement.bind('typeahead:select', function(ev, suggestion) {
selectedSuggestion = suggestion;
- window.location = suggestion.href;
+ window.location = baseHref + suggestion.href;
});
}
var jsonReq = new XMLHttpRequest();
- var scriptUrl = URI(document.getElementById("dartdoc_script_js").src);
-
- jsonReq.open('GET', URI(scriptUrl.directory() + '/..').absoluteTo(scriptUrl) + '/index.json', true);
+ jsonReq.open('GET', baseHref + 'index.json', true);
jsonReq.addEventListener('load', function() {
searchIndex = JSON.parse(jsonReq.responseText);
initTypeahead();
diff --git a/lib/templates/_footer.html b/lib/templates/_footer.html
index afcc2cc..bac8322 100644
--- a/lib/templates/_footer.html
+++ b/lib/templates/_footer.html
@@ -16,7 +16,7 @@
<script src="{{^useBaseHref}}%%__HTMLBASE_dartdoc_internal__%%{{/useBaseHref}}static-assets/typeahead.bundle.min.js"></script>
<script src="{{^useBaseHref}}%%__HTMLBASE_dartdoc_internal__%%{{/useBaseHref}}static-assets/highlight.pack.js"></script>
<script src="{{^useBaseHref}}%%__HTMLBASE_dartdoc_internal__%%{{/useBaseHref}}static-assets/URI.js"></script>
-<script id="dartdoc_script_js" src="{{^useBaseHref}}%%__HTMLBASE_dartdoc_internal__%%{{/useBaseHref}}static-assets/script.js"></script>
+<script src="{{^useBaseHref}}%%__HTMLBASE_dartdoc_internal__%%{{/useBaseHref}}static-assets/script.js"></script>
<!-- footer placeholder -->
</body>
diff --git a/lib/templates/_head.html b/lib/templates/_head.html
index 15580a9..5c5e9db 100644
--- a/lib/templates/_head.html
+++ b/lib/templates/_head.html
@@ -29,7 +29,8 @@
<!-- header placeholder -->
</head>
-<body>
+{{! We don't use <base href>, but we do lookup the htmlBase from javascript. }}
+<body data-base-href="{{{htmlBase}}}">
<div id="overlay-under-drawer"></div>