Skip to content
This repository was archived by the owner on Aug 3, 2024. It is now read-only.

Commit 8e88615

Browse files
timjbalexbiehl
authored andcommitted
Quick Jump: Show error when loading 'doc-index.json' failed (#691)
1 parent e41c1cb commit 8e88615

File tree

4 files changed

+34
-14
lines changed

4 files changed

+34
-14
lines changed

haddock-api/resources/html/haddock-bundle.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

haddock-api/resources/html/js-src/quick-jump.tsx

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ import preact = require("preact");
33

44
const { h, Component } = preact;
55

6-
declare interface ObjectConstructor {
7-
assign(target: any, ...sources: any[]): any;
8-
}
9-
106
type DocItem = {
117
display_html: string
128
name: string
@@ -19,8 +15,13 @@ function loadJSON(path: string, success: (json: DocItem[]) => void, error: (xhr:
1915
xhr.onreadystatechange = () => {
2016
if (xhr.readyState === XMLHttpRequest.DONE) {
2117
if (xhr.status === 200) {
22-
if (success)
23-
success(JSON.parse(xhr.responseText));
18+
if (success) {
19+
try {
20+
success(JSON.parse(xhr.responseText));
21+
} catch (exc) {
22+
error(xhr);
23+
}
24+
}
2425
} else {
2526
if (error) { error(xhr); }
2627
}
@@ -218,7 +219,19 @@ class QuickJump extends Component<QuickJumpProps, QuickJumpState> {
218219
}
219220

220221
render(props: any, state: QuickJumpState) {
221-
if (state.failedLoading) { return null; }
222+
if (state.failedLoading) {
223+
const usingFileProtocol = window.location.protocol == 'file:';
224+
return <div id="search" class={state.isVisible ? '' : 'hidden'}>
225+
<div id="search-results">
226+
<p class="error">Failed to load file 'doc-index.json' containing definitions in this package.</p>
227+
{usingFileProtocol ? <p class="error">
228+
To use quick jump, load this page with HTTP (from a local static file web server) instead of using the <code>file://</code> protocol.
229+
(For security reasons, it is not possible to fetch auxiliary files using JS in a HTML page opened with <code>file://</code>.)
230+
</p> : []
231+
}
232+
</div>
233+
</div>;
234+
}
222235

223236
this.linkIndex = 0;
224237

haddock-api/resources/html/quick-jump.css

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,24 @@
3333
outline: none;
3434
}
3535

36+
#search p.error {
37+
color: rgb(107, 24, 24);
38+
font-weight: bold;
39+
}
40+
3641
#search-results {
37-
top: 3em;
38-
max-height: calc(100% - 3em);
3942
box-sizing: border-box;
40-
border-width: 0 0.05em 0.05em;
41-
border-style: solid;
42-
border-color: #b2d5fb;
43+
border: 0.05em solid #b2d5fb;
4344
background: #e8f3ff;
4445
overflow-y: auto;
4546
}
4647

48+
#search-form input + #search-results {
49+
border-top: none;
50+
top: 3em;
51+
max-height: calc(100% - 3em);
52+
}
53+
4754
/* @end */
4855

4956
/* @group search results */

0 commit comments

Comments
 (0)