@@ -26,6 +26,7 @@ import Halogen.VDom.Driver (runUI)
2626import MarkdownIt as MD
2727import Web.DOM.ChildNode as ChildNode
2828import Web.DOM.Document as Document
29+ import Web.DOM.Document (Document )
2930import Web.DOM.Element as Element
3031import Web.DOM.Node as Node
3132import Web.DOM.ParentNode as ParentNode
@@ -41,12 +42,11 @@ import Web.HTML.Window as Window
4142
4243main :: Effect Unit
4344main = do
44- win <- HTML .window
45- doc <- HTMLDocument .toDocument <$> Window .document win
45+ window <- HTML .window
4646
47- insertStyle doc
48- insertVersionInfo doc
49- mbContainers <- getContainers doc
47+ insertStyle
48+ insertVersionInfo
49+ mbContainers <- getContainers
5050
5151 -- Initialize a `markdown-it` instance (we need it to render the docs as markdown)
5252 markdownIt <- MD .newMarkdownIt MD.Default mempty
@@ -100,7 +100,7 @@ main = do
100100 launchAff_ do
101101 sfio.query $ H .tell SearchField.ReadURIHash
102102
103- addEventListener hashchange listener true (Window .toEventTarget win )
103+ addEventListener hashchange listener true (Window .toEventTarget window )
104104
105105 sbio <- do
106106 component <- Sidebar .mkComponent moduleIndex isIndexHTML meta
@@ -114,11 +114,13 @@ main = do
114114 launchAff_ do
115115 sbio.query $ H .tell Sidebar.UpdateModuleGrouping
116116
117- addEventListener focus listener true (Window .toEventTarget win )
117+ addEventListener focus listener true (Window .toEventTarget window )
118118
119119
120- insertStyle :: Document.Document -> Effect Unit
121- insertStyle doc = do
120+ insertStyle :: Effect Unit
121+ insertStyle = do
122+ doc <- getDocument
123+
122124 let styleContents = """
123125 .top-banner__actions {
124126 width: 10%;
@@ -183,8 +185,9 @@ insertStyle doc = do
183185 void $ Node .appendChild (Element .toNode style) (Element .toNode head)
184186
185187
186- insertVersionInfo :: Document.Document -> Effect Unit
187- insertVersionInfo doc = do
188+ insertVersionInfo :: Effect Unit
189+ insertVersionInfo = do
190+ doc <- getDocument
188191 let docPN = Document .toParentNode doc
189192 mbVersionInfo <-
190193 ParentNode .querySelector (wrap " .footer > p" ) docPN
@@ -206,15 +209,15 @@ insertVersionInfo doc = do
206209-- | Query the DOM for specific elements that should always be present and determine if we are on
207210-- | `index.html` or not.
208211getContainers
209- :: Document.Document
210- -> Effect (Maybe { searchField :: HTML.HTMLElement
212+ :: Effect (Maybe { searchField :: HTML.HTMLElement
211213 , searchResults :: HTML.HTMLElement
212214 , pageContents :: Element.Element
213215 , sidebarContainer :: HTML.HTMLElement
214216 , realSidebar :: Element.Element
215217 , isIndexHTML :: Sidebar.IsIndexHTML
216218 } )
217- getContainers doc = do
219+ getContainers = do
220+ doc <- getDocument
218221 let docPN = Document .toParentNode doc
219222 mbBanner <-
220223 ParentNode .querySelector (wrap " .top-banner > .container" ) docPN
@@ -250,3 +253,7 @@ getContainers doc = do
250253 , isIndexHTML
251254 }
252255 | otherwise -> pure Nothing
256+
257+
258+ getDocument :: Effect Document
259+ getDocument = HTML .window >>= map HTMLDocument .toDocument <<< Window .document
0 commit comments