Created
October 5, 2011 14:40
-
-
Save jls/1264583 to your computer and use it in GitHub Desktop.
PunnBar with Worldnow example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Flag indicating that the punndit bar has | |
// already been loaded and initialized at least once. | |
var punnditLoaded = false; | |
// The WGNCustomAdHandler is going to be fired when the | |
// media in the WN player changes. The specific event we | |
// are interested in is the NewMedia event. It is fired | |
// whenever a pre-roll, clip and post-roll video is started. | |
// The NewClip event is supposed to only fire when the actual clip starts | |
// (not the pre or post roll) but the documentation lies. | |
WNAdWidget.prototype.WGNCustomAdHandler = function(p_evtObj) { | |
if(p_evtObj.evnt == "NewMedia") { | |
var objClip = p_evtObj.objClip; | |
// Since this event fires for every clip change, | |
// we have to determine if it is an ad or not. | |
// If the clip is a national ad (confirmed?) it will not | |
// have an isad property but instead will have an isAd property. | |
if(objClip.isad || objClip.isAd){ | |
// The clip is an ad but we can go ahead and load the punn bar. | |
// Since there could be multiple ads we will track whether the | |
// PunnBar is already loaded so we don't load it more than once. | |
if(!punnditLoaded){ | |
punndit_queue.push(['divWNVideoCanvas459', function(){ | |
return new pndt.players.worldnow(WNVideoCanvas459); | |
}, true]); // true parameter indicates we want to start the bar in a | |
// disabled state to prevent user interaction during an ad. | |
punnditLoaded = true; | |
} | |
}else{ | |
var punnContainer = document.getElementById('punn-container'); | |
punnContainer.removeAttribute('data-punn-id'); | |
punnContainer.setAttribute('data-punn-uid', 'http://worldnow.com/video/' + objClip.id.toString()); | |
// punndit_queue.push(['reload', 'divWNVideoCanvas459', function(){ | |
// return new pndt.players.worldnow(WNVideoCanvas459); | |
// }, pndt.embed.bar.enable]); | |
if(!punnditLoaded){ | |
punndit_queue.push(['divWNVideoCanvas459', function(){ | |
return new pndt.players.worldnow(WNVideoCanvas459); | |
}]); | |
punnditLoaded = true; | |
}else{ | |
pndt.embed.bar.reload('divWNVideoCanvas459', function(){ | |
return new pndt.players.worldnow(WNVideoCanvas459); | |
}, pndt.embed.bar.enable); | |
} | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment