[richfaces-svn-commits] JBoss Rich Faces SVN: r979 - in trunk/richfaces: drag-drop/src/main/resources/org/richfaces/renderkit/html/scripts and 1 other directories.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Fri Jun 1 13:04:15 EDT 2007


Author: nbelaevski
Date: 2007-06-01 13:04:15 -0400 (Fri, 01 Jun 2007)
New Revision: 979

Modified:
   trunk/richfaces/common/src/main/resources/org/richfaces/renderkit/html/scripts/dnd/dnd-draggable.js
   trunk/richfaces/drag-drop/src/main/resources/org/richfaces/renderkit/html/scripts/simple-draggable.js
   trunk/richfaces/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree-item.js
Log:
http://jira.jboss.com/jira/browse/RF-221 fixed

Modified: trunk/richfaces/common/src/main/resources/org/richfaces/renderkit/html/scripts/dnd/dnd-draggable.js
===================================================================
--- trunk/richfaces/common/src/main/resources/org/richfaces/renderkit/html/scripts/dnd/dnd-draggable.js	2007-06-01 15:00:36 UTC (rev 978)
+++ trunk/richfaces/common/src/main/resources/org/richfaces/renderkit/html/scripts/dnd/dnd-draggable.js	2007-06-01 17:04:15 UTC (rev 979)
@@ -10,6 +10,54 @@
 	}
 };
 
+DnD.DragEndListener = Class.create();
+DnD.DragEndListener.prototype = {
+	
+	initialize: function(callback) {
+		this.callback = callback;
+		this.onmoveBound = this.onmove.bindAsEventListener(this);
+		this.onupBound = this.onup.bindAsEventListener(this);
+	},
+	
+	activate: function(event) {
+		Event.observe(document, "mousemove", this.onmoveBound);
+		Event.observe(document, "mouseup", this.onupBound);
+		if (event.type == "mousemove") {
+			this.onmoveBound(event);
+		}
+	},
+	
+	onmove: function(event) {
+		if ("mousemove" == event.type) {
+	    	if (!this.mouseMoveProvidesButtonChecked) {
+				this.mouseMoveProvidesButtonChecked = true;
+		    	if (!this.mouseMoveProvidesButton) {
+			    	this.mouseMoveProvidesButton = event.button != 0;
+		    	}
+			}
+
+			if (this.mouseMoveProvidesButton && !Event.isLeftClick(event)) {
+				this.endDrag();
+			}
+		}
+	},
+	
+	onup: function(event) {
+		this.endDrag();
+	},
+	
+	endDrag: function() {
+		this.deactivate();
+		this.callback();
+	},	
+	
+	deactivate: function() {
+		Event.stopObserving(document, "mousemove", this.onmoveBound);
+		Event.stopObserving(document, "mouseup", this.onupBound);
+	}
+
+};
+
 DnD.Draggable.prototype = {
 
 	getElement: function() {
@@ -79,41 +127,47 @@
 		}
 	},
 
