Repository: wicket Updated Branches: refs/heads/wicket-6.x e6e821031 -> 3f5367f57
WICKET-5512 Allow using child selector for JS event bindings (cherry picked from commit cade75e5afdf447f4889a0aad28da472c22a00d3) Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/315472c6 Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/315472c6 Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/315472c6 Branch: refs/heads/wicket-6.x Commit: 315472c6cf4146bc4383c1c47c6b2e12c22f6720 Parents: e6e8210 Author: Martin Tzvetanov Grigorov <[email protected]> Authored: Wed Feb 19 14:33:56 2014 +0200 Committer: Martin Tzvetanov Grigorov <[email protected]> Committed: Wed Feb 19 14:40:52 2014 +0200 ---------------------------------------------------------------------- .../ajax/AbstractDefaultAjaxBehavior.java | 7 +++++ .../ajax/attributes/AjaxAttributeName.java | 7 ++++- .../ajax/attributes/AjaxRequestAttributes.java | 30 +++++++++++++++++++- .../wicket/ajax/res/js/wicket-ajax-jquery.js | 2 +- .../wicket/ajax/res/js/wicket-event-jquery.js | 7 +++-- .../ajax/attributes/AjaxAttributeNameTest.java | 2 +- 6 files changed, 49 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/315472c6/wicket-core/src/main/java/org/apache/wicket/ajax/AbstractDefaultAjaxBehavior.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/ajax/AbstractDefaultAjaxBehavior.java b/wicket-core/src/main/java/org/apache/wicket/ajax/AbstractDefaultAjaxBehavior.java index d993973..af289dc 100644 --- a/wicket-core/src/main/java/org/apache/wicket/ajax/AbstractDefaultAjaxBehavior.java +++ b/wicket-core/src/main/java/org/apache/wicket/ajax/AbstractDefaultAjaxBehavior.java @@ -251,6 +251,13 @@ public abstract class AbstractDefaultAjaxBehavior extends AbstractAjaxBehavior submittingComponentId); } + CharSequence childSelector = attributes.getChildSelector(); + if (Strings.isEmpty(childSelector) == false) + { + attributesJson.put(AjaxAttributeName.CHILD_SELECTOR.jsonName(), + childSelector); + } + String indicatorId = findIndicatorId(); if (Strings.isEmpty(indicatorId) == false) { http://git-wip-us.apache.org/repos/asf/wicket/blob/315472c6/wicket-core/src/main/java/org/apache/wicket/ajax/attributes/AjaxAttributeName.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/ajax/attributes/AjaxAttributeName.java b/wicket-core/src/main/java/org/apache/wicket/ajax/attributes/AjaxAttributeName.java index 1042deb..6f0508d 100644 --- a/wicket-core/src/main/java/org/apache/wicket/ajax/attributes/AjaxAttributeName.java +++ b/wicket-core/src/main/java/org/apache/wicket/ajax/attributes/AjaxAttributeName.java @@ -218,7 +218,12 @@ public enum AjaxAttributeName { /** * @see AbstractDefaultAjaxBehavior#getCallbackUrl(); */ - URL("u"); + URL("u"), + + /** + * @see org.apache.wicket.ajax.attributes.AjaxRequestAttributes#childSelector + */ + CHILD_SELECTOR("sel"); private final String jsonName; http://git-wip-us.apache.org/repos/asf/wicket/blob/315472c6/wicket-core/src/main/java/org/apache/wicket/ajax/attributes/AjaxRequestAttributes.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/ajax/attributes/AjaxRequestAttributes.java b/wicket-core/src/main/java/org/apache/wicket/ajax/attributes/AjaxRequestAttributes.java index 896c4fd..b7feb1b 100644 --- a/wicket-core/src/main/java/org/apache/wicket/ajax/attributes/AjaxRequestAttributes.java +++ b/wicket-core/src/main/java/org/apache/wicket/ajax/attributes/AjaxRequestAttributes.java @@ -133,6 +133,34 @@ public final class AjaxRequestAttributes private ThrottlingSettings throttlingSettings; /** + * A selector string to filter the descendants of the selected + * elements that trigger the event. If the selector is null or empty, + * the event is always triggered when it reaches the selected HTML element. + * + * @see <a href="http://api.jquery.com/on/">jQuery#on's selector</a> + */ + private CharSequence childSelector; + + /** + * @see #childSelector + * @return The selector string that filters the descendants + */ + public CharSequence getChildSelector() + { + return childSelector; + } + + /** + * @see #childSelector + * @param childSelector + * The selector string that filters the descendants + */ + public void setChildSelector(CharSequence childSelector) + { + this.childSelector = childSelector; + } + + /** * Returns whether the form submit is multipart. * <p> * Note that for multipart AJAX requests a hidden IFRAME will be used and that can have negative @@ -502,4 +530,4 @@ public final class AjaxRequestAttributes return this; } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/wicket/blob/315472c6/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js b/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js index 72bffd7..27f81cd 100644 --- a/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js +++ b/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js @@ -1868,7 +1868,7 @@ call.ajax(attributes); } Wicket.Ajax._handleEventCancelation(attributes); - }); + }, null, attrs.sel); }); }, http://git-wip-us.apache.org/repos/asf/wicket/blob/315472c6/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-event-jquery.js ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-event-jquery.js b/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-event-jquery.js index 19a504e..116fa03 100644 --- a/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-event-jquery.js +++ b/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-event-jquery.js @@ -148,8 +148,11 @@ * @param type {String} The type of the DOM event * @param fn {Function} The event handler to unbind * @param data {Object} Extra data for the event + * @param selector {String} A selector string to filter the descendants of the selected + * elements that trigger the event. If the selector is null or omitted, + * the event is always triggered when it reaches the selected element. */ - add: function (element, type, fn, data) { + add: function (element, type, fn, data, selector) { if (type === 'domready') { jQuery(fn); } else { @@ -166,7 +169,7 @@ '" on element "' + element + '" because the element is not in the DOM'); } - jQuery(el).on(type, data, fn); + jQuery(el).on(type, selector, data, fn); }); } return element; http://git-wip-us.apache.org/repos/asf/wicket/blob/315472c6/wicket-core/src/test/java/org/apache/wicket/ajax/attributes/AjaxAttributeNameTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/ajax/attributes/AjaxAttributeNameTest.java b/wicket-core/src/test/java/org/apache/wicket/ajax/attributes/AjaxAttributeNameTest.java index 47625c0..a50ce06 100644 --- a/wicket-core/src/test/java/org/apache/wicket/ajax/attributes/AjaxAttributeNameTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/ajax/attributes/AjaxAttributeNameTest.java @@ -58,7 +58,7 @@ public class AjaxAttributeNameTest } Assert.assertEquals("all known json parameter names", - "tr|p|d|id|dt|wr|rt|ad|sp|ch|e|async|dep|ep|pre|coh|fh|sh|ah|bsh|bh|i|sc|mp|f|c|m|u|", + "tr|p|d|id|dt|wr|rt|ad|sp|ch|e|async|dep|ep|pre|coh|fh|sh|ah|bsh|bh|i|sc|mp|f|c|m|u|sel|", sb.toString()); } }
