You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2012/08/14 03:33:15 UTC

[11/11] git commit: Set this to be the matched element's ElementWrapper when invoking an event handler function

Set this to be the matched element's ElementWrapper when invoking an event handler function


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

Branch: refs/heads/5.4-js-rewrite
Commit: c7ba52c4778ae3727817b9891b26b8042886f7be
Parents: 01d7fbe
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Mon Aug 13 13:36:00 2012 -0700
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Mon Aug 13 13:36:00 2012 -0700

----------------------------------------------------------------------
 .../coffeescript/META-INF/modules/core/spi.coffee  |   11 +++++++----
 .../integration/app1/pages/test-spi.coffee         |    2 +-
 2 files changed, 8 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/c7ba52c4/tapestry-core/src/main/coffeescript/META-INF/modules/core/spi.coffee
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/coffeescript/META-INF/modules/core/spi.coffee b/tapestry-core/src/main/coffeescript/META-INF/modules/core/spi.coffee
index 9fe5e47..26c12d5 100644
--- a/tapestry-core/src/main/coffeescript/META-INF/modules/core/spi.coffee
+++ b/tapestry-core/src/main/coffeescript/META-INF/modules/core/spi.coffee
@@ -112,15 +112,18 @@ define ["_", "prototype"], (_) ->
   # * elements - array of DOM elements
   # * eventNames - array of event names
   # * match - selector to match bubbled elements, or null
-  # * handler - event handler function to invoke; it will be passed an EventWrapper instance
+  # * 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.
   class EventHandler
     constructor: (elements, eventNames, match, handler) ->
       throw new Error("No event handler was provided.") unless handler?
 
       wrapped = (prototypeEvent) ->
-        # Set `this` to be the matched element (jQuery style), rather than
-        # the element on which the event is observed.
-        handler.call(prototypeEvent.findElement(), new EventWrapper prototypeEvent)
+        # Set `this` to be the matched ElementWrapper, rather than the element on which the event is observed.
+        elementWrapper = new ElementWrapper prototypeEvent.findElement()
+        eventWrapper = new EventWrapper prototypeEvent
+
+        handler.call elementWrapper, eventWrapper, eventWrapper.memo
 
       # Prototype Event.Handler instances
       @protoHandlers = []

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/c7ba52c4/tapestry-core/src/test/coffeescript/org/apache/tapestry5/integration/app1/pages/test-spi.coffee
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/coffeescript/org/apache/tapestry5/integration/app1/pages/test-spi.coffee b/tapestry-core/src/test/coffeescript/org/apache/tapestry5/integration/app1/pages/test-spi.coffee
index 33e07d9..c38dfe1 100644
--- a/tapestry-core/src/test/coffeescript/org/apache/tapestry5/integration/app1/pages/test-spi.coffee
+++ b/tapestry-core/src/test/coffeescript/org/apache/tapestry5/integration/app1/pages/test-spi.coffee
@@ -87,7 +87,7 @@ require ["core/spi"], (spi) ->
     eh = container.on "x:click", "a.btn-primary", (event) ->
       event.stop()
 
-      strictEqual this, primary.element, "this should be the element that was matched"
+      strictEqual this.element, primary.element, "this should be the wrapper for element that was matched"
 
     primary.trigger "x:click"