+	moveDrag: function(event) {
+		//TODO handle mouseover to update coords
+		var x = Event.pointerX(event);
+		var y = Event.pointerY(event);
+		
+		if (!window.drag && (Math.abs(this.lastDragX - x) + Math.abs(this.lastDragY - y)) > 2) {
+			this.updateDrag(event);
+		}
+	},
+
 	startDrag : function(event) {
 		var contentType = this.getContentType();
 
 		if (contentType) {
-			if (typeof this.lastDragX == "undefined" || typeof this.lastDragY == "undefined") {
-				this.lastDragX = Event.pointerX(event);
-				this.lastDragY = Event.pointerY(event);			
-
-	        	// prevent text selection in IE
-	        	this.onSelectStartHandler = document.onselectstart;
-	        	this.onDragStartHandler = document.ondragstart;
+			if (!this.endDragListener) {
+				this.dragTrigger = this.moveDrag.bindAsEventListener(this);
+			
+				this.endDragListener = new DnD.DragEndListener(function() {
 	
-	        	document.onselectstart = function () { return false; };
-	        	document.ondragstart = function () { DnD.ieReleaseCapture(); return false; };
-	    	
-	    		if (document.releaseCapture) {
-		    		Event.observe(document, "mousemove", DnD.ieReleaseCapture);
-	    		}
-	    		
-	    		return false;
-			} else {
-				//TODO handle mouseover to update coords
-				var x = Event.pointerX(event);
-				var y = Event.pointerY(event);
-				
-				if ((Math.abs(this.lastDragX - x) + Math.abs(this.lastDragY - y)) > 3) {
-					this.updateDrag(event);
-					
-					return true;			
-				}
-				
-				return false;
+					Event.stopObserving(document, "mousemove", this.dragTrigger);
+					this.endDrag(event, window.drag);
+	
+				}.bind(this));
 			}
-		} else {   	
-			return true;
+			
+			this.endDragListener.activate(event);
+			Event.observe(document, "mousemove", this.dragTrigger);
+
+			this.lastDragX = Event.pointerX(event);
+			this.lastDragY = Event.pointerY(event);			
+
+        	// prevent text selection in IE
+        	this.onSelectStartHandler = document.onselectstart;
+        	this.onDragStartHandler = document.ondragstart;
+
+        	document.onselectstart = function () { return false; };
+        	document.ondragstart = function () { DnD.ieReleaseCapture(); return false; };
+    	
+    		if (document.releaseCapture) {
+	    		Event.observe(document, "mousemove", DnD.ieReleaseCapture);
+    		}
 		}
     },
 
@@ -152,6 +206,7 @@
 	 * @param {DnD.Drag} drag
 	 */
 	endDrag: function(event, drag) {
+		DnD.endDrag(event);
 		this.lastDragX = undefined;
 		this.lastDragY = undefined;
 		
@@ -162,39 +217,24 @@
 	    	Event.stopObserving(document, "mousemove", DnD.ieReleaseCapture);
     	}
 
-        var indicator = drag.indicator;
-		if (indicator) {
-			indicator.hide();
+		if (this.endDragListener) {
+			this.endDragListener.deactivate();
 		}
 
-		this.ondragend(event, drag);
-
+        if (drag) {
+	        var indicator = drag.indicator;
+			if (indicator) {
+				indicator.hide();
+			}
+	
+			this.ondragend(event, drag);
+		}
+		
 		if( this.options && this.options.ondragend) {
 			this.options.ondragend();
 		}
     },
     
-    onupdatedrag: function(event) {
-		if ("mousemove" == event.type) {
-	    	if (!this.mouseMoveProvidesButtonChecked) {
-				this.mouseMoveProvidesButtonChecked = true;
-		    	if (!this.mouseMoveProvidesButton) {
-			    	this.mouseMoveProvidesButton = event.button != 0;
-		    	}
-			}
-
-			if (this.mouseMoveProvidesButton && !Event.isLeftClick(event)) {
-				if (window.drag) {
-					DnD.endDrag(event);
-				}
-				
-				return false;
-			}
-		}
-		
-		return true;
-    },
-    
 	/**
 	 * cubclasses may define custom behavior
 	 * @param {Object} drag

Modified: trunk/richfaces/drag-drop/src/main/resources/org/richfaces/renderkit/html/scripts/simple-draggable.js
===================================================================
--- trunk/richfaces/drag-drop/src/main/resources/org/richfaces/renderkit/html/scripts/simple-draggable.js	2007-06-01 15:00:36 UTC (rev 978)
+++ trunk/richfaces/drag-drop/src/main/resources/org/richfaces/renderkit/html/scripts/simple-draggable.js	2007-06-01 17:04:15 UTC (rev 979)
@@ -16,9 +16,6 @@
 
         this.eventMouseDown = this.initDrag.bindAsEventListener(this);
 
-		this.listenDragBound = this.listenDrag.bindAsEventListener(this);
-		this.stopListenDragBound = this.stopListenDrag.bindAsEventListener(this);
-
 		Event.observe(this.id, "mousedown", this.eventMouseDown);
 	},
 
@@ -48,31 +45,10 @@
 		//this.dragEnter(event);
 	},
 
-	ondragend : function(event, drag) {
-		this.dragStarted = false;
-	},
-
 	getContentType: function() {
 		return this.options.dragType;
 	},
 
-	listenDrag: function(e) {
-		if (this.onupdatedrag(e)) {
-			if (this.startDrag(e)) {
-				Event.stopObserving(document, "mousemove", this.listenDragBound);
-				Event.stopObserving(document, "mouseup", this.stopListenDragBound);
-				//this.dragStarted = true;
-			}
-		}
-	},
-	
-	stopListenDrag: function(e) {
-		//this.dragStarted = false;
-
-		Event.stopObserving(document, "mousemove", this.listenDragBound);
-		Event.stopObserving(document, "mouseup", this.stopListenDragBound);
-	},
-
 	initDrag: function(event) {
 		if(Event.isLeftClick(event)) {
 		  var src = Event.element(event);
@@ -85,8 +61,9 @@
 
 			Event.stop(event);
 
-			Event.observe(document, "mousemove", this.listenDragBound);
-			Event.observe(document, "mouseup", this.stopListenDragBound);
+			this.startDrag(event);
+			//Event.observe(document, "mousemove", this.listenDragBound);
+			//Event.observe(document, "mouseup", this.stopListenDragBound);
 		}
 	}
 });
\ No newline at end of file

Modified: trunk/richfaces/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree-item.js
===================================================================
--- trunk/richfaces/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree-item.js	2007-06-01 15:00:36 UTC (rev 978)
+++ trunk/richfaces/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree-item.js	2007-06-01 17:04:15 UTC (rev 979)
@@ -15,9 +15,6 @@
 		this.eventMouseOut = this.processMouseOut.bindAsEventListener(this);
 		this.eventMouseOver = this.processMouseOver.bindAsEventListener(this);
 
-		this.listenDragBound = this.listenDrag.bindAsEventListener(this);
-		this.stopListenDragBound = this.stopListenDrag.bindAsEventListener(this);
-		
 		if (this.onContextMenu) {
 			this.eventRightClick = this.onContextMenu.bindAsEventListener();
 		}
@@ -279,10 +276,7 @@
 				this.tree.showNode(this.elements.text.parentNode);
 		
 				if (e && e["originatingEventType"] == "mousedown" /* can be keydown */) {
-					Event.observe(this.elements.icon, "mousemove", this.listenDragBound);
-					Event.observe(this.elements.text, "mousemove", this.listenDragBound);
-			
-					Event.observe(document, "mouseup", this.stopListenDragBound);
+					this.startDrag(e);
 				}
 			}
 		
@@ -322,23 +316,5 @@
 
 	hasChilds: function() {
 		return this.childs.length > 0;
-	},
-	
-	listenDrag: function(e) {
-		if (this.onupdatedrag(e)) {
-			if (this.startDrag(e)) {
-				Event.stopObserving(this.elements.icon, "mousemove", this.listenDragBound);
-				Event.stopObserving(this.elements.text, "mousemove", this.listenDragBound);
-		
-				Event.stopObserving(document, "mouseup", this.stopListenDragBound);
-			}
-		}
-	},
-	
-	stopListenDrag: function(e) {
-		Event.stopObserving(this.elements.icon, "mousemove", this.listenDragBound);
-		Event.stopObserving(this.elements.text, "mousemove", this.listenDragBound);
-
-		Event.stopObserving(document, "mouseup", this.stopListenDragBound);
 	}
 }




More information about the richfaces-svn-commits mailing list