Author: nbelaevski
Date: 2007-12-24 16:57:17 -0500 (Mon, 24 Dec 2007)
New Revision: 5002
Modified:
trunk/framework/impl/src/main/javascript/ajaxjsf/JSFAJAX.js
trunk/framework/impl/src/main/javascript/prototype/patches.js
trunk/framework/impl/src/main/javascript/prototype/prototype1.6.0.js
Log:
http://jira.jboss.com/jira/browse/RF-1567
Modified: trunk/framework/impl/src/main/javascript/ajaxjsf/JSFAJAX.js
===================================================================
--- trunk/framework/impl/src/main/javascript/ajaxjsf/JSFAJAX.js 2007-12-24 21:32:45 UTC
(rev 5001)
+++ trunk/framework/impl/src/main/javascript/ajaxjsf/JSFAJAX.js 2007-12-24 21:57:17 UTC
(rev 5002)
@@ -347,6 +347,12 @@
if( ! newnode ) { LOG.error("New node for ID "+id+" is not present in
response");return;}
var oldnode = window.document.getElementById(id);
if ( oldnode ) {
+
+ // Remove unload prototype events for a removed elements.
+ if ((typeof Event != "undefined") && (typeof
Event.unloadElementsCache == "function")) {
+ Event.unloadElementsCache(oldnode);
+ }
+
var anchor = oldnode.parentNode;
if(!window.opera && oldnode.outerHTML && !oldnode.tagName.match(
/(tbody|thead|tfoot|tr|th|td)/i ) ){
LOG.debug("Replace content of node by outerHTML()");
@@ -366,11 +372,6 @@
anchor.replaceChild(importednode,oldnode);
}
- // Remove unload prototype events for a removed elements.
- if ((typeof Event != "undefined") && (typeof
Event.unloadElementsCache == "function")) {
- Event.unloadElementsCache(oldnode);
- }
-
// re-execute all script fragments in imported subtree...
// TODO - opera 8 run scripts at replace content stage.
if(!A4J.AJAX._scriptEvaluated){
Modified: trunk/framework/impl/src/main/javascript/prototype/patches.js
===================================================================
--- trunk/framework/impl/src/main/javascript/prototype/patches.js 2007-12-24 21:32:45 UTC
(rev 5001)
+++ trunk/framework/impl/src/main/javascript/prototype/patches.js 2007-12-24 21:57:17 UTC
(rev 5002)
@@ -62,32 +62,47 @@
}
};
+//That's prototype version-dependent
+
+if (window.attachEvent) {
+ window.attachEvent("onunload", function() {
+ Event.unloadElementsCache(document);
+ Event.unloadElementsCache(window);
+ });
+}
+
Event.unloadElementsCache = function(oldNode) {
//refer to window.unload handling conditions in prototype script
if (!window.attachEvent) return;
if (!oldNode) return;
- if (oldNode) {
- if (oldNode._eventID) {
- var cache = Event.cache[oldNode._eventID];
+ var node = oldNode;
+ //node.all is quicker than recursive traversing
+ //window doesn't have "all" attribute
+ var all = node.all || {};
+ var counter = 0;
+
+ do {
+ var eventID = node._eventID;
+ if (eventID) {
+ var cache = Event.cache[eventID];
for (var eventName in cache) {
+ var wrappers = cache[eventName];
+
+ wrappers.each(function(wrapper) {
+ node.detachEvent("on" + eventName, wrapper);
+ });
+
cache[eventName] = null;
}
- delete Event.cache[oldNode._eventID];
+ delete Event.cache[eventID];
}
+
+ node = all[counter++];
+ } while (node);
+};
- var firstNode = oldNode.firstChild;
- if (firstNode) {
- Event.unloadElementsCache(firstNode);
-
- var nextNode = firstNode.nextSibling;
- while (nextNode) {
- Event.unloadElementsCache(nextNode);
- nextNode = nextNode.nextSibling;
- }
- }
- }
-};
\ No newline at end of file
+//
Modified: trunk/framework/impl/src/main/javascript/prototype/prototype1.6.0.js
===================================================================
--- trunk/framework/impl/src/main/javascript/prototype/prototype1.6.0.js 2007-12-24
21:32:45 UTC (rev 5001)
+++ trunk/framework/impl/src/main/javascript/prototype/prototype1.6.0.js 2007-12-24
21:57:17 UTC (rev 5002)
@@ -3858,16 +3858,18 @@
c[eventName] = c[eventName].without(findWrapper(id, eventName, handler));
}
- function destroyCache() {
- for (var id in cache)
- for (var eventName in cache[id])
- cache[id][eventName] = null;
- }
+// Commented by Nick
+//
+// function destroyCache() {
+// for (var id in cache)
+// for (var eventName in cache[id])
+// cache[id][eventName] = null;
+// }
+//
+// if (window.attachEvent) {
+// window.attachEvent("onunload", destroyCache);
+// }
- if (window.attachEvent) {
- window.attachEvent("onunload", destroyCache);
- }
-
return {
observe: function(element, eventName, handler) {
element = $(element);