Author: nbelaevski
Date: 2008-01-25 18:32:21 -0500 (Fri, 25 Jan 2008)
New Revision: 5652
Added:
branches/3.1.x/framework/impl/src/main/javascript/jquery/patches.js
branches/3.1.x/framework/impl/src/main/javascript/memory.js
Removed:
branches/3.1.x/framework/impl/src/main/javascript/jquery/identity.js
Modified:
branches/3.1.x/framework/impl/generatescript.xml
branches/3.1.x/framework/impl/src/main/javascript/ajaxjsf/JSFAJAX.js
branches/3.1.x/framework/impl/src/main/javascript/prototype/patches.js
branches/3.1.x/ui/contextMenu/src/main/resources/org/richfaces/renderkit/html/scripts/context-menu.js
branches/3.1.x/ui/modal-panel/src/main/resources/org/richfaces/renderkit/html/scripts/modalPanel.js
Log:
http://jira.jboss.com/jira/browse/RF-1626
Modified: branches/3.1.x/framework/impl/generatescript.xml
===================================================================
--- branches/3.1.x/framework/impl/generatescript.xml 2008-01-25 20:09:30 UTC (rev 5651)
+++ branches/3.1.x/framework/impl/generatescript.xml 2008-01-25 23:32:21 UTC (rev 5652)
@@ -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>
@@ -60,14 +60,14 @@
</filelist>
- <filelist id="prototype"
+ <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"
@@ -75,7 +75,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: branches/3.1.x/framework/impl/src/main/javascript/ajaxjsf/JSFAJAX.js
===================================================================
--- branches/3.1.x/framework/impl/src/main/javascript/ajaxjsf/JSFAJAX.js 2008-01-25
20:09:30 UTC (rev 5651)
+++ branches/3.1.x/framework/impl/src/main/javascript/ajaxjsf/JSFAJAX.js 2008-01-25
23:32:21 UTC (rev 5652)
@@ -325,8 +325,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;
@@ -917,8 +917,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: branches/3.1.x/framework/impl/src/main/javascript/jquery/identity.js
===================================================================
--- branches/3.1.x/framework/impl/src/main/javascript/jquery/identity.js 2008-01-25
20:09:30 UTC (rev 5651)
+++ branches/3.1.x/framework/impl/src/main/javascript/jquery/identity.js 2008-01-25
23:32:21 UTC (rev 5652)
@@ -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
Added: branches/3.1.x/framework/impl/src/main/javascript/jquery/patches.js
===================================================================
--- branches/3.1.x/framework/impl/src/main/javascript/jquery/patches.js
(rev 0)
+++ branches/3.1.x/framework/impl/src/main/javascript/jquery/patches.js 2008-01-25
23:32:21 UTC (rev 5652)
@@ -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);
+ });
+ }
+};
Added: branches/3.1.x/framework/impl/src/main/javascript/memory.js
===================================================================
--- branches/3.1.x/framework/impl/src/main/javascript/memory.js
(rev 0)
+++ branches/3.1.x/framework/impl/src/main/javascript/memory.js 2008-01-25 23:32:21 UTC
(rev 5652)
@@ -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: branches/3.1.x/framework/impl/src/main/javascript/prototype/patches.js
===================================================================
--- branches/3.1.x/framework/impl/src/main/javascript/prototype/patches.js 2008-01-25
20:09:30 UTC (rev 5651)
+++ branches/3.1.x/framework/impl/src/main/javascript/prototype/patches.js 2008-01-25
23:32:21 UTC (rev 5652)
@@ -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:
branches/3.1.x/ui/contextMenu/src/main/resources/org/richfaces/renderkit/html/scripts/context-menu.js
===================================================================
---
branches/3.1.x/ui/contextMenu/src/main/resources/org/richfaces/renderkit/html/scripts/context-menu.js 2008-01-25
20:09:30 UTC (rev 5651)
+++
branches/3.1.x/ui/contextMenu/src/main/resources/org/richfaces/renderkit/html/scripts/context-menu.js 2008-01-25
23:32:21 UTC (rev 5652)
@@ -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:
branches/3.1.x/ui/modal-panel/src/main/resources/org/richfaces/renderkit/html/scripts/modalPanel.js
===================================================================
---
branches/3.1.x/ui/modal-panel/src/main/resources/org/richfaces/renderkit/html/scripts/modalPanel.js 2008-01-25
20:09:30 UTC (rev 5651)
+++
branches/3.1.x/ui/modal-panel/src/main/resources/org/richfaces/renderkit/html/scripts/modalPanel.js 2008-01-25
23:32:21 UTC (rev 5652)
@@ -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 = '';