[richfaces-svn-commits] JBoss Rich Faces SVN: r15929 - branches/sandbox/3.3.X_JSF2/ui/contextMenu/src/main/resources/org/richfaces/renderkit/html/scripts.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Thu Nov 19 02:48:38 EST 2009


Author: Alex.Kolonitsky
Date: 2009-11-19 02:48:37 -0500 (Thu, 19 Nov 2009)
New Revision: 15929

Modified:
   branches/sandbox/3.3.X_JSF2/ui/contextMenu/src/main/resources/org/richfaces/renderkit/html/scripts/context-menu.js
Log:
https://jira.jboss.org/jira/browse/RF-8074
Context menu destroyed not completely

Modified: branches/sandbox/3.3.X_JSF2/ui/contextMenu/src/main/resources/org/richfaces/renderkit/html/scripts/context-menu.js
===================================================================
--- branches/sandbox/3.3.X_JSF2/ui/contextMenu/src/main/resources/org/richfaces/renderkit/html/scripts/context-menu.js	2009-11-19 07:03:49 UTC (rev 15928)
+++ branches/sandbox/3.3.X_JSF2/ui/contextMenu/src/main/resources/org/richfaces/renderkit/html/scripts/context-menu.js	2009-11-19 07:48:37 UTC (rev 15929)
@@ -4,27 +4,40 @@
 Richfaces.ContextMenu.prototype = {
 	
 	initialize: function(id, delay, evaluator, options) {
-		this.options = options || {};
-		this.id = id;
-		this.element = $(id);
-		this.menuContent = null;
+        this.id = id;
+        this.element = $(id);
+        this.element.component = this;
+        this.menuContent = null;
+
+        this.options = options || {};
 		this.evaluator = evaluator;
-		this.element.component = this;
 		this["rich:destructor"] = "destroy";
+
 		this.doShow = this.show;
 		this.doHide = this.hide;
 		this.delay = delay;
+
+        this.attachedToElementId = null;
+        this.attachedTo = [];
 	},
 	
 	destroy: function() {
+        for (var elementId in this.attachedTo) {
+            var element = $(elementId);
+            if (element) {
+                var attached = this.attachedTo[elementId];
+                Event.stopObserving(element, attached['eventName'], attached['listener']);
+            }
+        }
+
 		this.enableDefaultContextMenu();
 		this.element.component = null;
 		this.element = null;
 		this.menuContent = null;
+        this.attachedTo = [];
 	},
 	
-	disableDefaultContextMenu: function (element, id, event, attachedToPerent)
-	{
+	disableDefaultContextMenu: function (element, id, event, attachedToPerent) {
 		if (event=="oncontextmenu") {
 			this.attachedToElementId = id;
 			this.attachedToParent = attachedToPerent;
@@ -34,9 +47,8 @@
 		}	
 	},
 	
-	enableDefaultContextMenu: function ()
-	{
-		if (this.eventName=="contextmenu" && this.attachedToElementId) {
+	enableDefaultContextMenu: function () {
+		if (this.eventName == "contextmenu" && this.attachedToElementIds.length) {
 			var element = $(this.attachedToElementId);
 			if (!element && this.attachedToParent) {
 				element = this.element;
@@ -72,18 +84,28 @@
 	
 	// attach contextMenu to specified element
 	attachToElement : function(element, event, context) {
-		if (element) {
-			this.applyDecoration(element);
+		if (!element) {
+            return;
+        }
 
-			//Strip 'on' here 
-			var evnName = event.substr(2);
-			// http://jira.jboss.com/jira/browse/RF-3419
-			if(evnName == 'contextmenu') {
-				Richfaces.enableDefaultHandler('click');
-			}
-			var listener = this.show.bindAsEventListener(this, context);
-			Event.observe(element, evnName, listener);
-		}
+        this.applyDecoration(element);
+
+        var evnName = event.substr(2); //Strip 'on' here
+        // http://jira.jboss.com/jira/browse/RF-3419
+        if(evnName == 'contextmenu') {
+            Richfaces.enableDefaultHandler('click');
+        }
+
+        var listener = this.show.bindAsEventListener(this, context);
+        Event.observe(element, evnName, listener);
+        if (element.id) {
+            this.attachedTo[element.id] = {
+                'eventName' : evnName,
+                'listener' : listener
+            };
+        }
+
+
 	},
 	
 	hide: function() {
@@ -140,13 +162,7 @@
 	},
 	
 	applyDecoration : function(element) {
-		
 		$(element).addClassName("rich-cm-attached");
-		
-		/*var f = this.options.applyDecorations;
-		if (f) {
-			f(element);
-		}*/
 	}
 };
 
@@ -159,7 +175,7 @@
 
 Richfaces.enableDefaultHandler = function(event) {
 	if (event.startsWith('on')) {
-	event = event.substr(2);
+	    event = event.substr(2);
 	}
 	Event.stopObserving(document, event, Event.stop);
 };
\ No newline at end of file



More information about the richfaces-svn-commits mailing list