Permalink
Browse files

* Added the ThisEventHandler.

  • Loading branch information...
1 parent 457363e commit 006edbcb14861984702d3272f4ef750d4ebc9144 @spockz spockz committed Jan 16, 2012
Showing with 21 additions and 4 deletions.
  1. +21 −4 uhc-jscript/src/Language/UHC/JScript/JQuery/JQuery.hs
@@ -150,19 +150,28 @@ foreign import jscript "%1.blur()"
data JUIPtr
type JUI = JSPtr JUIPtr
+-- ToDo: Probably the second arguments of the ThisEventHandlers and the first
+-- of the EventHandlers should not be a general JQuery object but an
+-- `eventObject'.
+-- Also I probably should deprecate the versions without this as you'll
+-- almost never have use of them...
+
type EventHandler = JQuery -> JEventResult
+type ThisEventHandler = JQuery -> JQuery -> JEventResult
type UIEventHandler = JQuery -> JUI -> JEventResult -- TODO: Split this off to JQueryUI or something :)
type UIThisEventHandler = JQuery -> JQuery -> JUI -> JEventResult
type JEventResult = IO Bool
type JEventHandler = JSFunPtr EventHandler
+type JThisEventHandler = JSFunPtr ThisEventHandler
type JUIEventHandler = JSFunPtr UIEventHandler
type JUIThisEventHandler = JSFunPtr UIThisEventHandler
type JEventType = String
-bind :: JQuery -> JEventType -> JEventHandler -> IO ()
-bind jq event eh = do _bind jq (toJS event) eh
+bind :: JQuery -> JEventType -> EventHandler -> IO ()
+bind jq event eh = do handler <- mkJEventHandler eh
+ _bind jq (toJS event) handler
foreign import jscript "%1.bind(%*)"
_bind :: JQuery -> JSString -> JEventHandler -> IO ()
@@ -172,8 +181,8 @@ blur :: JQuery -> JEventHandler -> IO ()
blur = undefined
-click :: JQuery -> JEventHandler -> IO ()
-click = _click
+click :: JQuery -> EventHandler -> IO ()
+click jq eh = mkJEventHandler eh >>= _click jq
foreign import jscript "%1.click(%2)"
_click :: JQuery -> JEventHandler -> IO ()
@@ -192,6 +201,14 @@ foreign import jscript "$('document').ready(%1)"
foreign import jscript "wrapper"
mkJEventHandler :: EventHandler -> IO JEventHandler
+
+foreign import jscript "wrapper"
+ mkJThisEventHandler :: ThisEventHandler -> IO JThisEventHandler
+
+foreign import jscript "wrappedJQueryEvent(%1)"
+ wrappedJQueryEvent :: JThisEventHandler -> IO JEventHandler
+
+
foreign import jscript "wrapper"
mkJUIEventHandler :: UIEventHandler -> IO JUIEventHandler

0 comments on commit 006edbc

Please sign in to comment.