aboutsummaryrefslogtreecommitdiff
path: root/haddock-api/resources/html/js-src/quick-jump.tsx
diff options
context:
space:
mode:
authoralexbiehl <alex.biehl@gmail.com>2017-10-31 21:48:55 +0100
committeralexbiehl <alex.biehl@gmail.com>2017-10-31 21:48:55 +0100
commit08c9e19236770811caf571321f5ece271d1fccff (patch)
treebeb3f6407d14abcab32f9d54811cabd319c356a4 /haddock-api/resources/html/js-src/quick-jump.tsx
parent3896bff411596ef50b5ca2f2be425e89878410aa (diff)
parente5fe98530d9c70f5197494da9de07f42dd7fe334 (diff)
Merge remote-tracking branch 'origin/master' into ghc-head
Diffstat (limited to 'haddock-api/resources/html/js-src/quick-jump.tsx')
-rw-r--r--haddock-api/resources/html/js-src/quick-jump.tsx29
1 files changed, 21 insertions, 8 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..97ac14af 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); }
}
@@ -102,7 +103,7 @@ class QuickJump extends Component<QuickJumpProps, QuickJumpState> {
loadJSON(this.props.baseUrl + "/doc-index.json", (data) => {
this.setState({
fuse: new Fuse(data, {
- threshold: 0.4,
+ threshold: 0.25,
caseSensitive: true,
includeScore: true,
tokenize: true,
@@ -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;