Skip to content

Fix the search widget on non-root pages #2125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/resources/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ function initSearch(name) {
'constructor' : 4
};

var baseHref = $('body').data('base-href');

function findMatches(q) {
var allMatches = []; // list of matches

Expand Down Expand Up @@ -226,7 +228,7 @@ function initSearch(name) {
if (suggestion.length > 0) {
var href = suggestion.data("href");
if (href != null) {
window.location = href;
window.location = baseHref + href;
}
}
}
Expand All @@ -235,14 +237,12 @@ function initSearch(name) {

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();
Expand Down
2 changes: 1 addition & 1 deletion lib/templates/_footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
3 changes: 2 additions & 1 deletion lib/templates/_head.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down