2 * (C) Copyright 2012 juplo (http://juplo.de/).
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the GNU Lesser General Public License
6 * (LGPL) version 3.0 which accompanies this distribution, and is available at
7 * http://www.gnu.org/licenses/lgpl-3.0.html
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
18 (function( openx, $, undefined ) {
31 openx.show_ads = function(server, zones) {
33 domain = document.location.protocol == 'https:' ? 'https://' + server + ':8443':'http://' + server;
40 * Without this option, jQuery appends an timestamp to every URL, that
41 * is fetched via $.getScript(). This can mess up badly written
42 * third-party-ad-scripts, that assume that the called URL's are not
45 $.ajaxSetup({ cache: true });
47 src += "/www/delivery/spc.php?zones=";
49 /** Only fetch banners, that are really included in this page */
51 $('.oa').each(function() {
55 if (node.hasClass(name)) {
59 src += escape(id + '=' + zones[name] + "|");
64 if (typeof OA_source !== 'undefined')
65 src += "&source=" + escape(OA_source);
66 src += "&nz=1&r=" + Math.floor(Math.random()*99999999);
67 src += "&block=1&charset=UTF-8";
69 if (window.location) src += "&loc=" + escape(window.location);
70 if (document.referrer) src += "&referer=" + escape(document.referrer);
72 $.getScript(src, load_flash);
76 function load_flash() {
78 $.getScript(domain + '/www/delivery/fl.js', init_ads);
85 for (i=0; i<queue.length; i++) {
87 if (typeof(OA_output[id]) != 'undefined' && OA_output[id] != '')
91 document.write = document_write;
92 document.writeln = document_write;
98 function render_ads() {
100 while (ads.length > 0) {
102 var result, src, inline, i;
109 // node.append(id + ": " + node.attr('class'));
112 * If output was added via document.write(), this output must be
113 * rendered before other banner-code from the OpenX-server is rendered!
117 while ((result = /<script/i.exec(OA_output[id])) != null) {
118 node.append(OA_output[id].slice(0,result.index));
119 /** Strip all text before "<script" from OA_output[id] */
120 OA_output[id] = OA_output[id].slice(result.index,OA_output[id].length);
121 result = /^([^>]*)>([\s\S]*?)<\\?\/script>/i.exec(OA_output[id]);
122 if (result == null) {
123 /** Invalid syntax in delivered banner-code: ignoring the rest of this banner-code! */
124 // alert(OA_output[id]);
128 /** Remember iinline-code, if present */
129 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!
131 /** Strip all text up to and including "</script>" from OA_output[id] */
132 OA_output[id] = OA_output[id].slice(result[0].length,OA_output[id].length);
133 result = /src\s*=\s*['"]?([^'"]*)['"]?\s/i.exec(src);
134 if (result == null) {
135 /** script-tag with inline-code: execute inline-code! */
136 result = /^\s*<.*$/m.exec(inline);
137 if (result != null) {
138 /** Remove leading HTML-comments, because IE will stumble otherwise */
139 inline = inline.slice(result[0].length,inline.length);
141 $.globalEval(inline);
142 insert_output(); // << The executed inline-code might have called document.write()!
145 /** script-tag with src-URL! */
146 if (OA_output[id].length > 0)
147 /** The banner-code was not rendered completely yet! */
149 /** Load the script and halt all work until the script is loaded and executed... */
150 $.getScript(result[1], render_ads); // << jQuery.getScript() generates onload-Handler for _all_ browsers ;)
156 node.append(OA_output[id]);
160 /** All entries from OA_output were rendered */
166 /** This function is used to overwrite document.write and document.writeln */
167 function document_write() {
172 for (var i=0; i<arguments.length; i++)
173 output.push(arguments[i]);
177 * Re-Add the last banner-code to the working-queue, because included
178 * scripts had added markup via document.write(), which is not
180 * Otherwise the added markup would be falsely rendered together with
181 * the markup from the following banner-code.
188 * This function prepends the collected output from calls to
189 * document_write() to the current banner-code.
191 function insert_output() {
193 if (output.length > 0) {
194 output.push(OA_output[id]);
196 for (i=0; i<output.length; i++)
197 OA_output[id] += output[i];
203 } ( window.openx = window.openx || {}, jQuery ));
205 var OA_output = {}; // << Needed, because IE will complain loudly otherwise!