count = 0,
slots = {},
queue = [],
- ads = [];
+ ads = [],
+ output = [];
openx.show_ads = function(server, zones) {
name,
src = domain;
+ /**
+ * 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 });
+
document.write = document_write;
document.writeln = document_write;
while (ads.length > 0) {
+ var result, src, inline, i;
+
id = ads.shift();
node = slots[id];
// node.append(id + ": " + node.attr('class'));
- var result, src, inline;
+ /**
+ * If output was added via document.write(), this output must be
+ * rendered before other banner-code from the OpenX-server is rendered!
+ */
+ 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() {
- if (id == undefined)
- return;
+ for (var i=0; i<arguments.length; i++)
+ output.push(arguments[i]);
- var
- str = "",
- i;
+ if (id != ads[0])
+ /**
+ * Re-Add the last banner-code to the working-queue, because included
+ * scripts had added markup via document.write(), which is not
+ * proccessed yet.
+ * Otherwise the added markup would be falsely rendered together with
+ * the markup from the following banner-code.
+ */
+ ads.unshift(id);
- for (i=0; i < arguments.length; i++)
- str += arguments[i];
+ }
- OA_output[id] = str + OA_output[id];
+ /**
+ * 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 = [];
+ }
}