[richfaces-svn-commits] JBoss Rich Faces SVN: r4876 - 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
Mon Dec 17 12:38:38 EST 2007


Author: abelevich
Date: 2007-12-17 12:38:38 -0500 (Mon, 17 Dec 2007)
New Revision: 4876

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-dropzone.js
Log:
add drop cursors support

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-17 17:38:05 UTC (rev 4875)
+++ trunk/framework/impl/src/main/resources/org/richfaces/renderkit/html/scripts/dnd/dnd-draggable.js	2007-12-17 17:38:38 UTC (rev 4876)
@@ -66,6 +66,10 @@
 		this.element = element;
 		this.cursor = cursor;
 		this.visible = false;
+		if (this.element.style.cursor && this.element.style.cursor != "") {
+			//save cursor if exist
+			this.oldcursor = this.element.style.cursor;
+		}	 
 	},
 	
 	showCursor: function() {
@@ -78,6 +82,10 @@
 		var parent = this.element;
 		parent.style.cursor = "" ;
 		this.visible = false;
+		if (this.oldcursor) {
+			//restore saved cursor
+			Element.setStyle(parent,"cursor: " + this.oldcursor);
+		} 
 	}
 
 }; 

Modified: trunk/framework/impl/src/main/resources/org/richfaces/renderkit/html/scripts/dnd/dnd-dropzone.js
===================================================================
--- trunk/framework/impl/src/main/resources/org/richfaces/renderkit/html/scripts/dnd/dnd-dropzone.js	2007-12-17 17:38:05 UTC (rev 4875)
+++ trunk/framework/impl/src/main/resources/org/richfaces/renderkit/html/scripts/dnd/dnd-dropzone.js	2007-12-17 17:38:38 UTC (rev 4876)
@@ -38,6 +38,11 @@
 	getTypeMapping: function() {
 		return {};
 	},
+	
+	getCursorTypeMapping: function() {
+		return {};
+	},	
+	
 	drop: function(event, drag){
 	},
 
@@ -48,7 +53,14 @@
 		}
 		return null;
 	},
-
+	
+	getCursorForType: function(type) {
+		var types = this.getCursorTypeMapping();
+		if(type && types) {
+			return types[type];
+		}		
+	}, 
+	
 	/**
 	 * implementations call this method when mouse over them
 	 * @param {Object} drag
@@ -62,10 +74,21 @@
 		var indicator = drag.indicator;
 		
 		var accepts = this.accept(drag);
-		
-		if (accepts && this.acceptCursor) {
-			this.acceptCursor.showCursor();
+					
+		if (accepts) {
+			// resolve acceptable cursor from drop type mapping
+			var cursor = this.getCursorForType(drag.type);
+			if (cursor) {
+				// show resolved cursor
+				this.acceptMappingCursor = new DnD.Cursor(this.getElement(), "cursor: " + cursor);
+				this.acceptMappingCursor.showCursor();
+			} else if(this.acceptCursor) {
+				// show default cursor
+				this.acceptCursor.showCursor();
+			}
+			
 		} else if (this.rejectCursor){
+			//show reject cursor
 			this.rejectCursor.showCursor();
 		}		
 				
@@ -133,31 +156,50 @@
 		if (opts && opts.ondragexit) {
 			opts.ondragexit(event);
 		}
-		
+	
+	//  reset visible cursor if we leave dropzone
 		if (this.acceptCursor) {
 			if (this.acceptCursor.visible) { 
 				this.acceptCursor.hideCursor();
 			}	
-		} else if (this.rejectCursor){
+		} 
+		
+		if (this.rejectCursor){
 			if (this.rejectCursor.visible) {
 				this.rejectCursor.hideCursor();
 			}	
 		}		
+		
+		if (this.acceptMappingCursor){
+			if (this.acceptMappingCursor.visible) {
+				this.acceptMappingCursor.hideCursor();
+			}	
+		}	
 	},
 
 	dragUp: function(event) {
         this.ondropend(event);
 		
+	//  reset visible cursor drop ended
 		if (this.acceptCursor) {
 			if (this.acceptCursor.visible) { 
 				this.acceptCursor.hideCursor();
 			}	
-		} else if (this.rejectCursor){
+		} 
+		
+		if (this.rejectCursor){
 			if (this.rejectCursor.visible) {
 				this.rejectCursor.hideCursor();
 			}	
-		}		
+		}
 		
+		if (this.acceptMappingCursor){
+			if (this.acceptMappingCursor.visible) {
+				this.acceptMappingCursor.hideCursor();
+			}	
+		}	
+			
+		
 		var options = this.getDropzoneOptions();
 		if (options && options.ondropend) {
 			options.ondropend();




More information about the richfaces-svn-commits mailing list