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/04/10 10:45:21 UTC

svn commit: r527059 - in /incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/ajax: AbstractDefaultAjaxBehavior.java wicket-ajax-debug-drag.js wicket-ajax-debug.js wicket-ajax.js

Author: knopp
Date: Tue Apr 10 01:45:21 2007
New Revision: 527059

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

Removed:
    incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/ajax/wicket-ajax-debug-drag.js
Modified:
    incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/ajax/AbstractDefaultAjaxBehavior.java
    incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/ajax/wicket-ajax-debug.js
    incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/ajax/wicket-ajax.js

Modified: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/ajax/AbstractDefaultAjaxBehavior.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/ajax/AbstractDefaultAjaxBehavior.java?view=diff&rev=527059&r1=527058&r2=527059
==============================================================================
--- incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/ajax/AbstractDefaultAjaxBehavior.java (original)
+++ incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/ajax/AbstractDefaultAjaxBehavior.java Tue Apr 10 01:45:21 2007
@@ -49,10 +49,6 @@
 			AbstractDefaultAjaxBehavior.class, "wicket-ajax.js");
 
 	/** reference to the default ajax debug support javascript file. */
-	private static final ResourceReference JAVASCRIPT_DEBUG_DRAG = new JavascriptResourceReference(
-			AbstractDefaultAjaxBehavior.class, "wicket-ajax-debug-drag.js");
-
-	/** reference to the default ajax debug support javascript file. */
 	private static final ResourceReference JAVASCRIPT_DEBUG = new JavascriptResourceReference(
 			AbstractDefaultAjaxBehavior.class, "wicket-ajax-debug.js");
 
@@ -81,9 +77,7 @@
 		if (debugSettings.isAjaxDebugModeEnabled())
 		{
 			response.renderJavascript("wicketAjaxDebugEnable=true;", "wicket-ajax-debug-enable");
-			response.renderJavascriptReference(JAVASCRIPT_DEBUG_DRAG);
 			response.renderJavascriptReference(JAVASCRIPT_DEBUG);
-
 		}
 	}
 

Modified: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/ajax/wicket-ajax-debug.js
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/ajax/wicket-ajax-debug.js?view=diff&rev=527059&r1=527058&r2=527059
==============================================================================
--- incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/ajax/wicket-ajax-debug.js (original)
+++ incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/ajax/wicket-ajax-debug.js Tue Apr 10 01:45:21 2007
@@ -108,10 +108,25 @@
 												
 				
 				WicketAjaxDebug.addElement(html);
-            	WicketDrag.init(wicketGet(dwdhid), wicketGet(dwid));
+            	Wicket.Drag.init(wicketGet(dwdhid), function() {} , function() { }, WicketAjaxDebug.onDrag);
 			}
 
         }
