You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by kn...@apache.org on 2007/08/28 18:51:57 UTC

svn commit: r570485 - in /wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/ajax: AbstractDefaultAjaxBehavior.java wicket-ajax.js

Author: knopp
Date: Tue Aug 28 09:51:56 2007
New Revision: 570485

URL: http://svn.apache.org/viewvc?rev=570485&view=rev
Log:
WICKET-895

Modified:
    wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/ajax/AbstractDefaultAjaxBehavior.java
    wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/ajax/wicket-ajax.js

Modified: wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/ajax/AbstractDefaultAjaxBehavior.java
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/ajax/AbstractDefaultAjaxBehavior.java?rev=570485&r1=570484&r2=570485&view=diff
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/ajax/AbstractDefaultAjaxBehavior.java (original)
+++ wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/ajax/AbstractDefaultAjaxBehavior.java Tue Aug 28 09:51:56 2007
@@ -74,7 +74,7 @@
 
 		response.renderJavascriptReference(WicketEventReference.INSTANCE);
 		response.renderJavascriptReference(JAVASCRIPT);
-		
+
 		if (debugSettings.isAjaxDebugModeEnabled())
 		{
 			response.renderJavascript("wicketAjaxDebugEnable=true;", "wicket-ajax-debug-enable");
@@ -83,8 +83,8 @@
 	}
 
 	/**
-	 * @return ajax call decorator used to decorate the call generated by this
-	 *         behavior or null for none
+	 * @return ajax call decorator used to decorate the call generated by this behavior or null for
+	 *         none
 	 */
 	protected IAjaxCallDecorator getAjaxCallDecorator()
 	{
@@ -92,8 +92,7 @@
 	}
 
 	/**
-	 * @return javascript that will generate an ajax GET request to this
-	 *         behavior
+	 * @return javascript that will generate an ajax GET request to this behavior
 	 */
 	protected CharSequence getCallbackScript()
 	{
@@ -101,30 +100,29 @@
 	}
 
 	/**
-	 * @return javascript that will generate an ajax GET request to this
-	 *         behavior *
+	 * @return javascript that will generate an ajax GET request to this behavior *
 	 * @param onlyTargetActivePage
-	 *            if true the callback to this behavior will be ignore if the
-	 *            page is not the last one the user accessed
+	 *            if true the callback to this behavior will be ignore if the page is not the last
+	 *            one the user accessed
 	 * 
 	 */
 	protected CharSequence getCallbackScript(boolean onlyTargetActivePage)
 	{
-		return generateCallbackScript("wicketAjaxGet('" + getCallbackUrl(onlyTargetActivePage) + "'");
+		return generateCallbackScript("wicketAjaxGet('" + getCallbackUrl(onlyTargetActivePage) +
+				"'");
 	}
 
 	/**
-	 * @return an optional javacript expression that determines whether the request
-	 *            will actually execute (in form of return XXX;);
+	 * @return an optional javacript expression that determines whether the request will actually
+	 *         execute (in form of return XXX;);
 	 */
 	protected CharSequence getPreconditionScript()
 	{
-		return null;
+		return "return Wicket.$$(this)";
 	}
 
 	/**
-	 * @return javascript that will run when the ajax call finishes with an
-	 *            error status
+	 * @return javascript that will run when the ajax call finishes with an error status
 	 */
 	protected CharSequence getFailureScript()
 	{
@@ -132,8 +130,7 @@
 	}
 
 	/**
-	 * @return javascript that will run when the ajax call finishes
-	 *            successfully
+	 * @return javascript that will run when the ajax call finishes successfully
 	 */
 	protected CharSequence getSuccessScript()
 	{
@@ -141,16 +138,15 @@
 	}
 
 	/**
-	 * Returns javascript that performs an ajax callback to this behavior. The
-	 * script is decorated by the ajax callback decorator from
+	 * Returns javascript that performs an ajax callback to this behavior. The script is decorated
+	 * by the ajax callback decorator from
 	 * {@link AbstractDefaultAjaxBehavior#getAjaxCallDecorator()}.
 	 * 
 	 * @param partialCall
-	 *            Javascript of a partial call to the function performing the
-	 *            actual ajax callback. Must be in format
-	 *            <code>function(params,</code> with signature
-	 *            <code>function(params, onSuccessHandler, onFailureHandler</code>.
-	 *            Example: <code>wicketAjaxGet('callbackurl'</code>
+	 *            Javascript of a partial call to the function performing the actual ajax callback.
+	 *            Must be in format <code>function(params,</code> with signature
+	 *            <code>function(params, onSuccessHandler, onFailureHandler</code>. Example:
+	 *            <code>wicketAjaxGet('callbackurl'</code>
 	 * 
 	 * @return script that peforms ajax callback to this behavior
 	 */
