X-Git-Url: http://juplo.de/gitweb/?a=blobdiff_plain;f=jquery.openx.js;h=a2343bb139ec9f6467ef4696f32a3b5318fb80ea;hb=b6ffa68d8d04fa594ea7b11f5e38fea2e89cb991;hp=582559358ee33d9ee8b31ea02bedbe0d585996c1;hpb=4691d2c97d4c3154c20020487dcd916a2b81abf2;p=openx diff --git a/jquery.openx.js b/jquery.openx.js index 5825593..a2343bb 100644 --- a/jquery.openx.js +++ b/jquery.openx.js @@ -25,28 +25,123 @@ var - domain, id, node, + settings, _options, domain, id, node, count = 0, slots = {}, + min_width = {}, + max_width = {}, queue = [], - ads = [], output = []; - $.openx = function( server, zones, options ) { + /* + * 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: + * + * 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_". + */ + $.openx = function( options ) { if (domain) { - if (console.error) + if (console.error) { console.error('jQuery.openx was already initialized!'); + console.log('Configured options: ', _options); + } return; } - domain = document.location.protocol == 'https:' ? 'https://' + server + ':8443':'http://' + server; + /** Enable convenient-configuration */ + if (typeof(options) == 'string') + options = { 'server': options }; + + _options = options; + + if (!options.server) { + if (console.error) { + console.error('Required option "server" is missing!'); + console.log('options: ', options); + } + return; + } - var - name, - src = domain; + settings = $.extend( + { + 'protocol': document.location.protocol, + 'delivery': '/www/delivery', + 'fl': 'fl.js', + 'selector': '.oa', + 'min_prefix': 'min_', + 'max_prefix': 'max_', + 'cache': true + }, + options + ); + + domain = settings.protocol + '//'; + domain += settings.server; + if (settings.protocol === 'http:' && settings.http_port) + domain += ':' + settings.http_port; + if (settings.protocol === 'https:' && settings.https_port) + domain += ':' + settings.https_port; /** * Without this option, jQuery appends an timestamp to every URL, that @@ -54,51 +149,102 @@ * third-party-ad-scripts, that assume that the called URL's are not * altered. */ - $.ajaxSetup({ cache: true }); + $.ajaxSetup({ 'cache': true }); - src += "/www/delivery/spc.php?zones="; - - /** Only fetch banners, that are really included in this page */ - for(name in zones) { - $('.oa').each(function() { + /** + * jQuery.openx only works with "named zones", because it does not know, + * which zones belong to which website. For mor informations about + * "named zones" see: + * http://www.openx.com/docs/2.8/userguide/single%20page%20call + * + * For convenience, jQuery.openx only fetches banners, that are really + * included in the actual page. This way, you can configure jQuery.openx + * with all zones available for your website - for example in a central + * template - and does not have to worry about performance penalties due + * to unnecessarily fetched banners. + */ + for(name in OA_zones) { + $(settings.selector).each(function() { var - node = $(this), - id; - if (node.hasClass(name)) { + 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] = node; - queue.push(id); - src += escape(id + '=' + zones[name] + "|"); + slots[id] = this; + min_width[id] = 0; + max_width[id] = Number.MAX_VALUE; + classes = this.className.split(/\s+/); + 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]); node.slideDown(); @@ -157,7 +303,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; @@ -184,7 +330,7 @@ for (var i=0; i