packages feed

fay-dom 0.3 → 0.4

raw patch · 4 files changed

+46/−47 lines, 4 filesdep +fay-textdep ~fay-basePVP ok

version bump matches the API change (PVP)

Dependencies added: fay-text

Dependency ranges changed: fay-base

API changes (from Hackage documentation)

- DOM: void :: Fay a -> Fay ()
- DOM: addClass :: Element -> String -> Fay ()
+ DOM: addClass :: Element -> Text -> Fay ()
- DOM: addEvent :: String -> Fay f -> Fay ()
+ DOM: addEvent :: Text -> Fay f -> Fay ()
- DOM: createElement :: String -> Fay Element
+ DOM: createElement :: Text -> Fay Element
- DOM: createTextNode :: String -> Fay Element
+ DOM: createTextNode :: Text -> Fay Element
- DOM: getAttr :: Element -> String -> Fay String
+ DOM: getAttr :: Element -> Text -> Fay Text
- DOM: getCurrentUrl :: Fay String
+ DOM: getCurrentUrl :: Fay Text
- DOM: getElementById :: String -> Fay Element
+ DOM: getElementById :: Text -> Fay Element
- DOM: getElementsByName :: String -> Fay [Element]
+ DOM: getElementsByName :: Text -> Fay [Element]
- DOM: getRadioValue :: String -> Fay String
+ DOM: getRadioValue :: Text -> Fay Text
- DOM: getTextData :: Element -> Fay String
+ DOM: getTextData :: Element -> Fay Text
- DOM: getValue :: Element -> Fay String
+ DOM: getValue :: Element -> Fay Text
- DOM: hasAttr :: Element -> String -> Fay Bool
+ DOM: hasAttr :: Element -> Text -> Fay Bool
- DOM: hasClass :: Element -> String -> Fay Bool
+ DOM: hasClass :: Element -> Text -> Fay Bool
- DOM: klass :: Element -> String -> Fay ()
+ DOM: klass :: Element -> Text -> Fay ()
- DOM: logS :: String -> Fay ()
+ DOM: logS :: Text -> Fay ()
- DOM: open :: RequestMethod -> String -> XMLHttpRequest -> Fay XMLHttpRequest
+ DOM: open :: RequestMethod -> Text -> XMLHttpRequest -> Fay XMLHttpRequest
- DOM: parseInt :: String -> Fay Int
+ DOM: parseInt :: Text -> Fay Int
- DOM: removeClass :: Element -> String -> Fay ()
+ DOM: removeClass :: Element -> Text -> Fay ()
- DOM: removeEvent :: Element -> String -> (Event -> Fay f) -> Fay ()
+ DOM: removeEvent :: Element -> Text -> (Event -> Fay f) -> Fay ()
- DOM: responseText :: XMLHttpRequest -> Fay String
+ DOM: responseText :: XMLHttpRequest -> Fay Text
- DOM: setAttr :: Element -> String -> String -> Fay ()
+ DOM: setAttr :: Element -> Text -> Text -> Fay ()
- DOM: setRadioValue :: String -> String -> Fay ()
+ DOM: setRadioValue :: Text -> Text -> Fay ()
- DOM: setTextData :: Element -> String -> Fay ()
+ DOM: setTextData :: Element -> Text -> Fay ()
- DOM: setValue :: Element -> String -> Fay ()
+ DOM: setValue :: Element -> Text -> Fay ()
- DOM: toggleClass :: Element -> String -> Fay ()
+ DOM: toggleClass :: Element -> Text -> Fay ()

Files

