[richfaces-svn-commits] JBoss Rich Faces SVN: r4570 - trunk/framework/impl/src/main/resources/org/richfaces/renderkit/html/scripts/dnd.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Thu Dec 6 14:18:16 EST 2007


Author: abelevich
Date: 2007-12-06 14:18:16 -0500 (Thu, 06 Dec 2007)
New Revision: 4570

Modified:
   trunk/framework/impl/src/main/resources/org/richfaces/renderkit/html/scripts/dnd/dnd-draggable.js
Log:
add grab and grabbing cursor support for the rich:dragSupport (RF-1403)

Modified: trunk/framework/impl/src/main/resources/org/richfaces/renderkit/html/scripts/dnd/dnd-draggable.js
===================================================================
--- trunk/framework/impl/src/main/resources/org/richfaces/renderkit/html/scripts/dnd/dnd-draggable.js	2007-12-06 18:39:12 UTC (rev 4569)
+++ trunk/framework/impl/src/main/resources/org/richfaces/renderkit/html/scripts/dnd/dnd-draggable.js	2007-12-06 19:18:16 UTC (rev 4570)
@@ -59,6 +59,29 @@
 
 };
 
+DnD.Cursor = Class.create();
+DnD.Cursor.prototype = {
+	
+	initialize: function(element,cursor) {
+		this.element = element;
+		this.cursor = cursor;
+		this.visible = false;
+	},
+	
+	showCursor: function() {
+		var parent = this.element;
+		Element.setStyle(parent,this.cursor);
+		this.visible = true;
+	},
+	
+	hideCursor: function() {
+		var parent = this.element;
+		parent.style.cursor = "" ;
+		this.visible = false;
+	}
+
+}; 
+
 DnD.Draggable.prototype = {
 
 	getElement: function() {
@@ -144,7 +167,15 @@
 
 	startDrag : function(event) {
 		var contentType = this.getContentType();
-
+		
+		if(this.grabbingCursor) {
+			if(this.grabCursor && this.grabCursor.visible) {
+				this.grabCursor.hideCursor();
+			}
+			this.grabbingCursor.showCursor();		
+		} 
+		window.status= document.body.style.cursor;
+					
 		if (contentType) {
 			if (!this.endDragListener) {
 				this.dragTrigger = this.moveDrag.bindAsEventListener(this);
@@ -213,6 +244,7 @@
 	 */
 	endDrag: function(event, drag) {
 		DnD.endDrag(event);
+		
 		this.lastDragX = undefined;
 		this.lastDragY = undefined;
 		
@@ -234,13 +266,28 @@
 			}
 	
 			this.ondragend(event, drag);
+			
 		}
 		
+		var grabbingCursor = this.getCurrentGrabbingCursor();
+					
+		if (grabbingCursor) {
+			if (grabbingCursor.visible) {
+				grabbingCursor.hideCursor();
+			}	
+		}
+		window.status= document.body.style.cursor;
+		
+		
 		var options = this.getDraggableOptions();
 		if (options && options.ondragend) {
 			options.ondragend(event);
 		}
     },
+     
+    attachCursor: function () {
+    	this.cursor = new DnD.Cursor(); 
+    },
     
 	/**
 	 * cubclasses may define custom behavior
@@ -254,6 +301,64 @@
 
 	},
 	
+	ondragover: function(event) {
+		var grabCursor = this.getCurrentGrabCursor();
+		if(!document.body.style.cursor) {
+			if(grabCursor) {
+				if(!grabCursor.visible) {
+					grabCursor.showCursor();
+				}	
+			}
+		}
+		this.i = this.i + 1
+		window.status= this.i;	
+	},
+	
+	ondragout: function(event) {
+		var grabCursor = this.getCurrentGrabCursor();
+		if (grabCursor) {
+			if(grabCursor.visible) {
+				grabCursor.hideCursor();
+			}  
+		}
+		window.status= document.body.style.cursor;
+	}, 
+	
+	getCurrentGrabbingCursor: function() {
+		var drag = window.drag;
+		var grabbingCursor = this.grabbingCursor;
+		if(drag) {
+			grabbingCursor = drag.source.grabbingCursor;
+		} 
+		return 	grabbingCursor;	
+	},
+	
+	getCurrentGrabCursor: function() {
+		var drag = window.drag;
+		var grabCursor = this.grabCursor
+		if(drag) {
+			grabCursor = drag.source.grabCursor;
+		} 
+		return grabCursor;
+	},
+	
+	onmouseup: function (event) {
+		var grabbingCursor = this.getCurrentGrabbingCursor(); 
+		var grabCursor = this.grabCursor;
+		
+		if(grabbingCursor && grabbingCursor.visible) {
+			grabbingCursor.hideCursor();
+		}
+		
+		if(grabCursor) {
+			grabCursor.showCursor();
+		}
+		
+		window.status= document.body.style.cursor;
+		
+		
+	},
+	
 	ondropover: function(event, drag) {
 		var options = this.getDraggableOptions();
 		if (options && options.ondropover) {
@@ -268,8 +373,53 @@
 			event.drag = drag;
 			options.ondropout(event);
 		}
-	}
+	},
 	
+	enableDraggableCursors: function() {
+			 
+		if(this.options){
+			var element = this.getElement();
+				
+			if(this.options.grab){
+				
+				this.dragOutBound = this.ondragout.bindAsEventListener(this);
+				this.dragOverBound = this.ondragover.bindAsEventListener(this);
+				this.dragUpBound = this.onmouseup.bindAsEventListener(this);
+				
+				Event.observe(element, "mouseout", this.dragOutBound);
+				Event.observe(element, "mouseover", this.dragOverBound);
+				Event.observe(element, "mouseup", this.dragUpBound);
+				this.i = 0;	
+				this.grabCursor = new DnD.Cursor(element,this.options.grab);
+			} 
+		
+			if (this.options.grabbing) {
+				
+				this.grabbingCursor = new DnD.Cursor(document.body,this.options.grabbing);
+			}
+		}
+		
+	},
+	
+	disableDraggableCursors: function() {
+		var element = this.getElement();
+		if(this.dragOutBound && this.dragOverBound) {
+			Event.stopObserving(element, "mouseover", this.dragOutBound);
+			Event.stopObserving(element, "mouseout", this.dragOverBound);
+		} else {
+			return false;
+		}
+		return true;
+	},
+	
+	isDraggableCursorsEnabled: function() {
+		if (this.isCursorsEnabled) {
+			this.isCursorsEnabled = true;
+		} else {
+			this.isCursorsEnabled = false;
+		}
+		return this.isCursorsEnabled;
+	} 
 };
 
 DefaultDragIndicator = {




More information about the richfaces-svn-commits mailing list