From 32c1a348b266f53ecf91ba684841ca8472f4c649 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Mon, 24 Sep 2012 23:56:47 +0200 Subject: [PATCH] Ad-banners are now fetched in the given order Ad-banners are now fetched in the order, that is defined in the variable "zones". The work-queue "ads" is now stored in an array, because it is not guarantied, that the JavaScript-engine iterates over the attributes of an object in the same order, they were added. --- openx.js | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/openx.js b/openx.js index 18d96ee..a01c775 100644 --- a/openx.js +++ b/openx.js @@ -11,6 +11,7 @@ count = 0, slots = {}, + queue = [], ads = []; @@ -18,6 +19,7 @@ var domain = document.location.protocol == 'https:' ? 'https://' + server + ':8443':'http://' + server, + name, src = domain; document.write = document_write; @@ -26,18 +28,19 @@ src += "/www/delivery/spc.php?zones="; /** Only fetch banners, that are really included in this page */ - $('.oa').each(function() { - var - node = $(this), - name, id; - for(name in zones) { + for(name in zones) { + $('.oa').each(function() { + var + node = $(this), + id; if (node.hasClass(name)) { id = 'oa_' + ++count; slots[id] = node; + queue.push(id); src += escape(id + '=' + zones[name] + "|"); } - } - }); + }); + } src += "&nz=1&source=" + escape(OA_source); src += "&r=" + Math.floor(Math.random()*99999999); @@ -55,7 +58,9 @@ function init_ads() { - for (var id in slots) { + var i, id; + for (i=0; i 0) { - id = ads.pop(); + id = ads.shift(); node = slots[id]; node.slideDown(); @@ -105,7 +110,7 @@ } else { /** script-tag with src-URL! */ - ads.push(id); // << The banner might not be rendered fully, or include more calls to document.write(). + ads.unshift(id); // << The banner might not be rendered fully, or include more calls to document.write(). /** 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; -- 2.20.1