1 /** Optimized methods for fetching ad-banners via OpenX */
3 /** see: http://enterprisejquery.com/2010/10/how-good-c-habits-can-encourage-bad-javascript-habits-part-1/ */
5 (function( openx, $, undefined ) {
17 openx.show_ads = function(server, zones) {
20 domain = document.location.protocol == 'https:' ? 'https://' + server + ':8443':'http://' + server,
23 document.write = render;
24 document.writeln = render;
26 src += "/www/delivery/spc.php?zones=";
28 /** Only fetch banners, that are really included in this page */
29 $('.oa').each(function() {
34 if (node.hasClass(name)) {
37 src += escape(id + '=' + zones[name] + "|");
42 src += "&nz=1&source=" + escape(OA_source);
43 src += "&r=" + Math.floor(Math.random()*99999999);
44 src += "&block=1&charset=UTF-8";
46 if (window.location) src += "&loc=" + escape(window.location);
47 if (document.referrer) src += "&referer=" + escape(document.referrer);
49 $.getScript(src, init_ads);
51 src = domain + '/www/delivery/fl.js';
58 for (var id in slots) {
59 if (typeof(OA_output[id]) != 'undefined' && OA_output[id] != '')
67 function render_ad() {
69 if (ads.length == 0) {
78 // node.append(id + ": " + node.attr('class'));
80 var result, src, inline;
82 while ((result = /<script/i.exec(OA_output[id])) != null) {
83 node.append(OA_output[id].slice(0,result.index));
84 /** Strip all text before "<script" from OA_output[id] */
85 OA_output[id] = OA_output[id].slice(result.index,OA_output[id].length);
86 result = /^([^>]*)>([\s\S]*?)<\\?\/script>/i.exec(OA_output[id]);
88 /** Invalid syntax in delivered banner-code: ignoring the rest of this banner-code! */
89 // alert(OA_output[id]);
94 /** Remember iinline-code, if present */
97 /** Strip all text up to and including "</script>" from OA_output[id] */
98 OA_output[id] = OA_output[id].slice(result[0].length,OA_output[id].length);
99 result = /src\s*=\s*['"]([^'"]*)['"]/i.exec(src);
100 if (result == null) {
101 /** script-tag with inline-code: execute inline-code! */
102 result = /^\s*<.*$/m.exec(inline);
103 if (result != null) {
104 /** Remove leading HTML-comments, because IE will stumble otherwise */
105 inline = inline.slice(result[0].length,inline.length);
107 $.globalEval(inline);
110 /** script-tag with src-URL! */
111 ads.push(id); // << The banner might not be rendered fully, or include more calls to document.write().
112 /** Load the script and halt all work until the script is loaded and executed... */
113 $.getScript(result[1], render_ad); // << jQuery.getScript() generates onload-Handler for _all_ browsers ;)
117 node.append(OA_output[id]);
120 /** This statement will only reached, when no script-element was rendered! */
134 for (i=0; i < arguments.length; i++)
137 OA_output[id] = str + OA_output[id];
141 } ( window.openx = window.openx || {}, jQuery ));
143 var OA_output = {}; // << Needed, because IE will complain loudly otherwise!