tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject git commit: TAP5-2353: It should be possible to unregister DOM event listeners
Date Mon, 01 Sep 2014 18:50:10 GMT
Repository: tapestry-5
Updated Branches:
  refs/heads/master 021b23e18 -> 4b0c857b7


TAP5-2353: It should be possible to unregister DOM event listeners


Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/4b0c857b
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/4b0c857b
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/4b0c857b

Branch: refs/heads/master
Commit: 4b0c857b7b08785850b6d399effa53d9aca6a2b0
Parents: 021b23e
Author: Howard M. Lewis Ship <hlship@apache.org>
Authored: Mon Sep 1 11:50:20 2014 -0700
Committer: Howard M. Lewis Ship <hlship@apache.org>
Committed: Mon Sep 1 11:50:20 2014 -0700

----------------------------------------------------------------------
 .../org/apache/tapestry5/t5-core-dom.coffee     | 26 +++++++++++++++-----
 1 file changed, 20 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/4b0c857b/tapestry-core/src/main/preprocessed-coffeescript/org/apache/tapestry5/t5-core-dom.coffee
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/preprocessed-coffeescript/org/apache/tapestry5/t5-core-dom.coffee
b/tapestry-core/src/main/preprocessed-coffeescript/org/apache/tapestry5/t5-core-dom.coffee
index 64bb6cf..cfb5ecc 100644
--- a/tapestry-core/src/main/preprocessed-coffeescript/org/apache/tapestry5/t5-core-dom.coffee
+++ b/tapestry-core/src/main/preprocessed-coffeescript/org/apache/tapestry5/t5-core-dom.coffee
@@ -136,6 +136,8 @@ define ["underscore", "./utils", "./events", "jquery"],
   # Event handlers may return false to stop event propogation; this prevents an event from
bubbling up, and
   # prevents any browser default behavior from triggering.  This is often easier than accepting
the `EventWrapper`
   # object as the first parameter and invoking `stop()`.
+  #
+  # Returns a function of no parameters that removes any added handlers.
 
   onevent = (jqueryObject, eventNames, match, handler) ->
     throw new Error "No event handler was provided." unless handler?
@@ -156,7 +158,8 @@ define ["underscore", "./utils", "./events", "jquery"],
 
     jqueryObject.on eventNames, match, wrapped
 
-    return
+    # Return a function to stop listening
+    -> jqueryObject.off eventNames, match, wrapped
 #elseif prototype
   # Interface between the dom's event model, and Prototype's.
   #
@@ -166,9 +169,11 @@ define ["underscore", "./utils", "./events", "jquery"],
   # * handler - event handler function to invoke; it will be passed an `EventWrapper` instance
as the first parameter,
   #   and the memo as the second parameter. `this` will be the `ElementWrapper` for the matched
element.
   #
-  # Event handlers may return false to stop event propogation; this prevents an event from
bubbling up, and
+  # Event handlers may return false to stop event propagation; this prevents an event from
bubbling up, and
   # prevents any browser default behavior from triggering.  This is often easier than accepting
the `EventWrapper`
   # object as the first parameter and invoking `stop()`.
+  #
+  # Returns a function of no parameters that removes any added handlers.
 
   onevent = (elements, eventNames, match, handler) ->
       throw new Error "No event handler was provided." unless handler?
@@ -191,11 +196,16 @@ define ["underscore", "./utils", "./events", "jquery"],
 
         return
 
+      eventHandlers = []
+
       for element in elements
         for eventName in eventNames
-          Event.on element, eventName, match, wrapped
+          eventHandlers.push (Event.on element, eventName, match, wrapped)
 
-      return
+      # Return a function to remove the handler(s)
+      ->
+        for eventHandler in eventHandlers
+          eventHandler.stop()
 #endif
 
   # Wraps a DOM element, providing some common behaviors.
@@ -610,6 +620,8 @@ define ["underscore", "./utils", "./events", "jquery"],
     #   will invoke the handler.
     # * handler - function invoked; the function is passed an `EventWrapper` object, and
the
     #   context (`this`) is the `ElementWrapper` for the matched element.
+    #
+    # Returns a function of no parameters that removes any added handlers.
     on: (events, match, handler) ->
       exports.on @element, events, match, handler
       return this
@@ -878,7 +890,7 @@ define ["underscore", "./utils", "./events", "jquery"],
 
     ajaxRequest: ajaxRequest
 
-    # Used to add an event handler to an element (possibly from elements below it in the
hierarch).
+    # Used to add an event handler to an element (possibly from elements below it in the
hierarchy).
     #
     # * selector - CSS selector used to select elements to attach handler to; alternately,
     #   a single DOM element, or an array of DOM elements. The document is considered an
element
@@ -889,6 +901,8 @@ define ["underscore", "./utils", "./events", "jquery"],
     #   will invoke the handler.
     # * handler - function invoked; the function is passed an `EventWrapper` object, and
the context (`this`)
     #   is the `ElementWrapper` for the matched element
+    #
+    # Returns a function of no parameters that removes any added handlers.
     on: (selector, events, match, handler) ->
       unless handler?
         handler = match
@@ -901,10 +915,10 @@ define ["underscore", "./utils", "./events", "jquery"],
       events = utils.split events
 #endif
       onevent elements, events, match, handler
-      return
 
     # onDocument() is used to add an event handler to the document object; this is used
     # for global (or default) handlers.
+    # Returns a function of no parameters that removes any added handlers.
     onDocument: (events, match, handler) ->
       exports.on document, events, match, handler
 


Mime
View raw message