X-Git-Url: https://juplo.de/gitweb/?p=openx;a=blobdiff_plain;f=jquery.openx.js;h=d02b228bc2726ce320c391770ea851cd8a0bfefb;hp=d687dfad87cfa2a89c808c34ccfae52df7d43257;hb=HEAD;hpb=8bf0530c43be94c835d313b572da3569a4c878b8 diff --git a/jquery.openx.js b/jquery.openx.js index d687dfa..d02b228 100644 --- a/jquery.openx.js +++ b/jquery.openx.js @@ -29,6 +29,14 @@ count = 0, slots = {}, + min_width = {}, + max_width = {}, + is_pagewidth = {}, + pagewidth, + rendered = {}, + visible = {}, + rendering = false, + resize_timer, queue = [], output = []; @@ -89,9 +97,30 @@ * * Other settings: * + * source: array An optional array of JavaScript-Objects, that + * define prefixes and suffixes, that should be + * added to source-tag defined in OA_source. Each + * object can (should) specify the properties "min" + * and "max". OA_source will only be altered, when + * min <= page-width <= max is true. If this is the + * case, the property "prefix" will be prepended to + * OA_source and the property "suffix" will be + * appended. * selector: string A selector for selecting the DOM-elements, that * should display ad-banners. DEFAULT: ".oa". * See: http://api.jquery.com/category/selectors/ + * min_prefix: string Prefix for the encoding of the minmal width as + * CSS-class. DEFAULT: "min_". + * max_prefix: string Prefix for the encoding of the maximal width as + * CSS-class. DEFAULT: "max_". + * pw_marker: string CSS-class, that marks the encoded maximal and minmal + * width as page width. DEFAULT: "pw". + * resize_delay: number Number of milliseconds to wait, before a + * recalculation of the visible ads is scheduled. + * If the value is choosen to small, a recalculation + * might be scheduled, while resizing is still in + * progress. DEFAULT: 500. + * debug: boolean Turn on/off console-debugging. DEFAULT: false. */ $.openx = function( options ) { @@ -123,7 +152,11 @@ 'delivery': '/www/delivery', 'fl': 'fl.js', 'selector': '.oa', - 'cache': true + 'min_prefix': 'min_', + 'max_prefix': 'max_', + 'pw_marker': 'pw', + 'resize_delay': 500, + 'debug': false }, options ); @@ -135,6 +168,9 @@ if (settings.protocol === 'https:' && settings.https_port) domain += ':' + settings.https_port; + if (settings.debug && console.debug) + console.debug('Ad-Server: ' + domain); + /** * Without this option, jQuery appends an timestamp to every URL, that * is fetched via $.getScript(). This can mess up badly written @@ -158,28 +194,115 @@ for(name in OA_zones) { $(settings.selector).each(function() { var - id; + id, + classes, + i, + min = new RegExp('^' + settings.min_prefix + '([0-9]+)$'), + max = new RegExp('^' + settings.max_prefix + '([0-9]+)$'), + match; if (this.id === name) { id = 'oa_' + ++count; slots[id] = this; + min_width[id] = 0; + max_width[id] = Number.MAX_VALUE; + is_pagewidth[id] = false; + classes = this.className.split(/\s+/); + for (i=0; i= settings.source[i].min + && pagewidth <= settings.source[i].max + ) { + source_prefix = settings.source[i].prefix + source_prefix; + source_suffix = source_suffix + settings.source[i].suffix; + } + } + /** Add the source-code - if present */ - if (typeof OA_source !== 'undefined') - src += "&source=" + escape(OA_source); + if (typeof OA_source !== 'undefined' + || source_prefix != '' + || source_suffix != '' + ) { + if (settings.debug && console.debug) + console.debug('OA_source: ' + source_prefix + OA_source + source_suffix); + src += "&source=" + escape(source_prefix + OA_source + source_suffix); + } + + /** Signal, that this task is done / in progress */ + pagewidth = undefined; /** Fetch data from OpenX and schedule the render-preparation */ $.getScript(src, init_ads); @@ -238,6 +380,9 @@ id = queue.shift(); node = $(slots[id]); + if (settings.debug && console.debug) + console.debug('Rendering banner ' + slots[id].id); + node.slideDown(); // node.append(id + ": " + node.attr('class')); @@ -272,7 +417,13 @@ /** Remove leading HTML-comments, because IE will stumble otherwise */ inline = inline.slice(result[0].length,inline.length); } - $.globalEval(inline); + try { + $.globalEval(inline); + } + catch(e) { + if (console.error) + console.error('Error while executing inline script-code: ' + e.message); + } insert_output(); // << The executed inline-code might have called document.write()! } else { @@ -295,6 +446,15 @@ id = undefined; node = undefined; + rendering = false; + + if (settings.debug && console.debug) + console.debug('Recalculation of visible banners done!'); + + /** Restart rendering, if new task was queued */ + if (pagewidth) + fetch_ads(); + } /** This function is used to overwrite document.write and document.writeln */