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

Commit 467551d

Browse files
committed
Fix #783 Don't show button if --quickjump not present
1 parent f493817 commit 467551d

File tree

6 files changed

+86
-36
lines changed

6 files changed

+86
-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: 38 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,16 @@ headHtml docTitle themes mathjax_url =
142145
, "}"
143146
, "});" ]
144147

148+
quickJumpButtonLi :: Bool -- ^ With Quick Jump?
149+
-> Maybe Html
150+
-- The TrueScript 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+
157+
145158
srcButton :: SourceURLs -> Maybe Interface -> Maybe Html
146159
srcButton (Just src_base_url, _, _, _) Nothing =
147160
Just (anchor ! [href src_base_url] << "Source")
@@ -180,20 +193,18 @@ indexButton maybe_index_url
180193
bodyHtml :: String -> Maybe Interface
181194
-> SourceURLs -> WikiURLs
182195
-> Maybe String -> Maybe String
196+
-> Bool -- ^ With Quick Jump?
183197
-> Html -> Html
184198
bodyHtml doctitle iface
185199
maybe_source_url maybe_wiki_url
186200
maybe_contents_url maybe_index_url
201+
withQuickjump
187202
pageContent =
188203
body << [
189204
divPackageHeader << [
190205
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"]
206+
ulist ! [theclass "links", identifier "page-menu"]
207+
<< catMaybes (quickJumpButtonLi withQuickjump : otherButtonLis)
197208
],
198209
divContent << pageContent,
199210
divFooter << paragraph << (
@@ -202,6 +213,13 @@ bodyHtml doctitle iface
202213
(" version " ++ projectVersion)
203214
)
204215
]
216+
where
217+
otherButtonLis = (fmap . fmap) (li <<)
218+
[ srcButton maybe_source_url iface
219+
, wikiButton maybe_wiki_url (ifaceMod <$> iface)
220+
, contentsButton maybe_contents_url
221+
, indexButton maybe_index_url
222+
]
205223

206224
moduleInfo :: Interface -> Html
207225
moduleInfo iface =
@@ -267,14 +285,16 @@ ppHtmlContents
267285
-> Maybe String
268286
-> SourceURLs
269287
-> WikiURLs
288+
-> Bool -- ^ With Quick Jump?
270289
-> [InstalledInterface] -> Bool -> Maybe (MDoc GHC.RdrName)
271290
-> Bool
272291
-> Maybe Package -- ^ Current package
273292
-> Qualification -- ^ How to qualify names
274293
-> IO ()
275294
ppHtmlContents dflags odir doctitle _maybe_package
276295
themes mathjax_url maybe_index_url
277-
maybe_source_url maybe_wiki_url ifaces showPkgs prologue debug pkg qual = do
296+
maybe_source_url maybe_wiki_url withQuickjump
297+
ifaces showPkgs prologue debug pkg qual = do
278298
let tree = mkModuleTree dflags showPkgs
279299
[(instMod iface, toInstalledDescription iface)
280300
| iface <- ifaces
@@ -287,7 +307,7 @@ ppHtmlContents dflags odir doctitle _maybe_package
287307
headHtml doctitle themes mathjax_url +++
288308
bodyHtml doctitle Nothing
289309
maybe_source_url maybe_wiki_url
290-
Nothing maybe_index_url << [
310+
Nothing maybe_index_url withQuickjump << [
291311
ppPrologue pkg qual doctitle prologue,
292312
ppSignatureTree pkg qual sig_tree,
293313
ppModuleTree pkg qual tree
@@ -420,11 +440,12 @@ ppHtmlIndex :: FilePath
420440
-> Maybe String
421441
-> SourceURLs
422442
-> WikiURLs
443+
-> Bool -- ^ With Quick Jump?
423444
-> [InstalledInterface]
424445
-> Bool
425446
-> IO ()
426447
ppHtmlIndex odir doctitle _maybe_package themes
427-
maybe_mathjax_url maybe_contents_url maybe_source_url maybe_wiki_url ifaces debug = do
448+
maybe_mathjax_url maybe_contents_url maybe_source_url maybe_wiki_url withQuickjump ifaces debug = do
428449
let html = indexPage split_indices Nothing
429450
(if split_indices then [] else index)
430451

@@ -443,7 +464,7 @@ ppHtmlIndex odir doctitle _maybe_package themes
443464
headHtml (doctitle ++ " (" ++ indexName ch ++ ")") themes maybe_mathjax_url +++
444465
bodyHtml doctitle Nothing
445466
maybe_source_url maybe_wiki_url
446-
maybe_contents_url Nothing << [
467+
maybe_contents_url Nothing withQuickjump << [
447468
if showLetters then indexInitialLetterLinks else noHtml,
448469
if null items then noHtml else
449470
divIndex << [sectionName << indexName ch, buildIndex items]
@@ -541,11 +562,14 @@ ppHtmlIndex odir doctitle _maybe_package themes
541562
ppHtmlModule
542563
:: FilePath -> String -> Themes
543564
-> Maybe String -> SourceURLs -> WikiURLs
544-
-> Maybe String -> Maybe String -> Bool -> Maybe Package -> QualOption
565+
-> Maybe String -> Maybe String
566+
-> Bool -- ^ With Quick Jump?
567+
-> Bool -> Maybe Package -> QualOption
545568
-> Bool -> Interface -> IO ()
546569
ppHtmlModule odir doctitle themes
547570
maybe_mathjax_url maybe_source_url maybe_wiki_url
548-
maybe_contents_url maybe_index_url unicode pkg qual debug iface = do
571+
maybe_contents_url maybe_index_url withQuickjump
572+
unicode pkg qual debug iface = do
549573
let
550574
mdl = ifaceMod iface
551575
aliases = ifaceModuleAliases iface
@@ -565,7 +589,7 @@ ppHtmlModule odir doctitle themes
565589
headHtml mdl_str_annot themes maybe_mathjax_url +++
566590
bodyHtml doctitle (Just iface)
567591
maybe_source_url maybe_wiki_url
568-
maybe_contents_url maybe_index_url << [
592+
maybe_contents_url maybe_index_url withQuickjump << [
569593
divModuleHeader << (moduleInfo iface +++ (sectionName << mdl_str_linked)),
570594
ifaceToHtml maybe_source_url maybe_wiki_url iface unicode pkg real_qual
571595
]

0 commit comments

Comments
 (0)