You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by iv...@apache.org on 2014/02/21 08:28:29 UTC

[05/11] git commit: WICKET-5512 Allow using child selector for JS event bindings

WICKET-5512 Allow using child selector for JS event bindings


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/25474d52
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/25474d52
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/25474d52

Branch: refs/heads/sandbox/component-queueing-2
Commit: 25474d5226dfa057999bb566dfcd61318d468232
Parents: 51e5b57
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Wed Feb 19 14:33:56 2014 +0200
Committer: Igor Vaynberg <ig...@gmail.com>
Committed: Thu Feb 20 23:24:05 2014 -0800

----------------------------------------------------------------------
 .../ajax/AbstractDefaultAjaxBehavior.java       |  7 +++++
 .../ajax/attributes/AjaxAttributeName.java      |  7 ++++-
 .../ajax/attributes/AjaxRequestAttributes.java  | 28 ++++++++++++++++++++
 .../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, 48 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/25474d52/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 1da7366..1d0caf3 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
@@ -227,6 +227,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/25474d52/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 e0ce088..0429ec3 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/25474d52/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 9eff742..fea733d 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

http://git-wip-us.apache.org/repos/asf/wicket/blob/25474d52/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 43ff3a4..a8c6102 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
@@ -1864,7 +1864,7 @@
 							call.ajax(attributes);
 						}
 						Wicket.Ajax._handleEventCancelation(attributes);
-					});
+					}, null, attrs.sel);
 				});
 			},
 			

http://git-wip-us.apache.org/repos/asf/wicket/blob/25474d52/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 f814897..8ac06f2 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/25474d52/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 51027eb..c689423 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
@@ -57,7 +57,7 @@ public class AjaxAttributeNameTest extends Assert
 		}
 
 		assertEquals("all known json parameter names",
-			"tr|p|d|id|dt|wr|rt|pd|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|pd|sp|ch|e|async|dep|ep|pre|coh|fh|sh|ah|bsh|bh|i|sc|mp|f|c|m|u|sel|",
 			sb.toString());
 	}
 }