{-# LANGUAGE EmptyDataDecls #-} {-# LANGUAGE NoImplicitPrelude #-} -- | The home page script: -- -- 1) Make sure that the language samples are highlighted. -- 2) Add a show/hide button for the JS output on all samples. -- 3) For code samples that are too large, hide them. -- -- Because dogfood. This is not necessarily a good example, indeed, it -- may very well be a very bad example of how to write client -- code. But that's the point, really. Even the quick scripts that -- you'd just whip up in JS should be also done in Fay. Alright? -- module Home (main) where import Language.Fay.FFI import Language.Fay.Prelude -- | Main entry point. main :: Fay () main = do ready (wrap thedocument) $ do indentAndHighlight setupExpanders setupTableOfContents -- | Setup highlighting/code re-indenting. indentAndHighlight :: Fay () indentAndHighlight = do samples <- query ".language-javascript" each samples $ \i this -> let sample = wrap this in do text <- getText sample setText sample (beautify text 2) return True setTabReplace hljs " " initHighlightingOnLoad hljs -- | Setup example expanders. setupExpanders :: Fay () setupExpanders = do wrapwidth <- query ".wrap" >>= getWidth examples <- query ".example" each examples $ \i this -> do tr <- getFind (wrap this) "tr" left <- getFind tr "td" >>= getFirst addClass left "left" right <- getNext left toggle <- makeElement "Show JavaScript" toggleButton <- return $ do visible <- getIs right ":visible" if visible then do setText toggle "Hide JavaScript" swapClasses toggle "toggle-hide" "toggle-show" else do setText toggle "Show JavaScript" swapClasses toggle "toggle-show" "toggle-hide" setClick toggle $ fadeToggle right $ toggleButton width <- getWidth tr when (width > wrapwidth + 20*wrapwidth/100) $ hide right toggleButton panel <- getFind left ".panel" prepend panel toggle return True -- | Generate a table of contents. setupTableOfContents :: Fay () setupTableOfContents = do toc <- makeElement "
Table of Contents