+ CHANGELOG.md view
@@ -0,0 +1,3 @@+# 0.4++* Changed to use fay-text instead of String (Willem van den Ende)
README.md view
@@ -10,24 +10,19 @@ Usage ----- -```-git clone git://github.com/bergmark/fay-dom.git-cd fay-dom-cabal install-```+Just install it with cabal: -The library is now installed in your cabal directory and can be seen-in haskell-mode auto-completion and such. To use this with Fay, use the `--include` flag:+    $ cabal install fay-dom -```-fay --include=~/.cabal/share/fay-dom-0.1.0.0/src myfile.hs-```+Then include it at the top of your `file.hs`: -To typecheck `myfile.hs` with ghc, do:+    import DOM -```-ghc ~/.cabal/share/fay-dom-0.1.0.0/src/ myfile.hs-```+fay-dom uses [fay-text](http://www.github.com/faylang/fay-text) so you probably want to enable `OverloadedStrings` and `RebindableSyntax` when using this package.++Finally, build the javascript including the package, as explained on [the wiki](https://github.com/faylang/fay/wiki/Package-management-with-Cabal):++    $ fay --package fay-text,fay-dom file.hs  Development Status ------------------
fay-dom.cabal view
@@ -1,5 +1,5 @@ name:                fay-dom-version:             0.3+version:             0.4 synopsis:            DOM FFI wrapper library for Fay description:         DOM FFI wrapper library for Fay homepage:            https://github.com/faylang/fay-dom@@ -15,6 +15,7 @@ extra-source-files:   LICENSE   README.md+  CHANGELOG.md data-files:          src/DOM.hs  source-repository head@@ -26,4 +27,6 @@   hs-source-dirs: src   exposed-modules: DOM   ghc-options: -Wall-  build-depends: fay-base >= 0.14.1.0+  build-depends:+    fay-base == 0.19.*,+    fay-text == 0.3.*
src/DOM.hs view
@@ -1,5 +1,6 @@-{-# LANGUAGE EmptyDataDecls    #-}-+{-# LANGUAGE EmptyDataDecls #-}+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE RebindableSyntax #-} -- | Document object model functions. Most of this doesn't have -- anything to do with the DOM and is actually ECMA library stuff, but -- I'll leave it in for now.@@ -8,6 +9,7 @@  import FFI import Prelude+import Fay.Text  -------------------------------------------------------------------------------- -- Foreign Data Declarations.@@ -32,16 +34,16 @@ getBody :: Fay Element getBody = ffi "document.body" -getElementById :: String -> Fay Element+getElementById :: Text -> Fay Element getElementById = ffi "document['getElementById'](%1)" -getElementsByName :: String -> Fay [Element]+getElementsByName :: Text -> Fay [Element] getElementsByName = ffi "document['getElementsByName'](%1)" -addEvent :: String -> Fay f -> Fay ()+addEvent :: Text -> Fay f -> Fay () addEvent = ffi "window['addEventListener'](%1,%2)" -removeEvent :: Element -> String -> (Event -> Fay f) -> Fay ()+removeEvent :: Element -> Text -> (Event -> Fay f) -> Fay () removeEvent = ffi "%1['removeEventListener'](%2, %3)"  --------------------------------------------------------------------------------@@ -56,7 +58,7 @@ -------------------------------------------------------------------------------- -- Element accessors. -createElement :: String -> Fay Element+createElement :: Text -> Fay Element createElement = ffi "window['document']['createElement'](%1)"  appendChild :: Element -> Element -> Fay ()@@ -109,15 +111,15 @@   -- Text nodes require special handling-createTextNode :: String -> Fay Element+createTextNode :: Text -> Fay Element createTextNode = ffi "document['createTextNode'](%1)"  -- Get/Set the text for the text node-getTextData :: Element -> Fay String+getTextData :: Element -> Fay Text getTextData = ffi "%1['data']"  -- NOTE: This can only be run on text elements-setTextData :: Element -> String -> Fay ()+setTextData :: Element -> Text -> Fay () setTextData = ffi "%1['data'] = %2"  clearInnerHtml :: Element -> Fay ()@@ -126,31 +128,31 @@ -- Adding, Removing, and Testing for classes -- This only works in modern browsers -- https://developer.mozilla.org/en-US/docs/DOM/element.classList-klass :: Element -> String -> Fay ()+klass :: Element -> Text -> Fay () klass = addClass -addClass :: Element -> String -> Fay ()+addClass :: Element -> Text -> Fay () addClass = ffi "%1.classList['add'](%2)" -removeClass :: Element -> String -> Fay ()+removeClass :: Element -> Text -> Fay () removeClass = ffi "%1['classList']['remove'](%2)" -toggleClass :: Element -> String -> Fay ()+toggleClass :: Element -> Text -> Fay () toggleClass = ffi "%1['classList']['toggle'](%2)" -hasClass :: Element -> String -> Fay Bool+hasClass :: Element -> Text -> Fay Bool hasClass = ffi "%1['classList']['contains'](%2)"  -------------------------------------------------------------------------------- -- Attributes -setAttr :: Element -> String -> String -> Fay ()+setAttr :: Element -> Text -> Text -> Fay () setAttr = ffi "%1['setAttribute'](%2, %3)" -getAttr :: Element -> String -> Fay String+getAttr :: Element -> Text -> Fay Text getAttr = ffi "%1['getAttribute'](%2)" -hasAttr :: Element -> String -> Fay Bool+hasAttr :: Element -> Text -> Fay Bool hasAttr = ffi "%1['hasAttribute'](%2)"  @@ -159,10 +161,10 @@  -- Get/Set the value for a textfields/textarea/hidden/password input -- On checkboxes, this is the value that is sent to the server-getValue :: Element -> Fay String+getValue :: Element -> Fay Text getValue = ffi "%1['value']" -setValue :: Element -> String -> Fay ()+setValue :: Element -> Text -> Fay () setValue = ffi "%1['value'] = %2"  -- Get/Set the checked status for checkbox@@ -173,7 +175,7 @@ setChecked = ffi "%1['checked'] = %2"  -- Get the selected value of a radio group-getRadioValue :: String -> Fay String+getRadioValue :: Text -> Fay Text getRadioValue = ffi "\   \(function(name) {\   \  var i, rs = document.getElementsByName(name);\@@ -187,7 +189,7 @@   \})(%1)"  -- Set the value of a radio group-setRadioValue :: String -> String -> Fay ()+setRadioValue :: Text -> Text -> Fay () setRadioValue = ffi "\   \(function(name, val) {\   \  var i, rs = document.getElementsByName(name);\@@ -204,14 +206,14 @@ -- Location  -- Get current URL-getCurrentUrl :: Fay String+getCurrentUrl :: Fay Text getCurrentUrl = ffi "window['location']['href']"   -------------------------------------------------------------------------------- -- Logging -logS :: String -> Fay ()+logS :: Text -> Fay () logS = ffi "console['log'](%1)"  logF :: f -> Fay ()@@ -247,7 +249,7 @@ xmlHttpRequest :: Fay XMLHttpRequest xmlHttpRequest = ffi "(function(window) { if(window['XMLHttpRequest']) return new XMLHttpRequest(); else return new ActiveXObject('Microsoft.XMLHTTP'); })(window)" -open :: RequestMethod -> String -> XMLHttpRequest -> Fay XMLHttpRequest+open :: RequestMethod -> Text -> XMLHttpRequest -> Fay XMLHttpRequest open = ffi "(function(method, url, xhr) { xhr['open'](method['instance'], url, true); return xhr; })(%1, %2, %3)"  send :: XMLHttpRequest -> Fay ()@@ -259,7 +261,7 @@ readyState :: XMLHttpRequest -> Fay ReadyState readyState = ffi "{ instance: ['UNSENT', 'OPENED', 'HEADERS_RECEIVED', 'LOADING', 'DONE'][%1['readyState']] }" -responseText :: XMLHttpRequest -> Fay String+responseText :: XMLHttpRequest -> Fay Text responseText = ffi "%1['responseText']"  status :: XMLHttpRequest -> Fay Int@@ -268,11 +270,8 @@ -------------------------------------------------------------------------------- -- Utility -void :: Fay a -> Fay ()-void m = m >> return ()- -- Read an int-parseInt :: String -> Fay Int+parseInt :: Text -> Fay Int parseInt = ffi "parseInt(%1, 10)"  -- Scroll a dom element into view@@ -286,4 +285,3 @@ -- Scroll the document body to the specified pixel height scrollAbsolute :: Int -> Fay () scrollAbsolute = ffi "window.scrollTo(0,%1)"-