X-Git-Url: https://juplo.de/gitweb/?p=openx;a=blobdiff_plain;f=jquery.openx.js;h=d02b228bc2726ce320c391770ea851cd8a0bfefb;hp=f156ba5aac65cd8c2a410288fbf3c9d764806e27;hb=HEAD;hpb=9b00ed74c64f696a03334e59364ac6341ce1627a diff --git a/jquery.openx.js b/jquery.openx.js index f156ba5..d02b228 100644 --- a/jquery.openx.js +++ b/jquery.openx.js @@ -25,37 +25,122 @@ var - settings, _zones, _options, domain, id, node, + settings, _options, domain, id, node, count = 0, slots = {}, + min_width = {}, + max_width = {}, + is_pagewidth = {}, + pagewidth, + rendered = {}, + visible = {}, + rendering = false, + resize_timer, queue = [], - ads = [], output = []; - $.openx = function( zones, options ) { - - var name, src, errors = [], i; + /* + * Configuration-Options for jQuery.openx + * + * Since the domain-name of the ad-server is the only required parameter, + * jQuery.openx for convenience can be configured with only that one + * parameter. For example: "jQuery.openx('openx.example.org');". If more + * configuration-options are needed, they must be specified as an object. + * For example: "jQuery.openx({'server': 'openx.example.org', ... });". + * + * + * Server-Settings: + * + * server: string Name of the server, without protocol or port. For + * example "openx.example.org". This option is + * REQUIRED. + * protocol: Optional parameter. + * http: All connections to the ad-server are made via HTTP. + * https: All connections to the ad-server are made via HTTPS. + * If empty, document.location.protocol will be used. + * http_port: number Port-Number for HTTP-connections to the ad-server + * (only needed, when it is not the default-value 80). + * https_port: Port-Number for HTTPS-connections to the ad-server + * (only needed, when it is not the default-value 443). + * + * + * Seldom needed special Server-Settings (these parameters are only needed, + * if the default delivery-configration of the OpenX-Server was changed): + * + * path: string Path to delivery-scripts. DEFAULT: "/www/delivery". + * fl: string Flash-Include-Script. DEFAULT: "fl.js". + * + * + * Delivery-Options (for details and explanations see the see: + * http://www.openx.com/docs/2.8/userguide/single%20page%20call): + * + * block: 1 Don't show the banner again on the same page. + * 0 A Banner might be shown multiple times on the same + * page (DEFAULT). + * blockcampaign: 1 Don't show a banner from the same campaign again on + * the same page. + * 0 A Banner from the same campaign might be shown + * muliple times on the same page (DEFAULT). + * target: string The value is addes as the HTML TARGET attribute in + * the ad code. Examples for sensible values: "_blank", + * "_top". + * withtext: 1 Show text below banner. Enter this text in the + * Banner properties page. + * 0 Ignore the text-field from the banner-properties + (DEFAULT). + * 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: + * + * 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 ) { if (domain) { if (console.error) { console.error('jQuery.openx was already initialized!'); - console.log('Configured zones: ', _zones); console.log('Configured options: ', _options); } return; } - _zones = zones; + /** Enable convenient-configuration */ + if (typeof(options) == 'string') + options = { 'server': options }; + _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! + + /** + * These are some additions to the URL of spc.php, that are originally + * made in spcjs.php + */ + src += '&r=' + Math.floor(Math.random()*99999999); if (window.location) src += "&loc=" + escape(window.location); if (document.referrer) src += "&referer=" + escape(document.referrer); - $.getScript(src, load_flash); + /** Add the configured options */ + if (settings.block === 1) + src += '&block=1'; + if (settings.blockcampaign === 1) + src += '&blockcampaign=1'; + if (settings.target) + src += '&target=' + settings.target; + if (settings.withtext === 1) + src += '&withtext=1'; + if (settings.charset) + src += '&charset=' + settings.charset; + + /** Calculate responsive source-tag'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' + || 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); + } - function load_flash() { + /** Signal, that this task is done / in progress */ + pagewidth = undefined; - $.getScript(domain + '/www/delivery/fl.js', 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(); @@ -177,14 +417,20 @@ /** 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 { /** 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; @@ -200,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 */ @@ -211,7 +466,7 @@ for (var i=0; i