cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sylv...@apache.org
Subject svn commit: r330513 - /cocoon/blocks/ajax/trunk/java/org/apache/cocoon/ajax/resources/js/cocoon-ajax.js
Date Thu, 03 Nov 2005 08:58:12 GMT
Author: sylvain
Date: Thu Nov  3 00:58:08 2005
New Revision: 330513

URL: http://svn.apache.org/viewcvs?rev=330513&view=rev
Log:
Fix issue COCOON-1672: help popups don't work with Ajax

Modified:
    cocoon/blocks/ajax/trunk/java/org/apache/cocoon/ajax/resources/js/cocoon-ajax.js

Modified: cocoon/blocks/ajax/trunk/java/org/apache/cocoon/ajax/resources/js/cocoon-ajax.js
URL: http://svn.apache.org/viewcvs/cocoon/blocks/ajax/trunk/java/org/apache/cocoon/ajax/resources/js/cocoon-ajax.js?rev=330513&r1=330512&r2=330513&view=diff
==============================================================================
--- cocoon/blocks/ajax/trunk/java/org/apache/cocoon/ajax/resources/js/cocoon-ajax.js (original)
+++ cocoon/blocks/ajax/trunk/java/org/apache/cocoon/ajax/resources/js/cocoon-ajax.js Thu Nov
 3 00:58:08 2005
@@ -57,28 +57,61 @@
         }
     }
 }
-
+cocoon.ajax.DOMUtils.ScriptRegexp = '(?:<script.*?>)((\n|.)*?)(?:<\/script>)';
 /**
  * Imports an element into a document, taking care of using the correct implementation
- * so that the browser interprets it as displayable XML
+ * so that the browser interprets it as displayable XML.
+ * Any <script> in the imported node are collected and evaluated after the import
  */
 cocoon.ajax.DOMUtils.importNode = function(node, targetDoc) {
+    var result;
     if(node.xml) {
         // IE
         var div = targetDoc.createElement("DIV");
-        div.innerHTML = node.xml;
-        return this.firstChildElement(div);
+        var text = node.xml;
+        
+        // Extract scripts
+        var match    = new RegExp(cocoon.ajax.DOMUtils.ScriptRegexp, 'img');
+        
+        // Update screen
+        div.innerHTML = text.replace(match, '');
+
+        // And evaluate scripts with a small delay (looks like IE doesn't
+        // immediately update the DOM after setting innerHTML?)
+        var scripts  = text.match(match);
+        if (scripts) {
+	        setTimeout(function() {
+	            var match = new RegExp(cocoon.ajax.DOMUtils.ScriptRegexp, 'im');
+	            for (var i = 0; i < scripts.length; i++) {
+	                eval(scripts[i].match(match)[1]);
+	            }
+	        }, 10);
+	    }
+        
+        result = this.firstChildElement(div);
+        
     } else {
-        return this._importNode(node, targetDoc);
+        var scripts = new Array();
+        result = this._importNode(node, targetDoc, scripts);
+        for (var i = 0; i < scripts.length; i++) {
+              eval(scripts[i]);
+        }
     }
+    return result;
 }
 
 /**
- * DOM implementation of importNode, recursively creating nodes
+ * DOM implementation of importNode, recursively creating nodes.
+ * Scripts are collected in the "scripts" parameter
  */
-cocoon.ajax.DOMUtils._importNode = function(node, targetDoc) {
+cocoon.ajax.DOMUtils._importNode = function(node, targetDoc, scripts) {
     switch(node.nodeType) {
         case this.ELEMENT_NODE:
+            if (node.nodeName.toLowerCase() == "script") {
+                // Collect scripts
+                scripts.push(node.firstChild && node.firstChild.nodeValue);
+                return;
+            }
             var element = targetDoc.createElement(node.nodeName);
             //var element = targetDoc.createElementNS(node.namespaceURI, node.nodeName);
             var attrs = node.attributes;



Mime
View raw message