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

Commit fafedd9

Browse files
mpilgremmergify[bot]
authored andcommitted
Fix #783 Don't show button if --quickjump not present
1 parent 4f53694 commit fafedd9

File tree

6 files changed

+85
-36
lines changed

6 files changed

+85
-36
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: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@ class PageMenuButton extends Component<any, any> {
4545

4646
}
4747

48-
function addSearchPageMenuButton(action: () => void) {
49-
const pageMenu = document.querySelector('#page-menu') as HTMLUListElement;
50-
const dummy = document.createElement('li');
51-
pageMenu.insertBefore(dummy, pageMenu.firstChild);
52-
preact.render(<PageMenuButton onClick={action} title="Quick Jump" />, pageMenu, dummy);
48+
function addSearchPageMenuButton(quickJumpButton: HTMLLIElement) {
49+
const showHide = function(action: () => void) {
50+
const pageMenu = document.querySelector('#page-menu') as HTMLUListElement;
51+
preact.render(<PageMenuButton onClick={action} title="Quick Jump" />, pageMenu, quickJumpButton);
52+
};
53+
return showHide;
5354
}
5455

5556
// -------------------------------------------------------------------------- //
@@ -410,10 +411,14 @@ function NoResultsMsg(props: { searchString: string }) {
410411
}
411412

412413
export function init(docBaseUrl?: string, showHide?: (action: () => void) => void) {
413-
preact.render(
414-
<QuickJump baseUrl={docBaseUrl || "."} showHideTrigger={showHide || addSearchPageMenuButton} />,
415-
document.body
416-
);
414+
// A <li> element with this id should exist if --quickjump was set
415+
const quickJumpButton = document.getElementById('quick-jump-button');
416+
if (quickJumpButton)
417+
preact.render(
418+
<QuickJump baseUrl={docBaseUrl || "."} showHideTrigger={showHide ||
419+
addSearchPageMenuButton(quickJumpButton as HTMLLIElement)} />,
420+
document.body
421+
);
417422
}
418423

419424
// export to global object

haddock-api/resources/html/package-lock.json

Lines changed: 30 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

haddock-api/resources/html/quick-jump.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/src/Haddock.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ render dflags flags sinceQual qual ifaces installedIfaces extSrcMap = do
372372
_ <- {-# SCC ppHtmlIndex #-}
373373
ppHtmlIndex odir title pkgStr
374374
themes opt_mathjax opt_contents_url sourceUrls' opt_wiki_urls
375+
withQuickjump
375376
allVisibleIfaces pretty
376377
return ()
377378

@@ -382,6 +383,7 @@ render dflags flags sinceQual qual ifaces installedIfaces extSrcMap = do
382383
_ <- {-# SCC ppHtmlContents #-}
383384
ppHtmlContents dflags' odir title pkgStr
384385
themes opt_mathjax opt_index_url sourceUrls' opt_wiki_urls
386+
withQuickjump
385387
allVisibleIfaces True prologue pretty
386388
sincePkg (makeContentsQual qual)
387389
return ()

haddock-api/src/Haddock/Backends/Xhtml.hs

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,15 @@ ppHtml dflags doctitle maybe_package ifaces reexported_ifaces odir prologue
8888
when (isNothing maybe_contents_url) $
8989
ppHtmlContents dflags odir doctitle maybe_package
9090
themes maybe_mathjax_url maybe_index_url maybe_source_url maybe_wiki_url
91+
withQuickjump
9192
(map toInstalledIface visible_ifaces ++ reexported_ifaces)
9293
False -- we don't want to display the packages in a single-package contents
9394
prologue debug pkg (makeContentsQual qual)
9495

9596
when (isNothing maybe_index_url) $ do
9697
ppHtmlIndex odir doctitle maybe_package
9798
themes maybe_mathjax_url maybe_contents_url maybe_source_url maybe_wiki_url
99+
withQuickjump
98100
(map toInstalledIface visible_ifaces ++ reexported_ifaces) debug
99101

100102
when withQuickjump $
@@ -103,7 +105,8 @@ ppHtml dflags doctitle maybe_package ifaces reexported_ifaces odir prologue
103105

104106
mapM_ (ppHtmlModule odir doctitle themes
105107
maybe_mathjax_url maybe_source_url maybe_wiki_url
106-
maybe_contents_url maybe_index_url unicode pkg qual debug) visible_ifaces
108+
maybe_contents_url maybe_index_url withQuickjump
109+
unicode pkg qual debug) visible_ifaces
107110

108111

109112
copyHtmlBits :: FilePath -> FilePath -> Themes -> Bool -> IO ()
@@ -142,6 +145,15 @@ headHtml docTitle themes mathjax_url =
142145
, "}"
143146
, "});" ]
144147

148+
quickJumpButtonLi :: Bool -- ^ With Quick Jump?
149+
-> Maybe Html
150+
-- The TypeScript should replace this <li> element, given its id. However, in
151+
-- case it does not, the element is given content here too.
152+
quickJumpButtonLi True = Just $ li ! [identifier "quick-jump-button"]
153+
<< anchor ! [href "#"] << "Quick Jump"
154+
155+
quickJumpButtonLi False = Nothing
156+
145157
srcButton :: SourceURLs -> Maybe Interface -> Maybe Html
146158
srcButton (Just src_base_url, _, _, _) Nothing =
147159
Just (anchor ! [href src_base_url] << "Source")
@@ -180,20 +192,18 @@ indexButton maybe_index_url
180192
bodyHtml :: String -> Maybe Interface
181193
-> SourceURLs -> WikiURLs
182194
-> Maybe String -> Maybe String
195+
-> Bool -- ^ With Quick Jump?
183196
-> Html -> Html
184197
bodyHtml doctitle iface
185198
maybe_source_url maybe_wiki_url
186199
maybe_contents_url maybe_index_url
200+
withQuickjump
187201
pageContent =
188202
body << [
189203
divPackageHeader << [
190204
nonEmptySectionName << doctitle,
191-
unordList (catMaybes [
192-
srcButton maybe_source_url iface,
193-
wikiButton maybe_wiki_url (ifaceMod <$> iface),
194-
contentsButton maybe_contents_url,
195-
indexButton maybe_index_url])
196-
! [theclass "links", identifier "page-menu"]
205+
ulist ! [theclass "links", identifier "page-menu"]
206+
<< catMaybes (quickJumpButtonLi withQuickjump : otherButtonLis)
197207
],
198208
divContent << pageContent,
199209
divFooter << paragraph << (
@@ -202,6 +212,13 @@ bodyHtml doctitle iface
202212
(" version " ++ projectVersion)
203213
)
204214
]
215+
where
216+
otherButtonLis = (fmap . fmap) (li <<)
217+
[ srcButton maybe_source_url iface
218+
, wikiButton maybe_wiki_url (ifaceMod <$> iface)
219+
, contentsButton maybe_contents_url
220+
, indexButton maybe_index_url
221+
]
205222

206223
moduleInfo :: Interface -> Html
207224
moduleInfo iface =
@@ -267,14 +284,16 @@ ppHtmlContents
267284
-> Maybe String
268285
-> SourceURLs
269286
-> WikiURLs
287+
-> Bool -- ^ With Quick Jump?
270288
-> [InstalledInterface] -> Bool -> Maybe (MDoc GHC.RdrName)
271289
-> Bool
272290
-> Maybe Package -- ^ Current package
273291
-> Qualification -- ^ How to qualify names
274292
-> IO ()
275293
ppHtmlContents dflags odir doctitle _maybe_package
276294
themes mathjax_url maybe_index_url
277-
maybe_source_url maybe_wiki_url ifaces showPkgs prologue debug pkg qual = do
295+
maybe_source_url maybe_wiki_url withQuickjump
296+
ifaces showPkgs prologue debug pkg qual = do
278297
let tree = mkModuleTree dflags showPkgs
279298
[(instMod iface, toInstalledDescription iface)
280299
| iface <- ifaces
@@ -287,7 +306,7 @@ ppHtmlContents dflags odir doctitle _maybe_package
287306
headHtml doctitle themes mathjax_url +++
288307
bodyHtml doctitle Nothing
289308
maybe_source_url maybe_wiki_url
290-
Nothing maybe_index_url << [
309+
Nothing maybe_index_url withQuickjump << [
291310
ppPrologue pkg qual doctitle prologue,
292311
ppSignatureTree pkg qual sig_tree,
293312
ppModuleTree pkg qual tree
@@ -420,11 +439,12 @@ ppHtmlIndex :: FilePath
420439
-> Maybe String
421440
-> SourceURLs
422441
-> WikiURLs
442+
-> Bool -- ^ With Quick Jump?
423443
-> [InstalledInterface]
424444
-> Bool
425445
-> IO ()
426446
ppHtmlIndex odir doctitle _maybe_package themes
427-
maybe_mathjax_url maybe_contents_url maybe_source_url maybe_wiki_url ifaces debug = do
447+
maybe_mathjax_url maybe_contents_url maybe_source_url maybe_wiki_url withQuickjump ifaces debug = do
428448
let html = indexPage split_indices Nothing
429449
(if split_indices then [] else index)
430450

@@ -443,7 +463,7 @@ ppHtmlIndex odir doctitle _maybe_package themes
443463
headHtml (doctitle ++ " (" ++ indexName ch ++ ")") themes maybe_mathjax_url +++
444464
bodyHtml doctitle Nothing
445465
maybe_source_url maybe_wiki_url
446-
maybe_contents_url Nothing << [
466+
maybe_contents_url Nothing withQuickjump << [
447467
if showLetters then indexInitialLetterLinks else noHtml,
448468
if null items then noHtml else
449469
divIndex << [sectionName << indexName ch, buildIndex items]
@@ -541,11 +561,14 @@ ppHtmlIndex odir doctitle _maybe_package themes
541561
ppHtmlModule
542562
:: FilePath -> String -> Themes
543563
-> Maybe String -> SourceURLs -> WikiURLs
544-
-> Maybe String -> Maybe String -> Bool -> Maybe Package -> QualOption
564+
-> Maybe String -> Maybe String
565+
-> Bool -- ^ With Quick Jump?
566+
-> Bool -> Maybe Package -> QualOption
545567
-> Bool -> Interface -> IO ()
546568
ppHtmlModule odir doctitle themes
547569
maybe_mathjax_url maybe_source_url maybe_wiki_url
548-
maybe_contents_url maybe_index_url unicode pkg qual debug iface = do
570+
maybe_contents_url maybe_index_url withQuickjump
571+
unicode pkg qual debug iface = do
549572
let
550573
mdl = ifaceMod iface
551574
aliases = ifaceModuleAliases iface
@@ -565,7 +588,7 @@ ppHtmlModule odir doctitle themes
565588
headHtml mdl_str_annot themes maybe_mathjax_url +++
566589
bodyHtml doctitle (Just iface)
567590
maybe_source_url maybe_wiki_url
568-
maybe_contents_url maybe_index_url << [
591+
maybe_contents_url maybe_index_url withQuickjump << [
569592
divModuleHeader << (moduleInfo iface +++ (sectionName << mdl_str_linked)),
570593
ifaceToHtml maybe_source_url maybe_wiki_url iface unicode pkg real_qual
571594
]

0 commit comments

Comments
 (0)