packages feed

ghcjs-dom-hello 2.0.0.0 → 3.0.0.0

raw patch · 2 files changed

+40/−23 lines, 2 filesdep ~ghcjs-dom

Dependency ranges changed: ghcjs-dom

Files

ghcjs-dom-hello.cabal view
@@ -1,5 +1,5 @@ name: ghcjs-dom-hello-version: 2.0.0.0+version: 3.0.0.0 cabal-version: >=1.6 build-type: Simple license: MIT@@ -10,21 +10,22 @@ homepage: https://github.com/ghcjs/ghcjs-dom-hello bug-reports: https://github.com/ghcjs/ghcjs-dom-hello/issues synopsis: GHCJS DOM Hello World, an example package-description: This is an implementation of the classic "Hello World" program using GHCJS DOM,-             as an example of how to create a minimal GHCJS DOM application.-             Please submit any suggestions and improvements.+description:+    This is an implementation of the classic "Hello World" program using GHCJS DOM,+    as an example of how to create a minimal GHCJS DOM application.+    Please submit any suggestions and improvements. category: Web author: Hamish Mackenzie-data-dir: ""  source-repository head     type: git     location: https://github.com/ghcjs/ghcjs-dom-hello  executable ghcjs-dom-hello-    build-depends: mtl >=2.1 && <2.3,-                   base >=4.2 && <5,-                   ghcjs-dom >=0.2 && <0.3     main-is: Main.hs-    buildable: True+    build-depends:+        mtl >=2.1 && <2.3,+        base >=4.2 && <5,+        ghcjs-dom >=0.4 && <0.5     hs-source-dirs: src+
src/Main.hs view
@@ -2,26 +2,42 @@     main ) where -import Control.Applicative ((<$>))-import GHCJS.DOM-       (enableInspector, webViewGetDomDocument, runWebGUI)-import GHCJS.DOM.Document (getBody, createElement, click)-import GHCJS.DOM.HTMLElement (setInnerText)+import Control.Monad.IO.Class (MonadIO(..))+import Control.Concurrent.MVar (takeMVar, putMVar, newEmptyMVar)++import GHCJS.DOM (run, syncPoint, currentDocument)+import GHCJS.DOM.Document (getBody, createElement, createTextNode) import GHCJS.DOM.Element (setInnerHTML)-import GHCJS.DOM.HTMLParagraphElement-       (castToHTMLParagraphElement) import GHCJS.DOM.Node (appendChild) import GHCJS.DOM.EventM (on, mouseClientXY)+import qualified GHCJS.DOM.Document as D (click)+import qualified GHCJS.DOM.Element as E (click) -main = runWebGUI $ \ webView -> do-    enableInspector webView-    Just doc <- webViewGetDomDocument webView+main = run 3708 $ do+    Just doc <- currentDocument     Just body <- getBody doc-    setInnerHTML body (Just "<h1>Hello World</h1>")-    on doc click $ do+    setInnerHTML body (Just "<h1>Kia ora (Hi)</h1>")+    on doc D.click $ do         (x, y) <- mouseClientXY-        Just newParagraph <- fmap castToHTMLParagraphElement <$> createElement doc (Just "p")-        setInnerText newParagraph $ Just $ "Click " ++ show (x, y)+        Just newParagraph <- createElement doc (Just "p")+        text <- createTextNode doc $ "Click " ++ show (x, y)+        appendChild newParagraph text         appendChild body (Just newParagraph)         return ()++    -- Make an exit button+    exitMVar <- liftIO newEmptyMVar+    Just exit <- createElement doc (Just "span")+    text <- createTextNode doc "Click here to exit"+    appendChild exit text+    appendChild body (Just exit)+    on exit E.click $ liftIO $ putMVar exitMVar ()++    -- Force all all the lazy evaluation to be executed+    syncPoint++    -- In GHC compiled version the WebSocket connection will end when this+    -- thread ends.  So we will wait until the user clicks exit.+    liftIO $ takeMVar exitMVar+    setInnerHTML body (Just "<h1>Ka kite ano (See you later)</h1>")     return ()