[richfaces-svn-commits] JBoss Rich Faces SVN: r5681 - in trunk: framework/impl/src/main/javascript and 5 other directories.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Mon Jan 28 19:11:21 EST 2008


Author: nbelaevski
Date: 2008-01-28 19:11:21 -0500 (Mon, 28 Jan 2008)
New Revision: 5681

Added:
   trunk/framework/impl/src/main/javascript/jquery/patches.js
   trunk/framework/impl/src/main/javascript/memory.js
Removed:
   trunk/framework/impl/src/main/javascript/jquery/identity.js
Modified:
   trunk/framework/impl/generatescript.xml
   trunk/framework/impl/src/main/javascript/ajaxjsf/JSFAJAX.js
   trunk/framework/impl/src/main/javascript/prototype/patches.js
   trunk/ui/contextMenu/src/main/resources/org/richfaces/renderkit/html/scripts/context-menu.js
   trunk/ui/modal-panel/src/main/resources/org/richfaces/renderkit/html/scripts/modalPanel.js
Log:
http://jira.jboss.com/jira/browse/RF-1626

Modified: trunk/framework/impl/generatescript.xml
===================================================================
--- trunk/framework/impl/generatescript.xml	2008-01-28 23:35:01 UTC (rev 5680)
+++ trunk/framework/impl/generatescript.xml	2008-01-29 00:11:21 UTC (rev 5681)
@@ -50,7 +50,7 @@
 -->	
 	<filelist id="jquery"
 	          dir="${basedir}/src/main/javascript/jquery"
-	          files="jquery-1.2.1.js,noConflict.js,identity.js">
+	          files="jquery-1.2.1.js,noConflict.js,../memory.js,patches.js">
 	</filelist>
 
 	<filelist id="scriptaculous"
@@ -61,12 +61,12 @@
 
     <filelist id="prototype"
 		          dir="${basedir}/src/main/javascript/prototype"
-		          files="prototype1.6.0.js,patches.js">
+		          files="prototype1.6.0.js,../memory.js,patches.js">
 	</filelist>
 
 	<filelist id="prototype.extend"
 	          dir="${basedir}/src/main/javascript/prototype"
-		      files="dom.js,form.js,event.js,position.js,patches.js">
+		      files="dom.js,form.js,event.js,position.js,../memory.js,patches.js">
 	</filelist>
 
 	<filelist id="dnd"
@@ -74,7 +74,7 @@
 			      files="prolog.js,dnd.js,epilog.js">
 	</filelist>
 
-    <filelist id="ajaxjsf" dir="${basedir}/src/main/javascript/ajaxjsf" files="prolog.js,sarissa.js,JSFAJAX.js,log4ajax.js,epilog.js"></filelist>   
+    <filelist id="ajaxjsf" dir="${basedir}/src/main/javascript/ajaxjsf" files="prolog.js,sarissa.js,JSFAJAX.js,log4ajax.js,epilog.js,../memory.js"></filelist>   
 	<!-- ================================= 
           target: assemble              
          ================================= -->

Modified: trunk/framework/impl/src/main/javascript/ajaxjsf/JSFAJAX.js
===================================================================
--- trunk/framework/impl/src/main/javascript/ajaxjsf/JSFAJAX.js	2008-01-28 23:35:01 UTC (rev 5680)
+++ trunk/framework/impl/src/main/javascript/ajaxjsf/JSFAJAX.js	2008-01-29 00:11:21 UTC (rev 5681)
@@ -350,8 +350,8 @@
 		if ( oldnode  ) {
 			
 	   	    // Remove unload prototype events for a removed elements.
-			if ((typeof Event != "undefined") && (typeof Event.unloadElementsCache == "function")) {
-			  	Event.unloadElementsCache(oldnode);
+			if (window.RichFaces && window.RichFaces.Memory) {
+				window.RichFaces.Memory.clean(oldnode);
 			}        	  
 			
 			var anchor = oldnode.parentNode;
@@ -950,8 +950,8 @@
 									}
 								 }
 								  //TODO - unloading cached observers?
