diff options
author | Tim Baumann <tim@timbaumann.info> | 2017-10-10 09:50:59 +0200 |
---|---|---|
committer | Alexander Biehl <alexbiehl@gmail.com> | 2017-10-10 09:50:59 +0200 |
commit | 8e88615a23a9f1980a55bd1b3ef9dcc938d95237 (patch) | |
tree | 6a6ea36ca276663abb0cd4930a2e5c6f8272f460 /haddock-api/resources/html/js-src | |
parent | e41c1cbe9f0476997eac7b4a3f17cbc6b2262faf (diff) |
Quick Jump: Show error when loading 'doc-index.json' failed (#691)
Diffstat (limited to 'haddock-api/resources/html/js-src')
-rw-r--r-- | haddock-api/resources/html/js-src/quick-jump.tsx | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/haddock-api/resources/html/js-src/quick-jump.tsx b/haddock-api/resources/html/js-src/quick-jump.tsx index a2bcdb64..b15ac4e8 100644 --- a/haddock-api/resources/html/js-src/quick-jump.tsx +++ b/haddock-api/resources/html/js-src/quick-jump.tsx @@ -3,10 +3,6 @@ import preact = require("preact"); const { h, Component } = preact; -declare interface ObjectConstructor { - assign(target: any, ...sources: any[]): any; -} - type DocItem = { display_html: string name: string @@ -19,8 +15,13 @@ function loadJSON(path: string, success: (json: DocItem[]) => void, error: (xhr: xhr.onreadystatechange = () => { if (xhr.readyState === XMLHttpRequest.DONE) { if (xhr.status === 200) { - if (success) - success(JSON.parse(xhr.responseText)); + if (success) { + try { + success(JSON.parse(xhr.responseText)); + } catch (exc) { + error(xhr); + } + } } else { if (error) { error(xhr); } } @@ -218,7 +219,19 @@ class QuickJump extends Component<QuickJumpProps, QuickJumpState> { } render(props: any, state: QuickJumpState) { - if (state.failedLoading) { return null; } + if (state.failedLoading) { + const usingFileProtocol = window.location.protocol == 'file:'; + return <div id="search" class={state.isVisible ? '' : 'hidden'}> + <div id="search-results"> + <p class="error">Failed to load file 'doc-index.json' containing definitions in this package.</p> + {usingFileProtocol ? <p class="error"> + To use quick jump, load this page with HTTP (from a local static file web server) instead of using the <code>file://</code> protocol. + (For security reasons, it is not possible to fetch auxiliary files using JS in a HTML page opened with <code>file://</code>.) + </p> : [] + } + </div> + </div>; + } this.linkIndex = 0; |