Skip to content

Commit 3169171

Browse files
authored
Fix the search widget on non-root pages (#2125)
1 parent f690e06 commit 3169171

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

lib/resources/script.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ function initSearch(name) {
100100
'constructor' : 4
101101
};
102102

103+
var baseHref = $('body').data('base-href');
104+
103105
function findMatches(q) {
104106
var allMatches = []; // list of matches
105107

@@ -226,7 +228,7 @@ function initSearch(name) {
226228
if (suggestion.length > 0) {
227229
var href = suggestion.data("href");
228230
if (href != null) {
229-
window.location = href;
231+
window.location = baseHref + href;
230232
}
231233
}
232234
}
@@ -235,14 +237,12 @@ function initSearch(name) {
235237

236238
typeaheadElement.bind('typeahead:select', function(ev, suggestion) {
237239
selectedSuggestion = suggestion;
238-
window.location = suggestion.href;
240+
window.location = baseHref + suggestion.href;
239241
});
240242
}
241243

242244
var jsonReq = new XMLHttpRequest();
243-
var scriptUrl = URI(document.getElementById("dartdoc_script_js").src);
244-
245-
jsonReq.open('GET', URI(scriptUrl.directory() + '/..').absoluteTo(scriptUrl) + '/index.json', true);
245+
jsonReq.open('GET', baseHref + 'index.json', true);
246246
jsonReq.addEventListener('load', function() {
247247
searchIndex = JSON.parse(jsonReq.responseText);
248248
initTypeahead();

lib/templates/_footer.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<script src="{{^useBaseHref}}%%__HTMLBASE_dartdoc_internal__%%{{/useBaseHref}}static-assets/typeahead.bundle.min.js"></script>
1717
<script src="{{^useBaseHref}}%%__HTMLBASE_dartdoc_internal__%%{{/useBaseHref}}static-assets/highlight.pack.js"></script>
1818
<script src="{{^useBaseHref}}%%__HTMLBASE_dartdoc_internal__%%{{/useBaseHref}}static-assets/URI.js"></script>
19-
<script id="dartdoc_script_js" src="{{^useBaseHref}}%%__HTMLBASE_dartdoc_internal__%%{{/useBaseHref}}static-assets/script.js"></script>
19+
<script src="{{^useBaseHref}}%%__HTMLBASE_dartdoc_internal__%%{{/useBaseHref}}static-assets/script.js"></script>
2020
<!-- footer placeholder -->
2121

2222
</body>

lib/templates/_head.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
<!-- header placeholder -->
3030
</head>
3131

32-
<body>
32+
{{! We don't use <base href>, but we do lookup the htmlBase from javascript. }}
33+
<body data-base-href="{{{htmlBase}}}">
3334

3435
<div id="overlay-under-drawer"></div>
3536

0 commit comments

Comments
 (0)