Author: nbelaevski
Date: 2009-04-26 14:20:23 -0400 (Sun, 26 Apr 2009)
New Revision: 13880
Modified:
trunk/framework/impl/src/main/javascript/ajaxjsf/JSFAJAX.js
Log:
https://jira.jboss.org/jira/browse/RF-6910
Modified: trunk/framework/impl/src/main/javascript/ajaxjsf/JSFAJAX.js
===================================================================
--- trunk/framework/impl/src/main/javascript/ajaxjsf/JSFAJAX.js 2009-04-26 14:47:12 UTC
(rev 13879)
+++ trunk/framework/impl/src/main/javascript/ajaxjsf/JSFAJAX.js 2009-04-26 18:20:23 UTC
(rev 13880)
@@ -391,10 +391,50 @@
} else {
// need to check for firstChild due to opera 8 bug with hasChildNodes
Sarissa.clearChildNodes(oldnode);
- var importednode = window.document.importNode(newnode, true);
+
+ var importednode = window.document.importNode(newnode, true);
//importednode.innerHTML = importednode.innerHTML;
LOG.debug("Replace content of node by replaceChild()");
- anchor.replaceChild(importednode,oldnode);
+
+ var oldGetElementById = null;
+
+ A4J.AJAX.TestReplacedGetElementByIdVisibility();
+ if (!A4J.AJAX._testReplacedGetElementByIdVisibility) {
+ LOG.debug("Temporarily substituting document.getElementById() to work around
WebKit issue");
+ oldGetElementById = document.getElementById;
+ document.getElementById = function(id) {
+ var elt = oldGetElementById.apply(document, arguments);
+ if (!elt) {
+ var id = arguments[0];
+
+ LOG.debug("Element [@id='" + id + "'] was not found in
document, trying to locate XPath match");
+
+ try {
+ var result = importednode.ownerDocument.evaluate("//*[@id='" + id +
"']",
+ importednode, null, XPathResult.ANY_UNORDERED_NODE_TYPE);
+
+ if (result) {
+ elt = result.singleNodeValue;
+ }
+
+ LOG.debug("XPath located: " + elt);
+ } catch (e) {
+ LOG.error("Error locating [@id='" + id + "'] element:
" + e.message);
+ }
+ }
+
+ return elt;
+ };
+ }
+
+ try {
+ anchor.replaceChild(importednode,oldnode);
+ } finally {
+ if (oldGetElementById) {
+ LOG.debug("Restoring document.getElementById()");
+ document.getElementById = oldGetElementById;
+ }
+ }
}
// re-execute all script fragments in imported subtree...
@@ -1733,3 +1773,30 @@
}
A4J.AJAX._scriptTested = true;
}
+
+A4J.AJAX.TestReplacedGetElementByIdVisibility = function() {
+ if (!A4J.AJAX._replacedGetElementByIdVisibilityTested) {
+ A4J.AJAX._replacedGetElementByIdVisibilityTested = true;
+
+ A4J.AJAX.TestScriptEvaluation();
+ if (A4J.AJAX._scriptEvaluated) {
+ try {
+ A4J.AJAX._testReplacedGetElementByIdVisibility = true;
+
+ var _span = document.createElement("span");
+ document.body.appendChild(_span);
+
+ var xmlString = "<html
xmlns='http://www.w3.org/1999/xhtml'><span
id='_A4J_AJAX_TestReplacedGetElementByIdVisibility'><sc"+"ript>A4J.AJAX._testReplacedGetElementByIdVisibility
=
!!(document.getElementById('_A4J_AJAX_TestReplacedGetElementByIdVisibility'));</scr"+"ipt></span></html>";
+ oDomDoc = (new DOMParser()).parseFromString(xmlString, "text/xml");
+ var _newSpan = oDomDoc.getElementsByTagName("span")[0];
+
+ var importednode;
+ importednode = window.document.importNode(_newSpan, true);
+ document.body.replaceChild(importednode,_span);
+ document.body.removeChild(importednode);
+ } catch (e) {
+ LOG.error("Error testing replaced elements getElementById() visibility: " +
e.message);
+ }
+ }
+ }
+};