slots = {},
min_width = {},
max_width = {},
- width,
+ is_pagewidth = {},
+ pagewidth,
rendered = {},
visible = {},
rendering = false,
*
* 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-classname. DEFAULT: "min_".
+ * CSS-class. DEFAULT: "min_".
* max_prefix: string Prefix for the encoding of the maximal width as
- * CSS-classname. DEFAULT: "max_".
+ * 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: 200.
+ * progress. DEFAULT: 500.
* debug: boolean Turn on/off console-debugging. DEFAULT: false.
*/
$.openx = function( options ) {
'selector': '.oa',
'min_prefix': 'min_',
'max_prefix': 'max_',
- 'resize_delay': 200,
+ 'pw_marker': 'pw',
+ 'resize_delay': 500,
'debug': false
},
options
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<classes.length; i++) {
match = min.exec(classes[i]);
if (match)
- min_width[id] = match[1];
+ min_width[id] = +match[1];
match = max.exec(classes[i]);
if (match)
- max_width[id] = match[1];
+ max_width[id] = +match[1];
+ is_pagewidth[id] = classes[i] === settings.pw_marker;
}
rendered[id] = false;
visible[id] = false;
if (settings.debug && console.debug)
console.debug(
- 'Slot ' + count + ': ' + this.id + ' (' + min_width[id]
+ 'Slot ' + count + ': ' + this.id
+ + (is_pagewidth[id] ? ', pagewidth: ' : ', width: ')
+ + min_width[id]
+ (max_width[id] != Number.MAX_VALUE ? '-' + max_width[id] : '')
- + ')'
);
}
});
}
+ /** Cleanup data for responsive source-tag's */
+ for (i=0; i<settings.source.length; i++) {
+ if (!settings.source[i].min) settings.source[i].min = 0;
+ if (!settings.source[i].max) settings.source[i].max = Number.MAX_VALUE;
+ if (!settings.source[i].prefix) settings.source[i].prefix = '';
+ if (!settings.source[i].suffix) settings.source[i].suffix = '';
+ }
+
/** Add resize-event */
$(window).resize(function() {
clearTimeout(resize_timer);
function recalculate_visible() {
- width = $(document).width();
+ pagewidth = $(document).width();
if (settings.debug && console.debug)
- console.debug('Scheduling recalculation of visible banners for width ' + width);
+ console.debug('Scheduling recalculation of visible banners for width ' + pagewidth);
if (!rendering)
fetch_ads();
rendering = true;
if (settings.debug && console.debug)
- console.debug('Starting recalculation of visible banners for width ' + width);
+ console.debug('Starting recalculation of visible banners for width ' + pagewidth);
- var name, src = domain + settings.delivery + '/spc.php';
+ var
+ name,
+ width,
+ i,
+ source_prefix = '',
+ source_suffix = '',
+ src = domain + settings.delivery + '/spc.php';
/** Order banners for all zones that were found on the page */
src += '?zones=';
for(id in slots) {
+ width =
+ is_pagewidth[id]
+ ? pagewidth
+ : Math.round($(slots[id]).parent().width());
visible[id] = width >= min_width[id] && width <= max_width[id];
if (visible[id]) {
if (!rendered[id]) {
if (settings.charset)
src += '&charset=' + settings.charset;
+ /** Calculate responsive source-tag's */
+ for (i=0; i<settings.source.length; i++) {
+ if (pagewidth >= 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 */
- width = undefined;
+ pagewidth = undefined;
/** Fetch data from OpenX and schedule the render-preparation */
$.getScript(src, init_ads);
/** 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 {
console.debug('Recalculation of visible banners done!');
/** Restart rendering, if new task was queued */
- if (width)
+ if (pagewidth)
fetch_ads();
}