ghcjs-dom-hello 1.1.0.0 → 1.2.0.0
raw patch · 2 files changed
+23/−5 lines, 2 filesdep +mtl
Dependencies added: mtl
Files
- ghcjs-dom-hello.cabal +3/−2
- src/Main.hs +20/−3
ghcjs-dom-hello.cabal view
@@ -1,5 +1,5 @@ name: ghcjs-dom-hello-version: 1.1.0.0+version: 1.2.0.0 cabal-version: >=1.6 build-type: Simple license: MIT@@ -22,7 +22,8 @@ location: https://github.com/ghcjs/ghcjs-dom-hello executable ghcjs-dom-hello- build-depends: base >=4.2 && <5, ghcjs-dom >=0.0.7 && <0.2+ build-depends: mtl >=2.1 && <2.3,+ base >=4.2 && <5, ghcjs-dom >=0.0.7 && <0.2 main-is: Main.hs buildable: True hs-source-dirs: src
src/Main.hs view
@@ -2,11 +2,28 @@ main ) where -import GHCJS.DOM (webViewGetDomDocument, runWebGUI)-import GHCJS.DOM.Document (documentGetBody)-import GHCJS.DOM.HTMLElement (htmlElementSetInnerHTML)+import Control.Applicative ((<$>))+import Control.Monad.Trans (liftIO)+import GHCJS.DOM+ (enableInspector, webViewGetDomDocument, runWebGUI)+import GHCJS.DOM.Document (documentGetBody, documentCreateElement)+import GHCJS.DOM.HTMLElement (htmlElementSetInnerHTML, htmlElementSetInnerText)+import GHCJS.DOM.Element (elementOnclick)+import GHCJS.DOM.HTMLParagraphElement+ (castToHTMLParagraphElement)+import GHCJS.DOM.Node (nodeAppendChild)+import GHCJS.DOM.EventM (mouseClientXY) main = runWebGUI $ \ webView -> do+ enableInspector webView Just doc <- webViewGetDomDocument webView Just body <- documentGetBody doc htmlElementSetInnerHTML body "<h1>Hello World</h1>"+ elementOnclick body $ do+ (x, y) <- mouseClientXY+ liftIO $ do+ Just newParagraph <- fmap castToHTMLParagraphElement <$> documentCreateElement doc "p"+ htmlElementSetInnerText newParagraph $ "Click " ++ show (x, y)+ nodeAppendChild body (Just newParagraph)+ return ()+ return ()