-								  //if (typeof Event != "undefined" && typeof Event.unloadElementsCache == "function") {
-								  	//Event.unloadElementsCache();
+								  //if (window.RichFaces && window.RichFaces.Memory) {
+								  //	  window.RichFaces.Memory.clean(oldnode);
 								  //}        	  
 								} else {
 									LOG.error("Error parsing response",Sarissa.getParseErrorText(oDomDoc));

Deleted: trunk/framework/impl/src/main/javascript/jquery/identity.js
===================================================================
--- trunk/framework/impl/src/main/javascript/jquery/identity.js	2008-01-28 23:35:01 UTC (rev 5680)
+++ trunk/framework/impl/src/main/javascript/jquery/identity.js	2008-01-29 00:11:21 UTC (rev 5681)
@@ -1,10 +0,0 @@
-if (jQuery(jQuery) != jQuery) {
-	var oldJQuery = jQuery;
-	jQuery = function() {
-		if (arguments[0] == arguments.callee) {
-			return arguments.callee;
-		} else {
-			return oldJQuery.apply(this, arguments);
-		}
-	};
-};
\ No newline at end of file

Copied: trunk/framework/impl/src/main/javascript/jquery/patches.js (from rev 5652, branches/3.1.x/framework/impl/src/main/javascript/jquery/patches.js)
===================================================================
--- trunk/framework/impl/src/main/javascript/jquery/patches.js	                        (rev 0)
+++ trunk/framework/impl/src/main/javascript/jquery/patches.js	2008-01-29 00:11:21 UTC (rev 5681)
@@ -0,0 +1,16 @@
+if (jQuery(jQuery) != jQuery) {
+	var oldJQuery = jQuery;
+	jQuery = function() {
+		if (arguments[0] == arguments.callee) {
+			return arguments.callee;
+		} else {
+			return oldJQuery.apply(this, arguments);
+		}
+	};
+	
+	if (window.RichFaces && window.RichFaces.Memory) {
+		window.RichFaces.Memory.addCleaner("jquery", function(node) {
+			oldJQuery.event.remove(node);
+		});
+	}
+};

Copied: trunk/framework/impl/src/main/javascript/memory.js (from rev 5652, branches/3.1.x/framework/impl/src/main/javascript/memory.js)
===================================================================
--- trunk/framework/impl/src/main/javascript/memory.js	                        (rev 0)
+++ trunk/framework/impl/src/main/javascript/memory.js	2008-01-29 00:11:21 UTC (rev 5681)
@@ -0,0 +1,70 @@
+//memory-leaks sanitizing code
+if (!window.RichFaces) {
+	window.RichFaces = {};
+}
+
+if (!window.RichFaces.Memory) {
+	window.RichFaces.Memory = {
+
+		cleaners: {},
+		
+		addCleaner: function (name, cleaner) {
+			this.cleaners[name] = cleaner;
+		},
+
+		applyCleaners: function (node) {
+			for (var name in this.cleaners) {
+				this.cleaners[name](node);
+			}
+		},
+		
+		clean: function (oldNode) {
+		    if (oldNode) {
+		    	this.applyCleaners(oldNode);
+			
+				//node.all is quicker than recursive traversing
+			    //window doesn't have "all" attribute
+			    var all = oldNode.all;
+			    
+			    if (all) {
+			        var counter = 0;
+			        var length = all.length;
+			        
+			        for (var counter = 0; counter < length; counter++ ) {
+				    	this.applyCleaners(all[counter]);
+			        }
+			    } else {
+			    	var node = oldNode.firstChild;
+			    	while (node) {
+			    		this.clean(node);
+			        	node = node.nextSibling;
+			    	}
+			    }
+		    }
+		}
+	};
+	
+	window.RichFaces.Memory.addCleaner("richfaces", function(node) {
+		var component = node.component;
+		if (component) {
+			var destructorName = component["rich:destructor"];
+			//destructor name is required to be back-compatible
+			if (destructorName) {
+				var destructor = component[destructorName];
+				if (destructor) {
+					destructor.call(component);
+				}
+			}
+		}
+	});
+	
+	if (window.attachEvent) {
+	    window.attachEvent("onunload", function() {
+	    	var memory = window.RichFaces.Memory;
+	    	memory.clean(document);
+	    	memory.clean(window);
+	    });
+	}
+}
+
+//
\ No newline at end of file

Modified: trunk/framework/impl/src/main/javascript/prototype/patches.js
===================================================================
--- trunk/framework/impl/src/main/javascript/prototype/patches.js	2008-01-28 23:35:01 UTC (rev 5680)
+++ trunk/framework/impl/src/main/javascript/prototype/patches.js	2008-01-29 00:11:21 UTC (rev 5681)
@@ -62,75 +62,30 @@
 	}
 };
 
