X-Git-Url: http://juplo.de/gitweb/?a=blobdiff_plain;f=jquery.openx.js;h=3ccdb39f9444f1ba5012c9e914668dcb81c4d06c;hb=17a2f5b7816379f69363ccb9e3c421eecedbea7a;hp=f5f22532d6a0d57f218426f693a1b3d25c65c278;hpb=95859482ad5fe50bd07fa8510e1168c8ed151d0c;p=openx diff --git a/jquery.openx.js b/jquery.openx.js index f5f2253..3ccdb39 100644 --- a/jquery.openx.js +++ b/jquery.openx.js @@ -29,8 +29,14 @@ count = 0, slots = {}, + min_width = {}, + max_width = {}, + width, + rendered = {}, + visible = {}, + rendering = false, + resize_timer, queue = [], - ads = [], output = []; @@ -86,11 +92,26 @@ * charset: string Charset used, when delivering the banner-codes. * If empty, the charset is guessed by OpenX. Examples * for sensible values: "UTF-8", "ISO-8859-1". + * + * + * Other settings: + * + * 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-classname. DEFAULT: "min_". + * max_prefix: string Prefix for the encoding of the maximal width as + * CSS-classname. DEFAULT: "max_". + * 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: 200. + * debug: boolean Turn on/off console-debugging. DEFAULT: false. */ $.openx = function( options ) { - var name, src, errors = [], i; - if (domain) { if (console.error) { console.error('jQuery.openx was already initialized!'); @@ -105,12 +126,9 @@ _options = options; - if (!options.server) - errors.push('Required option "server" is missing!'); - if (errors.length > 0) { + if (!options.server) { if (console.error) { - for (i=0; i= min_width[id] && width <= max_width[id]; + if (visible[id]) { + if (!rendered[id]) { + queue.push(id); + src += escape(id + '=' + OA_zones[slots[id].id] + "|"); + rendered[id] = true; + if (settings.debug && console.debug) + console.debug('Fetching banner ' + slots[id].id); + } + else { + /** Unhide already fetched visible banners */ + if (settings.debug && console.debug) + console.debug('Unhiding already fetched banner ' + slots[id].id); + $(slots[id]).slideDown(); + } + } + else { + /** Hide unvisible banners */ + if (settings.debug && console.debug) + console.debug('Hiding banner ' + slots[id].id); + $(slots[id]).hide(); + } + } src += '&nz=1'; // << We want to fetch named zones! /** @@ -196,25 +296,23 @@ if (typeof OA_source !== 'undefined') src += "&source=" + escape(OA_source); - /** Chain-load the scripts (next script to load is fl.js */ - $.getScript(src, load_flash); - - } - - function load_flash() { + /** Signal, that this task is done / in progress */ + width = undefined; - $.getScript(domain + settings.delivery + '/' + settings.fl, init_ads); + /** Fetch data from OpenX and schedule the render-preparation */ + $.getScript(src, init_ads); } function init_ads() { - var i, id; + var i, id, ads = []; for (i=0; i 0) { + while (queue.length > 0) { var result, src, inline; - id = ads.shift(); - node = slots[id]; + id = queue.shift(); + node = $(slots[id]); + + if (settings.debug && console.debug) + console.debug('Rendering banner ' + slots[id].id); node.slideDown(); @@ -273,7 +374,7 @@ /** script-tag with src-URL! */ if (OA_output[id].length > 0) /** The banner-code was not rendered completely yet! */ - ads.unshift(id); + queue.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; @@ -289,6 +390,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 (width) + fetch_ads(); + } /** This function is used to overwrite document.write and document.writeln */ @@ -300,7 +410,7 @@ for (var i=0; i