Another fix to the render-order, for from document.write() collected output
[openx] / openx.js
index 3499345..579b16f 100644 (file)
--- a/openx.js
+++ b/openx.js
        * If output was added via document.write(), this output must be
        * rendered before other banner-code from the OpenX-server is rendered!
        */
-      if (output.length > 0) {
-        output.push(OA_output[id]);
-        OA_output[id] = "";
-        for (i=0; i<output.length; i++)
-          OA_output[id] += output[i];
-        output = [];
-      }
+      insert_output();
 
       while ((result = /<script/i.exec(OA_output[id])) != null) {
         node.append(OA_output[id].slice(0,result.index));
               inline = inline.slice(result[0].length,inline.length);
             }
             $.globalEval(inline);
+            insert_output(); // << The executed inline-code might have called document.write()!
           }
           else {
             /** script-tag with src-URL! */
     node = undefined;
   }
 
+  /** This function is used to overwrite document.write and document.writeln */
   function document_write() {
 
     for (var i=0; i<arguments.length; i++)
 
   }
 
+  /**
+   * This function prepends the collected output from calls to
+   * document_write() to the current banner-code.
+   */
+  function insert_output() {
+
+    if (output.length > 0) {
+      output.push(OA_output[id]);
+      OA_output[id] = "";
+      for (i=0; i<output.length; i++)
+        OA_output[id] += output[i];
+      output = [];
+    }
+
+  }
+
 } ( window.openx = window.openx || {}, jQuery ));
 
 var OA_output = {}; // << Needed, because IE will complain loudly otherwise!