X-Git-Url: http://juplo.de/gitweb/?a=blobdiff_plain;f=openx.js;h=34993451a2c565b79b037c439fb8db975c658927;hb=bcf3be2e38ab96a41118a23e7e96db59655de733;hp=92c25bcaf5210ffb2b13a2223a7d76f17a03cd7b;hpb=fda1b3a613cddb11351df6e1cb06c31229b3d073;p=openx diff --git a/openx.js b/openx.js index 92c25bc..3499345 100644 --- a/openx.js +++ b/openx.js @@ -4,35 +4,44 @@ (function( openx, $, undefined ) { - var id; - var node; + var - var count = 0; - var slots = {}; - var ads = []; + id, + node, + + count = 0, + slots = {}, + queue = [], + ads = [], + output = []; openx.show_ads = function(server, zones) { - document.write = render; - document.writeln = render; + var + domain = document.location.protocol == 'https:' ? 'https://' + server + ':8443':'http://' + server, + name, + src = domain; - var domain = document.location.protocol == 'https:' ? 'https://' + server + ':8443':'http://' + server; + document.write = document_write; + document.writeln = document_write; - var src = domain; src += "/www/delivery/spc.php?zones="; /** Only fetch banners, that are really included in this page */ - $('.oa').each(function() { - var node = $(this); - for(var name in zones) { + for(name in zones) { + $('.oa').each(function() { + var + node = $(this), + id; if (node.hasClass(name)) { - var id = 'oa_' + ++count; + 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); @@ -50,81 +59,105 @@ function init_ads() { - for (var id in slots) { + var i, id; + for (i=0; i 0) { + + var result, src, inline, i; - id = ads.pop(); - node = slots[id]; + id = ads.shift(); + node = slots[id]; - // node.append(id + ": " + node.attr('class')); + node.slideDown(); - var result; - var src; - var inline; + // node.append(id + ": " + node.attr('class')); - while ((result = /" from OA_output[id] */ - OA_output[id] = OA_output[id].slice(result[0].length,OA_output[id].length); - result = /src\s*=\s*['"]([^'"]*)['"]/i.exec(src); - if (result == null) { - /** script-tag with inline-code: execute inline-code! */ - $.globalEval(inline); + for (i=0; i]*)>([\s\S]*?)<\\?\/script>/i.exec(OA_output[id]); + if (result == null) { + /** Invalid syntax in delivered banner-code: ignoring the rest of this banner-code! */ + // alert(OA_output[id]); + OA_output[id] = ""; + } + else { + /** Remember iinline-code, if present */ + src = result[1] + inline = result[2]; + /** Strip all text up to and including "" from OA_output[id] */ + OA_output[id] = OA_output[id].slice(result[0].length,OA_output[id].length); + result = /src\s*=\s*['"]([^'"]*)['"]/i.exec(src); + if (result == null) { + /** script-tag with inline-code: execute inline-code! */ + result = /^\s*<.*$/m.exec(inline); + if (result != null) { + /** Remove leading HTML-comments, because IE will stumble otherwise */ + inline = inline.slice(result[0].length,inline.length); + } + $.globalEval(inline); + } + else { + /** script-tag with src-URL! */ + 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; + } + } } + + node.append(OA_output[id]); + OA_output[id] = ""; } - node.append(OA_output[id]); - OA_output[id] = ""; - /** This statement will only reached, when no script-element was rendered! */ - render_ad(); + /** All entries from OA_output were rendered */ + id = undefined; + node = undefined; } - function render() { - - if (id == undefined) - return; + function document_write() { - var str = ""; - for (var i=0; i < arguments.length; i++) - str += arguments[i]; + for (var i=0; i