- id = ads.pop();
- node = slots[id];
-
- // node.append(id + ": " + node.attr('class'));
-
- var result;
- var script;
- var src;
- var inline;
-
- while ((result = /<script/i.exec(OA_output[id])) != null) {
- node.append(OA_output[id].slice(0,result.index));
- /** Strip all text before "<script" from OA_output[id] */
- OA_output[id] = OA_output[id].slice(result.index,OA_output[id].length);
- result = /^([^>]*)>([\s\S]*?)<\\?\/script>/i.exec(OA_output[id]);
- if (result == null) {
- /** Invalid syntax in delivered banner-code: ignoring the rest of this banner-code! */
- // alert(OA_output[id]);
- OA_output[id] = "";
- render_ad();
- return;
- }
- /** Remember iinline-code, if present */
- src = result[1]
- inline = result[2];
- /** Strip all text up to and including "</script>" 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);
- if (result == null) {
- /** script-tag with inline-code: execute inline-code! */
- eval(inline);
- }
- else {
- /** script-tag with src-URL! */
- script = document.createElement('script');
- script.type = 'text/javascript';
- script.async = false;
- script.defer = false;
- script.src = result[1];
- script.onload = render_ad;
- /** The banner might not be rendered fully, or include more calls to document.write(). */
- ads.push(id);
- /** Load the script and halt all work until the script is loaded and executed... */
- body.appendChild(script); // << The onload-event is only fired when appendChild is used!
- return;
+ var result, src, inline, i;
+
+ id = ads.shift();
+ node = slots[id];
+
+ node.slideDown();
+
+ // node.append(id + ": " + node.attr('class'));
+
+ /**
+ * 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 = /<script/i.exec(OA_output[id])) != null) {
+ node.append(OA_output[id].slice(0,result.index));
+ /** Strip all text before "<script" from OA_output[id] */
+ OA_output[id] = OA_output[id].slice(result.index,OA_output[id].length);
+ result = /^([^>]*)>([\s\S]*?)<\\?\/script>/i.exec(OA_output[id]);
+ if (result == null) {
+ /** Invalid syntax in delivered banner-code: ignoring the rest of this banner-code! */
+ // alert(OA_output[id]);
+ OA_output[id] = "";
+ }
+ else {
+ /** Remember iinline-code, if present */
+ 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 "</script>" from OA_output[id] */
+ OA_output[id] = OA_output[id].slice(result[0].length,OA_output[id].length);
+ result = /src\s*=\s*['"]?([^'"]*)['"]?\s/i.exec(src);
+ if (result == null) {
+ /** script-tag with inline-code: execute inline-code! */
+ result = /^\s*<.*$/m.exec(inline);
+ if (result != null) {
+ /** Remove leading HTML-comments, because IE will stumble otherwise */
+ inline = inline.slice(result[0].length,inline.length);
+ }
+ $.globalEval(inline);
+ insert_output(); // << The executed inline-code might have called document.write()!
+ }
+ else {
+ /** script-tag with src-URL! */
+ 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;
+ }
+ }