diff options
Diffstat (limited to 'haddock-api/resources/html/js-src')
-rw-r--r-- | haddock-api/resources/html/js-src/quick-jump.tsx | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/haddock-api/resources/html/js-src/quick-jump.tsx b/haddock-api/resources/html/js-src/quick-jump.tsx index 20ff8e15..ef02cbd2 100644 --- a/haddock-api/resources/html/js-src/quick-jump.tsx +++ b/haddock-api/resources/html/js-src/quick-jump.tsx @@ -45,11 +45,12 @@ class PageMenuButton extends Component<any, any> { } -function addSearchPageMenuButton(action: () => void) { - const pageMenu = document.querySelector('#page-menu') as HTMLUListElement; - const dummy = document.createElement('li'); - pageMenu.insertBefore(dummy, pageMenu.firstChild); - preact.render(<PageMenuButton onClick={action} title="Quick Jump" />, pageMenu, dummy); +function addSearchPageMenuButton(quickJumpButton: HTMLLIElement) { + const showHide = function(action: () => void) { + const pageMenu = document.querySelector('#page-menu') as HTMLUListElement; + preact.render(<PageMenuButton onClick={action} title="Quick Jump" />, pageMenu, quickJumpButton); + }; + return showHide; } // -------------------------------------------------------------------------- // @@ -410,10 +411,14 @@ function NoResultsMsg(props: { searchString: string }) { } export function init(docBaseUrl?: string, showHide?: (action: () => void) => void) { - preact.render( - <QuickJump baseUrl={docBaseUrl || "."} showHideTrigger={showHide || addSearchPageMenuButton} />, - document.body - ); + // A <li> element with this id should exist if --quickjump was set + const quickJumpButton = document.getElementById('quick-jump-button'); + if (quickJumpButton) + preact.render( + <QuickJump baseUrl={docBaseUrl || "."} showHideTrigger={showHide || + addSearchPageMenuButton(quickJumpButton as HTMLLIElement)} />, + document.body + ); } // export to global object |