X-Git-Url: http://juplo.de/gitweb/?a=blobdiff_plain;ds=sidebyside;f=openx.js;h=34993451a2c565b79b037c439fb8db975c658927;hb=bcf3be2e38ab96a41118a23e7e96db59655de733;hp=b916e78934b3807904f775b27b66cb58c0d0dd56;hpb=56aef196f70f2949706ac865e1e19395e7549b7e;p=openx diff --git a/openx.js b/openx.js index b916e78..3499345 100644 --- a/openx.js +++ b/openx.js @@ -4,153 +4,160 @@ (function( openx, $, undefined ) { - var body = document.getElementsByTagName('body')[0]; + var - var id; - var node; + id, + node, - var count = 0; - var slots = {}; - var ads = []; + 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 spc = document.createElement('script'); - - spc.type = 'text/javascript'; - spc.async = false; - spc.defer = false; - - spc.src = domain; - spc.src += "/www/delivery/spc.php?zones="; + 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; - spc.src += escape(id + '=' + zones[name] + "|"); + queue.push(id); + src += escape(id + '=' + zones[name] + "|"); } - } - }); - - spc.src += "&nz=1&source=" + escape(OA_source); - spc.src += "&r=" + Math.floor(Math.random()*99999999); - spc.src += "&block=1&charset=UTF-8"; - - if (window.location) spc.src += "&loc=" + escape(window.location); - if (document.referrer) spc.src += "&referer=" + escape(document.referrer); - - spc.onload = init_ads; - - body.appendChild(spc); - + }); + } - var fl = document.createElement('script'); + src += "&nz=1&source=" + escape(OA_source); + src += "&r=" + Math.floor(Math.random()*99999999); + src += "&block=1&charset=UTF-8"; - fl.type = 'text/javascript'; - fl.async = false; - fl.defer = false; + if (window.location) src += "&loc=" + escape(window.location); + if (document.referrer) src += "&referer=" + escape(document.referrer); - fl.src = domain + '/www/delivery/fl.js'; + $.getScript(src, init_ads); - body.appendChild(fl); + src = domain + '/www/delivery/fl.js'; + $.getScript(src); } function init_ads() { - for (var id in slots) { + var i, id; + for (i=0; i 0) { - id = ads.pop(); - node = slots[id]; + var result, src, inline, i; - // node.append(id + ": " + node.attr('class')); + id = ads.shift(); + node = slots[id]; - var result; - var script; - var src; - var inline; + node.slideDown(); - 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! */ - eval(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() { + function document_write() { - if (id == undefined) - return; + for (var i=0; i