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/12 03:45:37 UTC
[1/4] git commit: Handle window events the same as element events
Test core/spi:EventHandler start() and stop()
Updated Branches:
refs/heads/5.4-js-rewrite 48127ffda -> 553e39d35
Handle window events the same as element events
Test core/spi:EventHandler start() and stop()
Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/553e39d3
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/553e39d3
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/553e39d3
Branch: refs/heads/5.4-js-rewrite
Commit: 553e39d35bea2ab3b92e67a38209003ed14b0d3d
Parents: d522f22
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Sat Aug 11 18:45:21 2012 -0700
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Sat Aug 11 18:45:21 2012 -0700
----------------------------------------------------------------------
.../coffeescript/META-INF/modules/core/spi.coffee | 14 +-----
tapestry-core/src/test/app1/JavaScriptTests.tml | 6 +++
.../integration/app1/pages/test-spi.coffee | 32 ++++++++++++++-
3 files changed, 39 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/553e39d3/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 a7a946b..4c58b4f 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
@@ -97,9 +97,6 @@ define ["_", "prototype"], (_) ->
#
# Registers the handler as an event listener for matching elements and event names.
#
- # Note: it is possible to add handlers for events on the window object, but
- # `start()` and `stop()` do not do anything for such events.
- #
# * elements - array of DOM elements
# * eventNames - array of event names
# * match - selector to match bubbled elements, or null
@@ -108,22 +105,17 @@ define ["_", "prototype"], (_) ->
constructor: (elements, eventNames, match, handler) ->
throw new Error("No event handler was provided.") unless handler?
- wrapped = (prototypeEvent, matchedElement) ->
+ wrapped = (prototypeEvent) ->
# Set `this` to be the matched element (jQuery style), rather than
# the element on which the event is observed.
- handler.call(matchedElement, new EventWrapper prototypeEvent)
+ handler.call(prototypeEvent.findElement(), new EventWrapper prototypeEvent)
# Prototype Event.Handler instances
@protoHandlers = []
_.each elements, (element) =>
_.each eventNames, (eventName) =>
- if element is window
- unless _.isEmpty match
- throw Error("Matching of elements by selector is not supported for window events.")
- Event.observe element, eventName, wrapped
- else
- @protoHandlers.push element.on eventName, match, wrapped
+ @protoHandlers.push Event.on element, eventName, match, wrapped
# Invoked after `stop()` to restart event listening.
#
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/553e39d3/tapestry-core/src/test/app1/JavaScriptTests.tml
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/app1/JavaScriptTests.tml b/tapestry-core/src/test/app1/JavaScriptTests.tml
index c2aa34e..119b19b 100644
--- a/tapestry-core/src/test/app1/JavaScriptTests.tml
+++ b/tapestry-core/src/test/app1/JavaScriptTests.tml
@@ -16,8 +16,14 @@
<!-- The rest are test elements for the core/spi tests, etc. -->
+<hr/>
+
<div id="spi-test1"/>
+<div id="spi-test2">
+ <a href="#">button</a>
+</div>
+
</body>
</html>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/553e39d3/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 9b88524..d0f3736 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
@@ -4,9 +4,37 @@ require ["core/spi"], (spi) ->
test "get wrapped element by id", ->
e = spi.wrap "spi-test1"
- ok e != null, "element found and wrapped"
+ ok e isnt null, "element found and wrapped"
test "get wrapped element by unknown id is null", ->
e = spi.wrap "spi-does-not-exist-element"
- ok e == null, "element not found and null"
\ No newline at end of file
+ ok e is null, "element not found and null"
+
+ test "pause and resume events", ->
+
+ clicks = 0
+ container = spi.wrap "spi-test2"
+ button = container.find "a"
+
+ # Remember that Prototype will never trigger a native event, just a
+ # custom event, so we create a custom event here.
+ eh = container.on "x:click", "a", (event) ->
+ event.stop()
+ clicks++
+
+ button.trigger "x:click"
+
+ equal clicks, 1, "first click registered"
+
+ eh.stop()
+
+ button.trigger "x:click"
+
+ equal clicks, 1, "no notification when EventHandler stopped"
+
+ eh.start()
+
+ button.trigger "x:click"
+
+ equal clicks, 2, "notifications resume after EventHandler started"
\ No newline at end of file