-//That's prototype version-dependent
-
-if (window.attachEvent) {
-    window.attachEvent("onunload", function() {
-    	Event.unloadElementsCache(document);
-    	Event.unloadElementsCache(window);
-    });
-}
-
-Event.destroyEventCache = function(node) {
-	var eventID = node._eventID;
-	if (eventID) {
-		var cache = Event.cache[eventID];
-    	
-        for (var eventName in cache) {
-        	var wrappers = cache[eventName];
-        	var domEventName = Event.getDOMEventName(eventName);
-        	
-        	wrappers.each(function(wrapper) {
-				if (node.removeEventListener) {
-					node.removeEventListener(domEventName, wrapper, false);
-				} else {
-					node.detachEvent("on" + domEventName, wrapper);
-				}
-            });            	
-    		
-            cache[eventName] = null;
-        }
-
-        delete Event.cache[eventID];
-	}
+if (window.RichFaces && window.RichFaces.Memory) {
+	window.RichFaces.Memory.addCleaner("prototype", function(node) {
+		var eventID = node._eventID;
+		if (eventID) {
+			var cache = Event.cache[eventID];
+	    	
+	        for (var eventName in cache) {
+	        	var wrappers = cache[eventName];
+	        	var domEventName = Event.getDOMEventName(eventName);
+	        	
+	        	wrappers.each(function(wrapper) {
+					if (node.removeEventListener) {
+						node.removeEventListener(domEventName, wrapper, false);
+					} else {
+						node.detachEvent("on" + domEventName, wrapper);
+					}
+	            });            	
+	    		
+	            cache[eventName] = null;
+	        }
 	
-	var component = node.component;
-	if (component) {
-		var destructorName = component["rich:destructor"];
-		//destructor name is required to be back-compatible
-		if (destructorName) {
-			var destructor = component[destructorName];
-			if (destructor) {
-				destructor.call(component);
-			}
+	        delete Event.cache[eventID];
 		}
-	}
+	});
 }
 
-Event.unloadElementsCache = function(oldNode) {
-    if (oldNode) {
-		Event.destroyEventCache(oldNode);
-	
-		//node.all is quicker than recursive traversing
-	    //window doesn't have "all" attribute
-	    var all = oldNode.all;
-	    
-	    if (all) {
-	        var counter = 0;
-	        var length = all.length;
-	        
-	        for (var counter = 0; counter < length; counter++ ) {
-	        	Event.destroyEventCache(all[counter]);
-	        }
-	    } else {
-	    	var node = oldNode.firstChild;
-	    	while (node) {
-	    		Event.unloadElementsCache(node);
-	        	node = node.nextSibling;
-	    	}
-	    }
-    }
-    
-};
-
 //

Modified: trunk/ui/contextMenu/src/main/resources/org/richfaces/renderkit/html/scripts/context-menu.js
===================================================================
--- trunk/ui/contextMenu/src/main/resources/org/richfaces/renderkit/html/scripts/context-menu.js	2008-01-28 23:35:01 UTC (rev 5680)
+++ trunk/ui/contextMenu/src/main/resources/org/richfaces/renderkit/html/scripts/context-menu.js	2008-01-29 00:11:21 UTC (rev 5681)
@@ -6,17 +6,27 @@
 	initialize: function(id, delay, evaluator, options) {
 		this.options = options || {};
 		this.id = id;
+		this.element = $(id);
+		this.menuContent = null;
 		this.evaluator = evaluator;
-		$(id).component = this;
+		this.element.component = this;
+		this["rich:destructor"] = "destroy";
+		
 		this.doShow = this.show;
 		this.doHide = this.hide;
 		this.delay = delay;
 	},
 	
+	destroy: function() {
+		this.element.component = null;
+		this.element = null;
+		this.menuContent = null;
+	},
+	
 	attachToParent : function(id, event, context) {
 		var element = $(id);
 		if (!element) {
-			element = $(this.id);
+			element = this.element;
 			if (element) {
 				element = element.parentNode;
 			}
@@ -47,23 +57,25 @@
 	
 	construct: function(context) {
 		if (this.isNewContext(context)) {
-			this.destroy();
+			this.destroyMenu();
 		}
+		
 		var div = document.createElement("div");
 		div.id = this.id + ":_auto_created";
-		$(this.id).appendChild(div);
+		this.element.appendChild(div);
+		
 		var html = this.evaluator.invoke('getContent', context||window).join('');
 		new Insertion.Top(div, html);
 		
+		this.menuContent = div;
 	},
 	
-	destroy: function() {
-		var div = $(this.id + ":_auto_created");
-		Richfaces.infernalCachePurge(div);
-		if (div) {
-			div.parentNode.removeChild(div);
+	destroyMenu: function() {
+		if (this.menuContent) {
+			window.RichFaces.Memory.clean(this.menuContent);
+			this.menuContent.parentNode.removeChild(this.menuContent);
+			this.menuContent = null;
 		}
-		
 	},
 	
 	isNewContext: function(context) {
@@ -92,22 +104,8 @@
 };
 
 Richfaces.enableDefaultHandler = function(event) {
-	if (event.startsWith('on')) {
+	if (event.startsWith('on')) {
 	event = event.substr(2);
 	}
 	Event.stopObserving(document, event, Event.stop);
-};
-
-
-Richfaces.infernalCachePurge = function(root) {
-	if (root) {
-		if (root._eventID) {
-			Event.stopObserving(root);
-		}
-		var child = root.firstChild;
-		while(child) {
-			Richfaces.infernalCachePurge(child);
-			child = child.nextSibling;
-		}
-	}
 };
\ No newline at end of file

Modified: trunk/ui/modal-panel/src/main/resources/org/richfaces/renderkit/html/scripts/modalPanel.js
===================================================================
--- trunk/ui/modal-panel/src/main/resources/org/richfaces/renderkit/html/scripts/modalPanel.js	2008-01-28 23:35:01 UTC (rev 5680)
+++ trunk/ui/modal-panel/src/main/resources/org/richfaces/renderkit/html/scripts/modalPanel.js	2008-01-29 00:11:21 UTC (rev 5681)
@@ -18,7 +18,7 @@
         document.body.appendChild(garbageBin);
     }
 
-    Event.unloadElementsCache(element);
+	window.RichFaces.Memory.clean(element);
     // move the element to the garbage bin
     garbageBin.appendChild(element);
     garbageBin.innerHTML = '';




More information about the richfaces-svn-commits mailing list