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 ) {
18 openx.show_ads = function(server, zones) {
21 domain = document.location.protocol == 'https:' ? 'https://' + server + ':8443':'http://' + server,
25 document.write = document_write;
26 document.writeln = document_write;
28 src += "/www/delivery/spc.php?zones=";
30 /** Only fetch banners, that are really included in this page */
32 $('.oa').each(function() {
36 if (node.hasClass(name)) {
40 src += escape(id + '=' + zones[name] + "|");
45 src += "&nz=1&source=" + escape(OA_source);
46 src += "&r=" + Math.floor(Math.random()*99999999);
47 src += "&block=1&charset=UTF-8";
49 if (window.location) src += "&loc=" + escape(window.location);
50 if (document.referrer) src += "&referer=" + escape(document.referrer);
52 $.getScript(src, init_ads);
54 src = domain + '/www/delivery/fl.js';
62 for (i=0; i<queue.length; i++) {
64 if (typeof(OA_output[id]) != 'undefined' && OA_output[id] != '')
72 function render_ads() {
74 while (ads.length > 0) {
81 // node.append(id + ": " + node.attr('class'));
83 var result, src, inline;
85 while ((result = /<script/i.exec(OA_output[id])) != null) {
86 node.append(OA_output[id].slice(0,result.index));
87 /** Strip all text before "<script" from OA_output[id] */
88 OA_output[id] = OA_output[id].slice(result.index,OA_output[id].length);
89 result = /^([^>]*)>([\s\S]*?)<\\?\/script>/i.exec(OA_output[id]);
91 /** Invalid syntax in delivered banner-code: ignoring the rest of this banner-code! */
92 // alert(OA_output[id]);
96 /** Remember iinline-code, if present */
99 /** Strip all text up to and including "</script>" from OA_output[id] */
100 OA_output[id] = OA_output[id].slice(result[0].length,OA_output[id].length);
101 result = /src\s*=\s*['"]([^'"]*)['"]/i.exec(src);
102 if (result == null) {
103 /** script-tag with inline-code: execute inline-code! */
104 result = /^\s*<.*$/m.exec(inline);
105 if (result != null) {
106 /** Remove leading HTML-comments, because IE will stumble otherwise */
107 inline = inline.slice(result[0].length,inline.length);
109 $.globalEval(inline);
112 /** script-tag with src-URL! */
113 ads.unshift(id); // << The banner might not be rendered fully, or include more calls to document.write().
114 /** Load the script and halt all work until the script is loaded and executed... */
115 $.getScript(result[1], render_ads); // << jQuery.getScript() generates onload-Handler for _all_ browsers ;)
121 node.append(OA_output[id]);
125 /** All entries from OA_output were rendered */
131 function document_write() {
140 for (i=0; i < arguments.length; i++)
143 OA_output[id] = str + OA_output[id];
147 } ( window.openx = window.openx || {}, jQuery ));
149 var OA_output = {}; // << Needed, because IE will complain loudly otherwise!