/*!
* CN.dart.js
* @author Russell Munson
* @library cn-fe-ads-1.1.35
*/
if(typeof CN==='undefined'){
var CN = {};
}
/**
* @requires CN, jQuery
*/
CN.dart = (function($, CN, $D){
/* OBJECTS, CONSTANTS, PRIVATE VARS */
var ads={},
initialPause, // Safari and IE aren't requesting ads in order. This will force the ads to load in order of tile.
nextToLoad,
/** Common ad value object
* Used in get and plugin methods for easy read/write access
* to shared ad values.
*/
common={
ad : {},
charmap : {},
container : '_frame', /* Individual ad container div suffix */
dcopt : true, /* allow dcopt param to be appended to tile 1 */
frameurl : '/ads/newad.html', /* Iframe base-url - Used for generating contained dynamic script tags for ad calls. */
embed : false, /* If set to true, embed ads in page rather than in an iframe */
initialized : false,
ord : Math.floor(Math.random()*10e12),
pause : [true], /* Store paused queue - used to manage multiple use of pause functionality
by unknown # of entities. First value in queue is for CN.dart. */
remote : '/services/dart/',
retry : false,
site : "",
tiles : [],
tile : 0,
url : location.protocol + '//web.archive.org/web/20110816054610/http://ad.doubleclick.net/adj/',
zone : ""
},
kwregex=/kw=/g,
/**
* Shared message prefix
* Used in generating debug info.
*/
msg_pre="CN Ad ",
/**
* Message object for easily generating debug info.
*/
msg = {
/* These are for good! */
'true' : {
gen : 'Success',
call : 'Request Fired',
embed : 'Set to Embedded Mode. Operating with degraded feature-set.',
queue : 'Request Added to Queue',
pause : 'Pause queue emptied, unpausing ads.',
plug : 'Plugin Registered',
valid : 'Plugin Action Passed Validation'
},
/* These are for bad =( */
'false' : {
gen : 'Error',
call : 'Request Aborted',
embed : 'Set to Iframe Mode. Good job.',
queue : 'Request Faled To Be Added to Queue',
pause : 'Pause queue still contains ' + common.pause.length+ ' calls. Ads still paused',
plug : 'Plugin Skipped',
valid : 'Plugin Action Failed Validation'
}
},
/**
* Generate debug messages
* @param {string} type Message type defined in @msg
* @param {boolean} [state] Optional boolean value to indicate state [true=success,false=error]
* @memberOf CN.dart
* @private
*/
messager = function(type,state){
return msg_pre + msg[(state!==false).toString()][type || 'gen'];
},
nakedFrame=$('').attr({
frameBorder : 0,
scrolling : 'no'
}).css({
border : 'none',
margin : 0,
padding : 0
}),
/* METHODS */
/**
* Construct the ad request url
* @param {object} ad Dart ad object
* @param {string} [url] Optional url to use inplace of ad object properties
* @memberOf CN.dart
* @private
*/
buildurl = function(ad,url){
return common.url + common.site
+ '/' +
(url || ad.zone || common.zone)
+ 'sz='+ ad.sz + ';'
+ 'tile=' + ad.tile + ';'
+ (ad.tile===1 && common.dcopt===true ? 'dcopt=ist;' : '')
+ (!url ? keywordString(ad) : '')
+ 'ord='+common.ord+'?';
},
/**
* Create and store individual ad objects by extending the base common.ad.
* Initiates ad call, or ads ad call to queue.
* @param {string} name Unique name prefix for storage, container div, and iframe id generation
* @param {object} [pars] Addtion ad params to extend/overide common.ad values.
* @memberOf CN.dart
* @private
*/
call = function(name,pars){
var key= name+pars.sz,
zone,
ad=ads[key] = {
tile : common.tiles.push(key),
el : $('#'+key+common.container),
kws : unique(common.ad.kws,pars.kws || []),
store : pars.store===false ? false : common.ad.store,
sz : pars.sz,
xkws : pars.kws || [],
zone : pars.zone ? test.adzone(pars.zone) : false,
collapse : pars.collapse===true
};
/* If intialization is complete, and we're not in paused-state
* execute ad call immediatly.
* AND if initialPause state is not true. initialPause state is used to force loading of iframes
* in order. See code in onDrawFrame.
*/
if((common.embed || (common.initialized && !common.pause.length)) && initialPause !== true){
// Fix for bug in Safari and IE where iframes are drawing out of order.
if (ad.tile === 1 && !common.embed) {
initialPause = true;
nextToLoad = 1;
}
return draw(key);
}
$D.info(messager('queue'), [key,ad]);
/* Add to the request queue to be executed on CN.dart.ready() */
/* Don't add to the request queue if we are in initialPause mode (writing out ads one after another to fix IE/Safari bug) */
if (initialPause !== true) {
$(window).one('CN.customEvents.dartRequest.'+key,{key:key},function(e){
draw(e.data.key);
});
}
return this;
},
/**
* Generate an script tag the adcall, and append to the container [placement][common.container]
* This is the actual call execution for embedded ads
* @param {string} placement Dart ad placement identifier
* @param {string} [url] Url to be used in place of ad pars
*/
drawEmbedded = function(placement,url) {
var ad = ads[placement];
ad.frame=false;
embedScript(ad.url=buildurl(ad,url));
$D.info(messager('call'), [placement,ad]);
return this;
},
/**
* Generate an iframe for the ad, and append to the container [placement][common.container]
* This is the actual call execution for iframed ads
* @param {string} placement Dart ad placement identifier
* @param {string} [url] Url to be used in place of ad pars
*/
drawFrame = function(placement,url) {
var ad = ads[placement],
dims=ad.sz.split('x');
ad.el.html(ad.frame=nakedFrame.clone().attr({
id : placement,
name : placement,
height : ad.collapse ? 1 : dims[1],
width : dims[0],
src : (ad.url=buildurl(ad,url)) && common.frameurl + '#' + encodeURIComponent(ad.url)
}).bind('load',{key:placement},onFrameDraw)
);
$D.info(messager('call'), [placement,ad]);
return this;
},
/**
* Default method for drawing ads defined here.
* If common.emed=true, init will set draw=drawEmbedded.
* The rest of the operations should be seamless.
*/
draw=drawFrame,
/**
* Generate a script el for embedded ads, and remote calls - Blocking is a must!
* @param {script} src Ad source.
*/
embedScript = function(src){
document.write('');
},
/**
* Initialize CN.dart, setting common ad parameters and evaluating all registered plug-ins.
* Once plug-ins are all evaluated, CN.dart is put in a ready state, which signals the begining
* of ad calls. Any calls made before the ready stat is set will be placed in a queue.
* @param {object} pars Shared params - ex: Site, Zone, shared kws.
* @param {string} [url] Url to be used in place of ad pars
*/
init = function(pars){
if(common.initialized){
$D.warn(msg_pre+'Initialization called more than once. This should only happen once per page.');
return false;
}
common.initialized=true;
common.site = pars.site,
common.zone = pars.zone,
common.ad = {
store : true,
kws : pars.kws,
tile : common.tile
};
updateKws();
test.charmap(pars.charmap);
plugin.run();
if(common.embed=(pars.embed || common.embed)) {
draw=drawEmbedded;
$D.info(messager('embed',true),[]);
}
$(window).trigger('CN.customEvents.dartInitialized');
$D.info(msg_pre+'Initialized', [common.ad]);
return ready();
},
/**
* Translate kw array into a ';'-delimited query string
* @param {object} ad Ad object to grab keywords from for translation.
* @param {string} [url] Url to be used in place of ad pars.
*/
keywordString = function(ad){
return 'kw=' + ad.kws.join(';kw=') + ';' + (ad.xkws.length ? '!c=' + ad.xkws.join(';!c=') + ';' : '');
},
/**
* Callback even dispatcher, executed on frame-load
* @param {object} e Event object for callback
*/
onFrameDraw = function(e){
var key=e.data.key,
ad = ads[key];
try {
ad.doc=ad.frame.contents();
} catch(err) {
$D.user(e, [e.target, e.target.id]);
}
$(window).trigger('CN.customEvents.dartAdDrawn.'+key,[key,"#"+key, ad]);
resize(e);
// Now upause the rest of the queue.
if (initialPause === true) {
if (nextToLoad $val.length ? $site.length : $val.length,
result=[];
for (;i 1 ? ret : ret[prop];
},
init : init,
ondraw : common.embed ? false : onFrameDraw,
ready : ready,
recalSize : recalSize,
register : function(install){
if(!install){
return this;
}
install = [].concat(install);
var i=0,
len=install.length;
for(;i