{-# OPTIONS_GHC -fno-warn-orphans #-}
module WeekDaze.Text.XHTML(
mkShowHideButton,
mkXHTMLDiv,
mkXHTMLSpan
) where
import qualified Text.XHtml.Strict
import Text.XHtml.Strict((!), (<<))
import qualified WeekDaze.Text.CSS as Text.CSS
showHideButtonCSSIdentifier :: Text.CSS.CSSIdentifier
showHideButtonCSSIdentifier = "showHideButton"
instance Text.XHtml.Strict.HTML Int where
toHtml = Text.XHtml.Strict.toHtml . show
mkShowHideButton
:: Bool
-> Text.CSS.CSSIdentifier
-> Text.XHtml.Strict.Html
mkShowHideButton displayState elementIdentifier = Text.XHtml.Strict.button ! [
Text.XHtml.Strict.theclass showHideButtonCSSIdentifier,
Text.XHtml.Strict.strAttr "onclick" . showString "this.innerHTML = ((this.innerHTML !== '" . showString hideLabel . showString "') ? '" . showString hideLabel . showString "' : '" . showString showLabel . showString "'); var element = document.getElementById('" $ showString elementIdentifier "'); element.style.display = ((element.style.display !== 'none') ? 'none' : 'block');"
] << (
if displayState
then hideLabel
else showLabel
) where
hideLabel, showLabel :: String
hideLabel = "Hide"
showLabel = "Show"
mkXHTMLDiv :: String -> Text.XHtml.Strict.Html -> Text.XHtml.Strict.Html
mkXHTMLDiv s = Text.XHtml.Strict.thediv ! [Text.XHtml.Strict.theclass $ Text.CSS.mkIdentifier s, Text.XHtml.Strict.title s]
mkXHTMLSpan :: String -> Text.XHtml.Strict.Html -> Text.XHtml.Strict.Html
mkXHTMLSpan s = Text.XHtml.Strict.thespan ! [Text.XHtml.Strict.theclass $ Text.CSS.mkIdentifier s, Text.XHtml.Strict.title s]