module DomDemo where import UnsafeJS import Control.Monad.JS import DOM.Level1.Dom import DOM.Level1.Html import DOM.Level1.Node import DOM.Level1.Document import DOM.Level1.HTMLDocument import DOM.Level1.HTMLElement as E import DOM.Level1.HTMLBodyElement import DOM.Level1.HTMLImageElement import CDOM.Level1.DomUtils putStatus :: a -> JS a putStatus a = return (putStatus' a) putStatus' a = unsafeJS "window.status=exprEval(a).toString();return a;" body :: (Monad mn, JSpecM mn, CHTMLDocument a) => a -> mn THTMLBodyElement body = get'body mkDiv :: (Monad mn, JSpecM mn, CHTMLDocument a) => a -> mn THTMLDivElement mkDiv = flip createElement "div" mkImage :: (Monad mn, JSpecM mn, CHTMLDocument a) => a -> mn THTMLImageElement mkImage = flip createElement "img" mkText :: (Monad mn, JSpecM mn, CHTMLDocument a) => a -> String -> mn TText mkText = createTextNode main :: JS () main = do doc <- getHTMLDocument dbody <- body doc >>= set'bgColor "lightblue" mydiv <- mkDiv doc al <- get'bgColor dbody tn <- mkText doc $ "|" ++ al ++ "| " ++ "Hello World" img <- mkImage doc >>= set'src "http://www.golubovsky.org/images/linux.tux_02.gif" >>= set'alt "A Symbol of Linux" >>= E.set'title "Linux" -- conflicts with document's title z <- appendChild mydiv tn :: (JS TNode) x <- appendChild dbody mydiv :: (JS TNode) t <- appendChild dbody img :: (JS TNode) return ()