X-Git-Url: http://juplo.de/gitweb/?a=blobdiff_plain;f=openx.js;h=76e994bcec718316c5ceeed9ffe4f58203d2af82;hb=d95742f4f780bc45f7f091fb256251e332f41753;hp=ce94f71a526891141ef23a9807875dc4a04021c0;hpb=c9c1476fef538e4dc82716cf887b6fe878652851;p=openx diff --git a/openx.js b/openx.js index ce94f71..76e994b 100644 --- a/openx.js +++ b/openx.js @@ -1,13 +1,25 @@ -/** 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 = {}, @@ -18,8 +30,9 @@ 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; @@ -31,9 +44,6 @@ */ $.ajaxSetup({ cache: true }); - document.write = document_write; - document.writeln = document_write; - src += "/www/delivery/spc.php?zones="; /** Only fetch banners, that are really included in this page */ @@ -51,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); + + } + + function load_flash() { - src = domain + '/www/delivery/fl.js'; - $.getScript(src); + $.getScript(domain + '/www/delivery/fl.js', init_ads); } @@ -74,6 +88,9 @@ ads.push(id); } + document.write = document_write; + document.writeln = document_write; + render_ads(); } @@ -109,11 +126,11 @@ } else { /** Remember iinline-code, if present */ - src = result[1] + src = result[1] + ' ' // << simplifies the following regular expression: the string ends with a space in any case, so that the src-URL cannot be followed by the end of the string emediately! 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); + result = /src\s*=\s*['"]?([^'"]*)['"]?\s/i.exec(src); if (result == null) { /** script-tag with inline-code: execute inline-code! */ result = /^\s*<.*$/m.exec(inline); @@ -126,7 +143,9 @@ } else { /** script-tag with src-URL! */ - ads.unshift(id); // << The banner might not be rendered fully, or include more calls to document.write(). + if (OA_output[id].length > 0) + /** The banner-code was not rendered completely yet! */ + ads.unshift(id); /** 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; @@ -147,6 +166,9 @@ /** This function is used to overwrite document.write and document.writeln */ function document_write() { + if (id == undefined) + return; + for (var i=0; i