Polishing the code...
[openx] / openx.js
index 579b16f..bfd49a5 100644 (file)
--- a/openx.js
+++ b/openx.js
     name,
     src = domain;
 
-    document.write = document_write;
-    document.writeln = document_write;
+    /**
+     * Without this option, jQuery appends an timestamp to every URL, that
+     * is fetched via $.getScript(). This can mess up badly written
+     * third-party-ad-scripts, that assume that the called URL's are not
+     * altered.
+     */
+    $.ajaxSetup({ cache: true });
 
     src += "/www/delivery/spc.php?zones=";
 
@@ -66,6 +71,9 @@
         ads.push(id);
     }
 
+    document.write = document_write;
+    document.writeln = document_write;
+
     render_ads();
 
   }
           }
           else {
             /** script-tag with src-URL! */
-            ads.unshift(id); // << The banner might not be rendered fully, or include more calls to document.write().
+            if (OA_output[id].length > 0)
+              /** The banner-code was not rendered completely yet! */
+              ads.unshift(id);
             /** Load the script and halt all work until the script is loaded and executed... */
             $.getScript(result[1], render_ads); // << jQuery.getScript() generates onload-Handler for _all_ browsers ;)
             return;
   /** This function is used to overwrite document.write and document.writeln */
   function document_write() {
 
+    if (id == undefined)
+      return;
+
     for (var i=0; i<arguments.length; i++)
       output.push(arguments[i]);