From 8e88615a23a9f1980a55bd1b3ef9dcc938d95237 Mon Sep 17 00:00:00 2001 From: Tim Baumann Date: Tue, 10 Oct 2017 09:50:59 +0200 Subject: Quick Jump: Show error when loading 'doc-index.json' failed (#691) --- haddock-api/resources/html/js-src/quick-jump.tsx | 27 ++++++++++++++++++------ 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'haddock-api/resources/html/js-src') 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 { } render(props: any, state: QuickJumpState) { - if (state.failedLoading) { return null; } + if (state.failedLoading) { + const usingFileProtocol = window.location.protocol == 'file:'; + return ; + } this.linkIndex = 0; -- cgit v1.2.3