Updated Branches: refs/heads/master b39079c84 -> c18e1199e
TAP5-2124: Support triggering zone update/refresh via nested element Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/52fcb51f Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/52fcb51f Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/52fcb51f Branch: refs/heads/master Commit: 52fcb51f170fff5c2144a4dab7bcd3b9aad44af3 Parents: b39079c Author: Howard M. Lewis Ship <[email protected]> Authored: Wed Jun 5 09:30:12 2013 -0700 Committer: Howard M. Lewis Ship <[email protected]> Committed: Wed Jun 5 09:30:12 2013 -0700 ---------------------------------------------------------------------- .../META-INF/modules/t5/core/events.coffee | 6 +++--- .../META-INF/modules/t5/core/zone.coffee | 12 ++++++++---- .../org/apache/tapestry5/t5-core-dom-jquery.coffee | 11 +++++++++++ .../apache/tapestry5/t5-core-dom-prototype.coffee | 9 +++++++++ 4 files changed, 31 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/52fcb51f/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/events.coffee ---------------------------------------------------------------------- diff --git a/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/events.coffee b/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/events.coffee index 94e2901..908470b 100644 --- a/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/events.coffee +++ b/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/events.coffee @@ -1,4 +1,4 @@ -# Copyright 2012 The Apache Software Foundation +# Copyright 2012, 2013 The Apache Software Foundation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -128,7 +128,7 @@ define # Triggered (by the standard handler) just before the content in a Zone will be updated. willUpdate: "t5:zone:will-update" - # Triggered (by the standard hanndler) just after the content in a Zone has updated. If the zone was not visible, it + # Triggered (by the standard handler) just after the content in a Zone has updated. If the zone was not visible, it # is made visible after its content is changed, and before this event is triggered. Some number of other components that # also perform Ajax updates of the page also trigger this event. # @@ -137,7 +137,7 @@ define # (see `t5/core/datefield` module). didUpdate: "t5:zone:did-update" - # Triggered on a zone element, the default handler will peform an Ajax request and, when the response is available, + # Triggered on (or within) a zone element, the default handler will peform an Ajax request and, when the response is available, # update the zone (via `events.zone.update`). The request should provide a partial page render response. If the # response includes a `content` key, its value will be the markup to replace the zone element's body. # http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/52fcb51f/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/zone.coffee ---------------------------------------------------------------------- diff --git a/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/zone.coffee b/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/zone.coffee index 32db8f5..57bbaf6 100644 --- a/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/zone.coffee +++ b/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/zone.coffee @@ -90,15 +90,19 @@ define ["./dom", "./events", "./ajax", "./console", "./forms", "underscore"], dom.onDocument events.zone.refresh, (event) -> + # This even may be triggered on an element inside the zone, rather than on the zone itself. Scan upwards + # to find the actual zone. + zone = @closest "[data-container-type=zone]" + # A Zone inside a form will render some additional parameters to coordinate updates with the Form on the server. - attr = @attribute "data-zone-parameters" + attr = zone.attribute "data-zone-parameters" parameters = attr and JSON.parse attr ajax event.memo.url, - parameters: _.extend { "t:zoneid": @element.id }, parameters, event.memo.parameters + parameters: _.extend { "t:zoneid": zone.element.id }, parameters, event.memo.parameters success: (response) => - @trigger events.zone.update, content: response.json?.content + zone.trigger events.zone.update, content: response.json?.content # Locates a zone element by its unique id attribute, and (deferred, to a later event loop cycle), # performs a standard refresh of the zone. This is primarily used by the core/ProgressiveDisplay component. @@ -116,5 +120,5 @@ define ["./dom", "./events", "./ajax", "./console", "./forms", "underscore"], zone.trigger events.zone.refresh, { url } - # Most of this module is document-level event handlers, but there's also some exports. + # Most of this module is document-level event handlers, but there's also some exports: return { deferredZoneUpdate, findZone } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/52fcb51f/tapestry-core/src/main/coffeescript/org/apache/tapestry5/t5-core-dom-jquery.coffee ---------------------------------------------------------------------- diff --git a/tapestry-core/src/main/coffeescript/org/apache/tapestry5/t5-core-dom-jquery.coffee b/tapestry-core/src/main/coffeescript/org/apache/tapestry5/t5-core-dom-jquery.coffee index 8e8e078..9f60c92 100644 --- a/tapestry-core/src/main/coffeescript/org/apache/tapestry5/t5-core-dom-jquery.coffee +++ b/tapestry-core/src/main/coffeescript/org/apache/tapestry5/t5-core-dom-jquery.coffee @@ -266,6 +266,17 @@ define ["underscore", "./utils", "jquery"], (_, utils, $) -> new ElementWrapper parents.eq(0) + # Returns this ElementWrapper if it matches the selector; otherwise, returns the first container element (as an ElementWrapper) + # that matches the selector. Returns null if no container element matches. + closest: (selector) -> + + match = @$.closest selector + + switch + when match.length is 0 then return null + when match[0] is @element then return this + else return new ElementWrapper match + # Returns an ElementWrapper for this element's containing element. # Returns null if this element has no parent (either because this element is the document object, or # because this element is not yet attached to the DOM). http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/52fcb51f/tapestry-core/src/main/coffeescript/org/apache/tapestry5/t5-core-dom-prototype.coffee ---------------------------------------------------------------------- diff --git a/tapestry-core/src/main/coffeescript/org/apache/tapestry5/t5-core-dom-prototype.coffee b/tapestry-core/src/main/coffeescript/org/apache/tapestry5/t5-core-dom-prototype.coffee index 42fd8ee..ccabd1b 100644 --- a/tapestry-core/src/main/coffeescript/org/apache/tapestry5/t5-core-dom-prototype.coffee +++ b/tapestry-core/src/main/coffeescript/org/apache/tapestry5/t5-core-dom-prototype.coffee @@ -306,6 +306,15 @@ define ["underscore", "./utils", "prototype"], (_, utils) -> new ElementWrapper parent + # Returns this ElementWrapper if it matches the selector; otherwise, returns the first container element (as an ElementWrapper) + # that matches the selector. Returns null if no container element matches. + closest: (selector) -> + + if @element.match selector + return this + + return @findParent selector + # Returns an ElementWrapper for this element's immediate containing element. # Returns null if this element has no parent (either because this element is the document object, or # because this element is not yet attached to the DOM).
