X-Git-Url: http://juplo.de/gitweb/?a=blobdiff_plain;f=openx.js;h=cba60d32733f63c85a82ab0a93e668fb933dbf9c;hb=bebf36d20d314c5b338063dc02c58c0f5bf26933;hp=b916e78934b3807904f775b27b66cb58c0d0dd56;hpb=56aef196f70f2949706ac865e1e19395e7549b7e;p=openx diff --git a/openx.js b/openx.js index b916e78..cba60d3 100644 --- a/openx.js +++ b/openx.js @@ -4,65 +4,52 @@ (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 = {}, + ads = []; openx.show_ads = function(server, zones) { - document.write = render; - document.writeln = render; + var + domain = document.location.protocol == 'https:' ? 'https://' + server + ':8443':'http://' + server, + 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) { + var + node = $(this), + name, id; + for(name in zones) { if (node.hasClass(name)) { - var id = 'oa_' + ++count; + id = 'oa_' + ++count; slots[id] = node; - spc.src += escape(id + '=' + zones[name] + "|"); + 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); + src += "&nz=1&source=" + escape(OA_source); + src += "&r=" + Math.floor(Math.random()*99999999); + src += "&block=1&charset=UTF-8"; + if (window.location) src += "&loc=" + escape(window.location); + if (document.referrer) src += "&referer=" + escape(document.referrer); - var fl = document.createElement('script'); + $.getScript(src, init_ads); - fl.type = 'text/javascript'; - fl.async = false; - fl.defer = false; - - fl.src = domain + '/www/delivery/fl.js'; - - body.appendChild(fl); + src = domain + '/www/delivery/fl.js'; + $.getScript(src); } @@ -73,80 +60,77 @@ ads.push(id); } - render_ad(); + render_ads(); } - function render_ad() { + function render_ads() { - if (ads.length == 0) { - id = undefined; - node = undefined; - return; - } + while (ads.length > 0) { - id = ads.pop(); - node = slots[id]; - - // node.append(id + ": " + node.attr('class')); - - var result; - var script; - var src; - var inline; - - 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); - } - else { - /** script-tag with src-URL! */ - script = document.createElement('script'); - script.type = 'text/javascript'; - script.async = false; - script.defer = false; - script.src = result[1]; - script.onload = render_ad; - /** The banner might not be rendered fully, or include more calls to document.write(). */ - ads.push(id); - /** Load the script and halt all work until the script is loaded and executed... */ - body.appendChild(script); // << The onload-event is only fired when appendChild is used! - return; + id = ads.pop(); + node = slots[id]; + + // node.append(id + ": " + node.attr('class')); + + var result, src, inline; + + 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! */ + 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.push(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; - var str = ""; - for (var i=0; i < arguments.length; i++) + var + str = "", + i; + + for (i=0; i < arguments.length; i++) str += arguments[i]; OA_output[id] = str + OA_output[id]; @@ -154,3 +138,5 @@ } } ( window.openx = window.openx || {}, jQuery )); + +var OA_output = {}; // << Needed, because IE will complain loudly otherwise!