+	},
+	
+	onDrag: function(element, deltaX, deltaY) {
+		var w = wicketGet(WicketAjaxDebug.debugWindowId);
+		
+		var x = parseInt(w.style.left, 10) + deltaX;
+		var y = parseInt(w.style.top, 10) + deltaY;
+		
+		if (x < 0)
+			x = 0;
+		if (y < 0)
+			y = 0;							
+			
+		w.style.left = x + "px";
+		w.style.top = y + "px";		
 	},
 	
 	addElement : function(html) {

Modified: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/ajax/wicket-ajax.js
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/ajax/wicket-ajax.js?view=diff&rev=527059&r1=527058&r2=527059
==============================================================================
--- incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/ajax/wicket-ajax.js (original)
+++ incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/ajax/wicket-ajax.js Tue Apr 10 01:45:21 2007
@@ -875,7 +875,8 @@
 			// IE this will cause double events for everything.. (mostly because of the Function.prototype.bind(element))
 			Wicket.Focus.attachFocusEvent();
 			// set the focus to the last component
-			Wicket.Focus.requestFocus();	
+			
+//			window.setTimeout(function() { Wicket.Focus.requestFocus(); }, 0);	
 			this.request.done();
 			this.successHandler();
 			// continue to next step (which should make the processing stop, as success should be the final step)		
@@ -1290,6 +1291,159 @@
 
 Wicket.throttler = new Wicket.Throttler();
 
+/**
+ * Prevent event from bubbling up in the element hierarchy.
+ */
+Wicket.stopEvent = function(e) {
+	if (typeof(e) == "undefined")
+		e = window.event;
+		
+	e.cancelBubble = true;
+	if (e.stopPropagation)
+		e.stopPropagation();
+}
+
+
+/**
+ * Flexible dragging support.
+ */
+Wicket.Drag = {
+
+	/**
+	 * If no event is given as argument (IE), window.event is returned. 
+	 */
+	fixEvent: function(e) {
+		if (typeof e == 'undefined') 
+			e = window.event;
+		return e;		
+	},
+	
+	/**
+	 * Initializes the dragging on the specified element.
+	 * Element's onmousedown will be replaced by generated handler.
+	 *
+	 * @param {Element} element - element clicking on which the drag should begin 
+	 * @param {Function} onDragBegin - handler called at the begin on dragging - passed element as first parameter
+	 * @param {Function} onDragEnd - handler called at the end of dragging - passed element as first parameter
+	 * @param {Function} onDrag - handler called during dragging - passed element and mouse deltas	 
+	 */
+	init: function(element, onDragBegin, onDragEnd, onDrag) {		
+		
+		if (typeof(onDragBegin) == "undefined")
+			onDragBegin = Wicket.emptyFunction;
+		if (typeof(onDragEnd) == "undefined")
+			onDragEnd = Wicket.emptyFunction;
+		if (typeof(onDrag) == "undefined")
+			onDrag = Wicket.emptyFunction;
+		
+		// set the mousedown handler 
+		element.onmousedown = function(e) {			
+			
+			e = Wicket.Drag.fixEvent(e);
+	
+			// HACK - for safari stopPropagation doesn't work well because
+			// it also prevents scrollbars and form components getting the
+			// event. Therefore for safari the 'ignore' flag is set on event. 
+			if (typeof(e.ignore) == "undefined") {
+				
+				Wicket.stopEvent(e);
+	
+				onDragBegin(element);
+			
+				element.onDrag = onDrag;
+				element.onDragEnd = onDragEnd;
+				
+				element.lastMouseX = e.clientX;
+				element.lastMouseY = e.clientY;
+				
+				element.old_onmousemove = document.onmousemove;
+				element.old_onmouseup = document.onmouseup;
+				element.old_onselectstart = document.onselectstart;			
+				
+				document.onselectstart = function() { return false; }
+				document.onmousemove = Wicket.Drag.mouseMove;
+				document.onmouseup = Wicket.Drag.mouseUp;
+							
+				Wicket.Drag.current = element;
+							
+				return false;
+			} 			
+		};		
+	},
+	
+	/**
+	 * Deinitializes the dragging support on given element. 
+	 */
+	clean: function(element) {
+		element.onmousedown = null;
+	},
+
+	/**
+	 * Called when mouse is moved. This method fires the onDrag event
+	 * with element instance, deltaX and deltaY (the distance
+	 * between this call and the previous one).
+	 
+	 * The onDrag handler can optionally return an array of two integers 
+	 * - the delta correction. This is used, for example, if there is
+	 * element being resized and the size limit has been reached (but the
+	 * mouse can still move).
+	 * 
+	 * @param {Event} e
+	 */	
+	mouseMove: function(e) {
+		e = Wicket.Drag.fixEvent(e);
+		var o = Wicket.Drag.current;
+
+		// this happens sometimes in Safari 
+		if (e.clientX < 0 || e.clientY < 0) {
+			return;
+		}
+
+		if (o != null) {		
+			var deltaX = e.clientX - o.lastMouseX;
+			var deltaY = e.clientY - o.lastMouseY;
+				
+			var res = o.onDrag(o, deltaX, deltaY);
+			
+			if (res == null)
+				res = [0, 0];
+			
+			o.lastMouseX = e.clientX + res[0];
+			o.lastMouseY = e.clientY + res[1];
+		}
+		
+		return false;
+	},
+
+	/**
+	 * Called when the mouse button is released.
+	 * Cleans all temporary variables and callback methods.
+	 * 
+	 * @param {Event} e
+	 */	
+	mouseUp: function(e) {		
+		e = Wicket.Drag.fixEvent(e);
+		var o = Wicket.Drag.current;
+		
+		o.onDragEnd(o);		
+		
+		o.onDrag = null;
+		o.onDragEnd = null;
+		o.lastMouseX = null;
+		o.lastMouseY = null;
+		
+		document.onmousemove = o.old_onmousemove;
+		document.onmouseup = o.old_onmouseup;		
+		document.onselectstart = o.old_onselectstart;
+		
+		o.old_mousemove = null;		
+		o.old_mouseup = null;
+		o.old_onselectstart = null;
+		
+		Wicket.Drag.current = null;
+	}
+};
+
 /*
  * Compatibility layer to maintain the original wicket-ajax API.
  */
@@ -1389,7 +1543,10 @@
 			var toFocus = document.getElementById(lastFocusId);
 			if (toFocus != null && typeof(toFocus) != "undefined") {
 				Wicket.Log.info("Calling focus on " + lastFocusId);
-				toFocus.focus();
+				try {
+					toFocus.focus();
+				} catch (ignore) {
+				}
 			}
 			else
 			{