X-Git-Url: http://juplo.de/gitweb/?a=blobdiff_plain;f=openx.js;h=76e994bcec718316c5ceeed9ffe4f58203d2af82;hb=d95742f4f780bc45f7f091fb256251e332f41753;hp=a01c775a47f2b20a5118de83f7a3f29418fb9f85;hpb=32c1a348b266f53ecf91ba684841ca8472f4c649;p=openx diff --git a/openx.js b/openx.js index a01c775..76e994b 100644 --- a/openx.js +++ b/openx.js @@ -1,29 +1,48 @@ -/** Optimized methods for fetching ad-banners via OpenX */ - -/** see: http://enterprisejquery.com/2010/10/how-good-c-habits-can-encourage-bad-javascript-habits-part-1/ */ +/* + * (C) Copyright 2012 juplo (http://juplo.de/). + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser General Public License + * (LGPL) version 3.0 which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.html + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Contributors: + * - Kai Moritz + */ (function( openx, $, undefined ) { var - id, - node, + domain, id, node, count = 0, slots = {}, queue = [], - ads = []; + ads = [], + output = []; openx.show_ads = function(server, zones) { + domain = document.location.protocol == 'https:' ? 'https://' + server + ':8443':'http://' + server; + var - domain = document.location.protocol == 'https:' ? 'https://' + server + ':8443':'http://' + server, name, src = domain; - document.write = document_write; - document.writeln = document_write; + /** + * 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 }); src += "/www/delivery/spc.php?zones="; @@ -42,17 +61,21 @@ }); } - src += "&nz=1&source=" + escape(OA_source); - src += "&r=" + Math.floor(Math.random()*99999999); + if (typeof OA_source !== 'undefined') + src += "&source=" + escape(OA_source); + src += "&nz=1&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); - $.getScript(src, init_ads); + $.getScript(src, load_flash); - src = domain + '/www/delivery/fl.js'; - $.getScript(src); + } + + function load_flash() { + + $.getScript(domain + '/www/delivery/fl.js', init_ads); } @@ -65,6 +88,9 @@ ads.push(id); } + document.write = document_write; + document.writeln = document_write; + render_ads(); } @@ -73,6 +99,8 @@ while (ads.length > 0) { + var result, src, inline, i; + id = ads.shift(); node = slots[id]; @@ -80,7 +108,11 @@ // 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 = /