@@ -188,18 +184,18 @@
 		buff.append("var ").append(IAjaxCallDecorator.WICKET_CALL_RESULT_VAR).append("=");
 		buff.append(partialCall).append(", function() { ").append(success);
 		buff.append("}.bind(this), function() { ").append(failure).append("}.bind(this)");
-		
-		if (precondition != null) 
+
+		if (precondition != null)
 		{
 			buff.append(", function() {");
 			buff.append(precondition);
-			buff.append("}");
+			buff.append("}.bind(this)");
 		}
-		
+
 		String channel = getChannelName();
-		if (channel != null) 
+		if (channel != null)
 		{
-			if (precondition == null) 
+			if (precondition == null)
 			{
 				buff.append(", null");
 			}
@@ -207,7 +203,7 @@
 			buff.append(channel);
 			buff.append("'");
 		}
-		
+
 		buff.append(");");
 
 		CharSequence call = buff;
@@ -226,10 +222,11 @@
 		return call;
 	}
 
-	protected String getChannelName() {
+	protected String getChannelName()
+	{
 		return null;
 	}
-	
+
 	/**
 	 * 
 	 * @return String
@@ -245,7 +242,7 @@
 		{
 			return ((IAjaxIndicatorAware)this).getAjaxIndicatorMarkupId();
 		}
-		
+
 		Component parent = getComponent().getParent();
 		while (parent != null)
 		{
@@ -280,24 +277,21 @@
 	protected abstract void respond(AjaxRequestTarget target);
 
 	/**
-	 * Wraps the provided javascript with a throttled block. Throttled behaviors
-	 * only execute once within the given delay even though they are triggered
-	 * multiple times.
+	 * Wraps the provided javascript with a throttled block. Throttled behaviors only execute once
+	 * within the given delay even though they are triggered multiple times.
 	 * <p>
-	 * For example, this is useful when attaching an event behavior to the
-	 * onkeypress event. It is not desirable to have an ajax call made every
-	 * time the user types so we throttle that call to a desirable delay, such
-	 * as once per second. This gives us a near real time ability to provide
+	 * For example, this is useful when attaching an event behavior to the onkeypress event. It is
+	 * not desirable to have an ajax call made every time the user types so we throttle that call to
+	 * a desirable delay, such as once per second. This gives us a near real time ability to provide
 	 * feedback without overloading the server with ajax calls.
 	 * 
 	 * @param script
 	 *            javascript to be throttled
 	 * @param throttleId
-	 *            the id of the throttle to be used. Usually this should remain
-	 *            constant for the same javascript block.
+	 *            the id of the throttle to be used. Usually this should remain constant for the
+	 *            same javascript block.
 	 * @param throttleDelay
-	 *            time span within which the javascript block will only execute
-	 *            once
+	 *            time span within which the javascript block will only execute once
 	 * @return wrapped javascript
 	 */
 	public static final CharSequence throttleScript(CharSequence script, String throttleId,

Modified: wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/ajax/wicket-ajax.js
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/ajax/wicket-ajax.js?rev=570485&r1=570484&r2=570485&view=diff
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/ajax/wicket-ajax.js (original)
+++ wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/ajax/wicket-ajax.js Tue Aug 28 09:51:56 2007
@@ -37,7 +37,7 @@
 	Wicket = { };
 
 
-Wicket.$=function(arg) {
+Wicket.$ = function(arg) {
 	if (arguments.length > 1) {
 		var e=[];
 		for (var i=0; i<arguments.length; i++) {
@@ -49,6 +49,16 @@
 	} else {
 		return arg;
 	}
+}
+
+// returns if the element belongs to current document
+// if the argument is not element, function returns true
+Wicket.$$ = function(element) {
+	if (element == null || typeof(element) == "undefined" ||
+	    element.tagName == null || typeof(element.tagName)) {
+	    return true;
+	} 
+	return element.ownerDocument == document;
 }
 
 Wicket.emptyFunction = function() { };