(function () { var VPNBCCore = { // Custom core for NBC Offsite player playerFlavor: "base", playMode: "video", version: "NBC offsite 9/11/2014", debug: false, debugLevel: "4", // show all debugLine: 0, badFeedRetryCount: 0, maxFeedRetries: 10, defaultFeedId: "msnbc_video", // default msnbc feedId: "", feedUrl: "", showSource: "", currentGuid: "", baseGUIDUrl: "", baseAccountID: "2E2eJC", baseFeedUrl: "http://feed.theplatform.com/f/2E2eJC/", feedParameters: "", playerDivContainers: {}, restDiv: false, mpxFeedParameters: "?form=json", mpxFeedRange: "&range=-40", mainPlaylist: {}, mobileRestPlaylist: {}, mainPlayerDiv: {}, doPlayerInit: true, initTimeout: 0, playerWidth: function () { return -1 }, playerHeight: function () { return -1 }, restStateFillToOwner: true, restState: false, adCompanions: true, shareButtons: true, displayPlaylist: true, continuousPlay: true, metaData: true, autoPlay: true, displayBreakPoints: [320, 768, 1024, 1230], displayMode: "tablet", // desktop isiDevice: false, isMobile: false, inMobileRestState: false, endSlateOn: false, mobileFullScreenPlaying: false, isCurrentlyAd: false, readHash: false, isMobileDevice: false, requiresMobilePlaylist: false, inRestStateRequest: false, isIE8: false, isHD: false, useFreeWheelTestNetwork: false, LiveVideoStreamStatus: "notlive", LiveVideoPollInterval: 10000, LiveVideoIsPolling: false, tabletLiveVideoRest: false, Init: function (guid, feedid, startPlayer) { this.GetMainContainer(); $pdk.NBCplayer.CCSupport.init(); this.PDKinit(); if (((navigator.platform.indexOf("iPhone") != -1) || (navigator.platform.indexOf("iPod") != -1))) { this.requiresMobilePlaylist = true; this.isiDevice = true; } var mobileCheck = screen.width; if (screen.width > screen.height) { mobileCheck = screen.height; } if (navigator.userAgent.toLowerCase().indexOf("mobile") > -1 && (navigator.platform.indexOf("iPad") == -1)) { this.isMobileDevice = true; if (navigator.userAgent.toLowerCase().indexOf("windows") > -1) { this.requiresMobilePlaylist = true; this.isMobile = true; } } if (this.readHash) { this.hashCheck.grabHash(); } this.isMobile = this.CheckIfMobile(); if (mobileCheck < 390) { //this.requiresMobilePlaylist=true; this.isMobile = true; } if (this.isMobile || this.isMobileDevice) { this.restState = true; this.mpxFeedRange = "&range=-10"; $('#TPVideoPlayerContainer').addClass('mobile'); } this.isFlash = ((new Player("none")._runtime).toLowerCase() == "flash"); if (!this.isFlash && !this.isMobile) { // tablet this.restState = true; } this.initTimeout++; if (this.initTimeout > 3) { console.log('Init:exceeded 3 tries'); return; } var context = this; if (guid) { this.currentGuid = guid; } if (feedid) { this.SetFeedURL(feedid); } if (startPlayer != undefined) { this.doPlayerInit = startPlayer; } this.playerType = new Player("none")._runtime; this.DebugLog(":::::NBCplayer:::: ", this.playerMode, this.playerFlavor, this.version, this.playerType); this.TestForDevURL(); if (this.autoPlay && this.isFlash) { this.restState = false; } this.InitSpecifics(); if (this.playerMode == "show") { this.restState = true; this.ShowPlayerInit(); this.ShowPlayerTaxonomy.renderTaxonomyList(); } else { this.GetPlayerData(); } $pdk.NBCplayer.UIMessenger.init($('#tpContainerSizer')[0]); }, TestForDevURL: function () { var loc = (window.location.hostname) ? window.location.hostname : ""; var ref = (document.referrer) ? document.referrer : ""; if (loc == "dev.msnbc.com" || ref.indexOf('//dev.msnbc.com') > 0) { if (ref.indexOf('debug=true') > 0) { this.debug = "true"; } this.CheckToUseMPXDev(true); this.useFreeWheelTestNetwork = true; } }, CheckIfMobile: function () { if (screen.width <= this.displayBreakPoints[0]) { return true; } return false; }, ShowPlayerInit: function () { $('#' + $pdk.NBCplayer.playerDivContainers.playerParentContainer).addClass('showPlayer'); }, GetMainContainer: function () { this.mainPlayerDiv = $('#' + $pdk.NBCplayer.playerDivContainers.playerParentContainer); if (this.mainPlayerDiv.length < 1) { var classExtra = ""; if (this.playerFlavor.toLowerCase() == "embeddedplayer") { classExtra = " class='embeddedPlayer " + this.playerMode + "'"; } $('.tpContainer').wrap('
'); this.mainPlayerDiv = $('#' + $pdk.NBCplayer.playerDivContainers.playerParentContainer); //console.error('!!Main Player container not found. creating it'); } else { if (($('#tpContainerSizer').length) < 1) { $('.tpContainer').wrap('
'); } } this.applyClassesBasedOnDevice(["#TPVideoFeaturePlayer", "#TPVideoPlayerPlaylistHeader"]); if (this.playerFlavor != "FeaturePlayer") { return; } this.featurePlayerDiv = $('#TPVideoFeaturePlayer'); if (this.featurePlayerDiv.length < 1) { this.mainPlayerDiv.wrap('
'); this.featurePlayerDiv = $('#TPVideoFeaturePlayer'); } }, applyClassesBasedOnDevice: function (elementArray) { try { if (navigator.appName.toLowerCase() == 'microsoft internet explorer') { var vers = navigator.userAgent.substr(navigator.userAgent.toLowerCase().indexOf("msie ") + 5, 2); if (parseInt(vers, 10) < 9) { this.applyDeviceClassing(true, "ie8", elementArray); this.isIE8 = true; } } this.applyDeviceClassing(navigator.userAgent.toLowerCase().indexOf("android") > -1, "android", elementArray); this.applyDeviceClassing((navigator.userAgent.toLowerCase().indexOf("windows") > -1) && (navigator.userAgent.toLowerCase().indexOf("mobile") > -1), "windows", elementArray); } catch (err) { // do nothing } }, applyDeviceClassing: function (deviceCheck, classToApply, elementArray) { if (deviceCheck) { for (var el in elementArray) { if ($(elementArray[el]).length > 0) { if (!$(elementArray[el]).hasClass(classToApply)) { $(elementArray[el]).addClass(classToApply); } } } } }, InitSpecifics: function () { this.playerWidth = function () { return (window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth); }; this.playerHeight = function () { return (window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight) }; this.onPlayerResize(); }, GetPlayerData: function () { if (this.feedUrl.length > 0) { this.DataStoreModule.GetAndSetActiveFeed(this.feedId, $pdk.NBCplayer.GetInitialFeed); } else { //console.log('Feed not specified'); this.DataStoreModule.SetReleaseFromGUID(this.currentGuid, this.ProcessGuidData); } }, GetInitialFeed: function () { //console.log('GetInitialFeed::'); $pdk.NBCplayer.DataStoreModule.SetReleaseFromGUID($pdk.NBCplayer.currentGuid, $pdk.NBCplayer.StartPlayback); }, ProcessGuidData: function (data) { $pdk.NBCplayer.DataStoreModule.feedData = data; $pdk.NBCplayer.DebugLog("level:2", ':::::ProcessGuidData:: ', $pdk.NBCplayer.feedId, $pdk.NBCplayer.DataStoreModule.associatedFeedId); if ($pdk.NBCplayer.feedId != "none") { $pdk.NBCplayer.DataStoreModule.GetAndSetActiveFeed(this.feedId, $pdk.NBCplayer.GetInitialFeed); } else { if ($pdk.NBCplayer.DataStoreModule.associatedFeedId) { $pdk.NBCplayer.DebugLog('level:2', ':::::Getting associated feed ' + $pdk.NBCplayer.DataStoreModule.associatedFeedId); $pdk.NBCplayer.DataStoreModule.GetAndSetActiveFeed($pdk.NBCplayer.DataStoreModule.associatedFeedId, $pdk.NBCplayer.GetInitialFeed); } else { $pdk.NBCplayer.DebugLog('level:2', ':::::Using default feed ' + $pdk.NBCplayer.defaultFeedId); $pdk.NBCplayer.DataStoreModule.GetAndSetActiveFeed($pdk.NBCplayer.defaultFeedId, $pdk.NBCplayer.GetInitialFeed); } } }, LoadAssociatedFeed: function (feedid) { $pdk.NBCplayer.SetFeedURL(feedid); this.DataStoreModule.GetAndSetActiveFeed(feedid, $pdk.NBCplayer.StartPlayback); }, StartLiveStatusPolling: function() { if ($pdk.NBCplayer.DataStoreModule.videoType == "live" && !$pdk.NBCplayer.LiveVideoIsPolling) { $pdk.NBCplayer.LiveVideoIsPolling = true; $pdk.NBCplayer.DebugLog('____:LIVE video detected - initial status = '+$pdk.NBCplayer.DataStoreModule.liveVideoStatus); if ($pdk.NBCplayer.DataStoreModule.liveVideoStatus.toLowerCase() != "concluded") { if ($pdk.NBCplayer.LiveVideoStreamStatus == "unknown") { if ($pdk.NBCplayer.DataStoreModule.mpxid.length > 0) { $pdk.NBCplayer.LiveVideoCheck(); } else { if ($pdk.NBCplayer.debug) {console.error('---> Live Video - Cannot get mpxid');} } } } } }, StartPlayback: function (e) { var context = $pdk.NBCplayer; context.StartLiveStatusPolling(); if (context.doPlayerInit) { context.doPlayerInit = false; context.PlayerModeSetup(context.playerMode); context.SetUpEvents(); context.CreatePlaylistNameContainer(context.DataStoreModule.feedTitle); context.CrateMetaDataContainers(); var eventData = {}; eventData.type = "PlayerReady"; $pdk.controller.dispatchEvent('NBCplayerNotification', eventData); context.PrePDKinit(); if ($pdk.NBCplayer.DataStoreModule.videoType == "live" && $pdk.NBCplayer.DataStoreModule.liveVideoStatus.toLowerCase() != "live") { var liveVideoState = {} liveVideoState.liveState = $pdk.NBCplayer.DataStoreModule.liveVideoStatus.toLowerCase(); context.inRestStateRequest = true; context.LiveFeedStatesDispatch(liveVideoState); return; } if (context.restState) { if (!context.inRestStateRequest) { context.inRestStateRequest = true; context.RenderRestState(); } } else { context.SetVideoToPlay(context.DataStoreModule.releaseURL, !context.isFlash); } } else { if ($pdk.NBCplayer.DataStoreModule.videoType == "live" && ($pdk.NBCplayer.DataStoreModule.liveVideoStatus.toLowerCase() != "live" && !$pdk.NBCplayer.tabletLiveVideoRest)) { var liveVideoState = {} liveVideoState.liveState = $pdk.NBCplayer.DataStoreModule.liveVideoStatus.toLowerCase(); context.inRestStateRequest = true; context.LiveFeedStatesDispatch(liveVideoState); return; } context.SetVideoToPlay(context.DataStoreModule.releaseURL); if (context.isMobileDevice && (!context.requiresMobilePlaylist)) { //this is to catch android devices that play inline. $("#mobileRestSlider").hide(); } } }, InitSettings: function (o) { for (var i in o) { this[i] = o[i]; } }, restStateResizeMethod: function () { //nothing }, RenderRestState: function (liveVideoState) { if (liveVideoState) { $pdk.NBCplayer.DebugLog('level:2', ':::::Rendering Live Video State',liveVideoState.url); $pdk.NBCplayer.DataStoreModule.LiveVideoStatusUrl = liveVideoState.url; } else { $pdk.NBCplayer.DebugLog('level:2', ':::::Rendering Reststate '); } var context = $pdk.NBCplayer; context.DataStoreModule.statusFlags.inRestState = true; context.UpdateMetaData(); if (context.isMobile || (!context.isFlash) || (context.displayMode == "mobile" && context.playerMode != "show")) { setTimeout(function () { $('#tpContainerSizer')[0].appendChild(document.getElementById($pdk.NBCplayer.playerDivContainers.restState)); if (($pdk.NBCplayer.displayMode == "mobile" || context.isMobileDevice) && $pdk.NBCplayer.playerFlavor == "FeaturePlayer") { $pdk.NBCplayer.DebugLog('level:3', '::::: Rendering mobile playlist reststate'); $pdk.NBCplayer.inMobileRestState = true; var video = document.getElementsByTagName('video')[0]; video.style.display = "none"; video.controls = false; video.addEventListener('ended', function () { $pdk.NBCplayer.AdvanceMobilePlayList(); }); video.addEventListener('pause', function () { $pdk.NBCplayer.MobilePlayerPaused(); }); video.addEventListener('play', function () { $pdk.NBCplayer.MobilePlayerPlaying(); }); $pdk.NBCplayer.CustomRestStateForMobile(); } context.UIMessenger.reassign($('#tpContainerSizer')[0]); context.UIMessenger.Message("restStateRendered"); context.inRestStateRequest = false; }, 100); if ($('#TPVideoPlayerRestState').length < 1) { $('#tpContainerSizer').append('
'); context.UIMessenger.reassign($('.tpLayout')[0]); } } else { if ($('#TPVideoPlayerRestState').length < 1) { $('#tpContainerSizer').append('
'); context.UIMessenger.Message("restStateRendered"); context.UIMessenger.reassign($('#tpContainerSizer')[0]); } } var thumbImage; if (($pdk.NBCplayer.displayMode != "mobile" || ((!context.isMobile) && (context.isMobileDevice)) || $pdk.NBCplayer.playerFlavor != "FeaturePlayer")) { context.inRestStateRequest = false; context.restDiv = document.getElementById(context.playerDivContainers.restState); context.restDiv.innerHTML = ""; thumbImage = new $pdk.NBCplayer.AimsImager(context.restDiv); thumbImage.responsive = true; thumbImage.fillToOwner = context.restStateFillToOwner; thumbImage.resizeOwner = true; thumbImage.resizeMethod = context.restStateResizeMethod; $('#TPVideoPlayerLoading').hide(); restWidth = context.GetCorrectViewportWidth(); var thumburl = $pdk.NBCplayer.DataStoreModule.thumb; if (liveVideoState) { thumburl = liveVideoState.url; } thumbImage.create(thumburl, restWidth); context.restDiv = $('#' + context.playerDivContainers.restState); context.restDiv.append('
watch now
'); if (liveVideoState && liveVideoState.status != "live") { context.restDiv.unbind('click'); context.restDiv.click(function (e) { }); context.restDiv.hide(); $("#TPVideoPlayerRestPlayButton").hide(); $("#playIcon").hide(); } else { context.restDiv.unbind('click'); context.restDiv.click(function (e) { functionClick() }); $("#TPVideoPlayerRestPlayButton").show(); $("#playIcon").show(); } } var functionClick = function () { $pdk.NBCplayer.PlayVideo(); }; if (!context.isFlash) { functionClick = function () { if ($pdk.NBCplayer.DataStoreModule.videoType == "live" && $pdk.NBCplayer.LiveVideoStreamStatus != "live") { return; } $pdk.NBCplayer.PlayVideo($pdk.NBCplayer.DataStoreModule.guid); } } context.restImage = thumbImage; context.SetVideoHeight(); }, PlayVideo: function (guid) { var context = this; $pdk.NBCplayer.DebugLog('____:Playing video ', $pdk.NBCplayer.DataStoreModule.guid); this.UIMessenger.Message("startPlayback"); if (guid) { $pdk.NBCplayer.DataStoreModule.SetReleaseFromGUID(guid, $pdk.NBCplayer.StartPlayback); } if (this.DataStoreModule.statusFlags.inRestState) { context.SetVideoToPlay(context.DataStoreModule.releaseURL, !context.isFlash); } this.DataStoreModule.statusFlags.inRestState = false; $("#playIcon").hide(); $pdk.NBCplayer.canHideBrand = true; if ($pdk.NBCplayer.restDiv) { $pdk.NBCplayer.restDiv.hide(); } if (context.isMobileDevice && (!context.requiresMobilePlaylist)) { //this is to catch android devices that play inline. $("#mobileRestSlider").hide(); } }, PrePDKinit: function () { var plCallback = function () { }; var plCommonCallback = function (divId) { $pdk.NBCplayer.mainPlaylist.FlexApi.flexAnimate(1); if ($pdk.NBCplayer.playerMode == "show") { divId.addClass('showPlayer'); } } if (!this.displayPlaylist) { plCallback = function (divId) { $pdk.NBCplayer.mainPlaylistDiv = divId; divId.hide(); plCommonCallback(divId); } } else { plCallback = function (divId) { $pdk.NBCplayer.mainPlaylistDiv = divId; divId.fadeTo("slow", 1); plCommonCallback(divId); }; } $pdk.NBCplayer.DataStoreModule.MoveItemToFront($pdk.NBCplayer.DataStoreModule.guid); if (!$pdk.NBCplayer.isMobile) { this.mainPlaylist = new $pdk.NBCplayer.PlaylistModuleFLEXInstanseable(); $pdk.NBCplayer.DebugLog('level:2', ':::::Loading mainPlaylist::', this.mainPlaylist); this.mainPlaylist.InsertPlaylist( { id: $pdk.NBCplayer.playerDivContainers.mainPlaylist, parentDiv: $("#" + $pdk.NBCplayer.playerDivContainers.playerParentContainer), data: this.DataStoreModule.feedData, startAt: 0, callback: plCallback } ); } /* $pdk.NBCplayer.PlaylistModuleFLEX.InsertPlaylist( { id: $pdk.NBCplayer.playerDivContainers.mainPlaylist, data: this.DataStoreModule.feedData, startAt: 1, callback: plCallback }); */ // Once initialized - you can then fade out like this //$pdk.NBCplayer.TPVideoMainPlaylist.fadeTo('slow',0); // Rest state playlist example //$pdk.NBCplayer.DataStoreModule.RequestFeed('Weather',this.DataForRestStatePlaylist); }, DataForRestStatePlaylist: function (newdata) { //console.log('DataForRestStatePlaylist:: ',data ); $pdk.NBCplayer.PlaylistModuleFLEX.InsertPlaylist( { id: $pdk.NBCplayer.playerDivContainers.restStatePlaylist, data: newdata, callback: function (divId) {//divId.show(); divId.fadeTo("slow", 1); } }); //$pdk.NBCplayer.PlaylistModuleFLEX.InsertPlaylist($pdk.NBCplayer.playerDivContainers.restStatePlaylist,data); }, //abstracts SetUpSpecifics: function () { }, CustomEvents: function (e) { }, PlayerModeSetup: function (mode) { }, RenderElements: function () { }, SetUpEvents: function () { //console.log('setting up events'); var context = this; $pdk.controller.addEventListener("NBCplayerVideoInit", function (e) { context.Reporter.reset(); }); $pdk.controller.addEventListener("OnMediaLoadStart", function (e) { $pdk.NBCplayer.OnMediaLoadStart(e); }); //$pdk.controller.addEventListener("OnLoadReleaseUrl",function(e){$pdk.NBCplayer.OnPDKInitiazed(e);}); $pdk.controller.addEventListener("OnMediaComplete", function (e) { $pdk.NBCplayer.OnMediaComplete(e); }); $pdk.controller.addEventListener("OnReleaseEnd", function (e) { context.Reporter.reportOnEnd(context.FreeWheelModule.adIsRunning); $pdk.NBCplayer.OnReleaseEnd(e); }); $pdk.controller.addEventListener("OnMediaError", function (e) { $pdk.NBCplayer.OnMediaTimeout(e); }); $pdk.controller.addEventListener("OnReleaseError", function (e) { $pdk.NBCplayer.OnReleaseError(e); }); //$pdk.controller.addEventListener("OnGetRelease",function(e){ console.log("OnGetRelease: "+(e));}); $pdk.controller.addEventListener("OnReleaseStart", function (e) { context.Reporter.reportOnStart(context.FreeWheelModule.adIsRunning); $pdk.NBCplayer.OnPDKLoaded(e); }); $pdk.controller.addEventListener("OnMediaPause", function (e) { $pdk.NBCplayer.CustomEvents(e); context.Reporter.reportPause(context.FreeWheelModule.adIsRunning); }); $pdk.controller.addEventListener("OnMediaUnpause", function (e) { try{ if (($pdk.NBCplayer.playerFlavor =="EmbeddedPlayer")&& ($pdk.NBCplayer.playerMode !="Offsite")){ var guid = window.location.search.substring(6); window.parent.postMessage('platform-embedded-play:' + guid, '*'); } } catch(err){ console.log("canNotCommunicatewithParent"); } $pdk.NBCplayer.CustomEvents(e); }); $pdk.controller.addEventListener("OnMediaSeek", function (e) { context.Reporter.reportScrub(); }); $pdk.controller.addEventListener("OnShowFullScreen", function (e) { context.Reporter.setFullscreen(); }); $pdk.controller.addEventListener("OnSubtitleCuePoint", function (e) { context.Reporter.setCC(); }); $pdk.controller.addEventListener("OnAdvertisementClick", function (e) { $pdk.NBCplayer.FreeWheelModule.OnAdClickEvent(e); }); // non PDK events $pdk.controller.addEventListener("NBCplayerOnFeedError", function (e) { $pdk.NBCplayer.DataStoreModule.OnFeedError(e); }); $pdk.controller.addEventListener("NBCplayerOnFeedChange", function (e) { $pdk.NBCplayer.OnFeedChange(e); }); $pdk.controller.addEventListener("NBCplayerPlaylistClick", function (e) { $pdk.NBCplayer.OnPlaylistClick(e); }) $pdk.controller.addEventListener("NBCplayerNotification", function (e) { $pdk.NBCplayer.OnPlayerNotification(e); }) $pdk.controller.addEventListener("NBCplayerReport", function (e) { $pdk.NBCplayer.DebugLog(':::: NBCplayerReport', e.data); }); $pdk.controller.addEventListener("OnMediaPlaying", function (e) { context.Reporter.reportOnTime(e, $pdk.NBCplayer.FreeWheelModule); context.UIMessenger.Message("nowPlaying"); if (context.isMobileDevice && (!context.requiresMobilePlaylist)) { //this is to catch android devices that play inline. $("#mobileRestSlider").hide(); } }); $(window).resize(function () { $pdk.NBCplayer.onPlayerResize(); }) }, SetVideoToPlay: function (releaseURL, metadataOnly) { if (!metadataOnly) { $pdk.NBCplayer.DebugLog('____:Playing video using release ', releaseURL); $pdk.controller.setReleaseURL(releaseURL, true); $pdk.controller.pause(false); } this.UpdateMetaData(); }, LiveVideoCheck: function () { $pdk.NBCplayer.GetLiveVideoStatus(); setTimeout(function () { if ($pdk.NBCplayer.LiveVideoStreamStatus != "concluded" && $pdk.NBCplayer.DataStoreModule.videoType == "live") { $pdk.NBCplayer.LiveVideoCheck(); } else { $pdk.NBCplayer.LiveVideoIsPolling = false; $pdk.NBCplayer.DebugLog(':::::LiveVideoCheck:::: Event concluded or Video Switched - polling stopped. video type is ',$pdk.NBCplayer.DataStoreModule.videoType); } }, $pdk.NBCplayer.LiveVideoPollInterval) }, GetLiveVideoStatus: function() { //feedurl = "http://publica.nbcnews.com/videoredirect/Mpx/"+$pdk.NBCplayer.DataStoreModule.mpxid+"?callback=$pdk.NBCplayer.LiveFeedStatesDispatch"; //feedurl = "http://sys06-public.nbcnews.com/VideoRedirect/Mpx/"+$pdk.NBCplayer.DataStoreModule.mpxid+"?callback=$pdk.NBCplayer.LiveFeedStatesDispatch"; //feedurl = "http://sys06-public.nbcnews.com/mpx/"+$pdk.NBCplayer.DataStoreModule.mpxid+"?callback=$pdk.NBCplayer.LiveFeedStatesDispatch"; feedurl = "http://mpxvideogateway.nbcnews.com/mpx/"+$pdk.NBCplayer.DataStoreModule.mpxid+"?callback=$pdk.NBCplayer.LiveFeedStatesDispatch"; //feedurl = "http://playback.nbcnews.com/VideoRedirect/Mpx/"+$pdk.NBCplayer.DataStoreModule.mpxid+"?callback=$pdk.NBCplayer.LiveFeedStatesDispatch"; //console.log('GetLiveVideoStatus:: url = '+feedurl); $.ajax({ type: "GET", url: feedurl, async: false, cache: true, dataType: "script", crossDomain: true, error: function (xhr, textStatus, errorThrown) { console.error('GetLiveVideoStatus:: cannot read feed',feedurl,' Error: ',errorThrown); } }); }, LiveFeedStatesDispatch: function(data) { var liveVideoState = {}; liveVideoState.status = "unknown"; if (data.liveState) { liveVideoState.status = data.liveState.toLowerCase(); } $pdk.NBCplayer.DebugLog(':::::LiveFeedStatesDispatch:::: Status = '+liveVideoState.status); switch(liveVideoState.status) { case "coming up": liveVideoState.url = "http://media2.s-nbcnews.com/i/msnbc/components/video/_player/configurations/thePlatform/assets/nbcnewslivestates/liveComingUp.jpg"; break; case "concluded": liveVideoState.url = "http://media2.s-nbcnews.com/i/msnbc/components/video/_player/configurations/thePlatform/assets/nbcnewslivestates/liveConcluded.jpg"; break; case "general break": liveVideoState.url = "http://media2.s-nbcnews.com/i/msnbc/components/video/_player/configurations/thePlatform/assets/nbcnewslivestates/liveWillResume.jpg"; break; case "ad break": liveVideoState.url = "http://media2.s-nbcnews.com/i/msnbc/components/video/_player/configurations/thePlatform/assets/nbcnewslivestates/liveWillResume.jpg"; break; case "live": break; default: if ($pdk.NBCplayer.debug) { console.error('Unknown live feed status ='+liveVideoState.status); } return; break; } $pdk.NBCplayer.SetLivePlayerState(liveVideoState); }, SetLivePlayerState: function(liveVideoState) { if ($pdk.NBCplayer.LiveVideoStreamStatus != liveVideoState.status) { $pdk.NBCplayer.LiveVideoStreamStatus = liveVideoState.status; if ($pdk.NBCplayer.LiveVideoStreamStatus == "live") { if ($pdk.NBCplayer.isFlash) { liveThumb = $pdk.NBCplayer.DataStoreModule.ConvertToFixedAims($pdk.NBCplayer.DataStoreModule.thumb); liveVideoState.url = liveThumb; $pdk.NBCplayer.RenderRestState(liveVideoState); } else { // mobile/tablet $pdk.NBCplayer.tabletLiveVideoRest = true; $pdk.NBCplayer.RenderRestState(); } } else { $pdk.NBCplayer.RenderRestState(liveVideoState); setTimeout(function () { if ($pdk.NBCplayer.restDiv) { $pdk.NBCplayer.restDiv.show(); $pdk.controller.pause(true); } }, 100); } } }, OnFeedChange: function (e) { }, OnPlaylistClick: function (e) { console.log('OnPlaylistClick:: ', e, e.data.guid, e.data.feedid); }, OnPlayerNotification: function (e) { //console.log('OnPlayerNotification:: ', e.data.type,e.data.guid); }, CreateShareToolBar: function () { // console.log('share button here'); if (this.shareButtons) { var metaHolder = $('#' + $pdk.NBCplayer.playerDivContainers.metaHolder); //var shareHTML = '
'; var shareHTML = '
upcomsharesave
' metaHolder.append('
' + shareHTML + '
'); $('#' + $pdk.NBCplayer.playerDivContainers.shareButtons + ' .j_social_share').bind('click', function () { $pdk.controller.pause(true); console.log('share clicked - requesting data', $pdk.NBCplayer.PlayerData()); }) //this.TestSeupShareButtonListener(); } }, UpdateMetaData: function () { //console.log('updateMetaData::',this.DataStoreModule.title); if (this.metaData) { $('#' + this.playerDivContainers.sourceAndDate).html(this.DataStoreModule.sourceAndDate); $('#' + this.playerDivContainers.title).html(this.DataStoreModule.ParseQuotes(this.DataStoreModule.title)); $('#' + this.playerDivContainers.description).html(this.DataStoreModule.ParseQuotes(this.DataStoreModule.description)); } // send notification with object this.SendUpdateNotification(); }, PlayerData: function () { $pdk.NBCplayer.DataStoreModule.playerUrl = "http://player.theplatform.com/p/69ekLC/NBCFeaturePlayerDEV?guid=" + this.DataStoreModule.guid; return $pdk.NBCplayer.DataStoreModule; }, SendUpdateNotification: function () { var eventData = {}; eventData.type = "VideoPlay"; eventData.guid = $pdk.NBCplayer.DataStoreModule.guid; eventData.title = $pdk.NBCplayer.DataStoreModule.title; eventData.releaseURL = $pdk.NBCplayer.DataStoreModule.releaseURL; eventData.url = $pdk.NBCplayer.DataStoreModule.canonical; $pdk.controller.dispatchEvent('NBCplayerNotification', eventData); }, TestSeupShareButtonListener: function () { $pdk.controller.addEventListener("NBCplayerNotification", function (e) { $pdk.NBCplayer.TestShareButtonListener(e); }); }, TestShareButtonListener: function (data) { console.log('TestShareButtonListener:: ', data); }, GetCorrectViewportWidth: function () { var parentWidth = $("#TPVideoPlaylistTaxonomyContainer").parent().width(); var w1 = $("#TPVideoPlaylistTaxonomyContainer").width(); var w2 = $("#TPVideoMainPlaylist").width(); var padding = 50; var bw = (parentWidth) ? parentWidth : (window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth); if (bw < this.displayBreakPoints[3]) { w2 = 0; padding = 0; } var dwidth = (w1 + w2); var width = bw - dwidth - padding; //console.log("w1: "+w1+" - w2: "+ w2+ " - bw: "+bw+ "- width: " +width); return width; }, EnforceSizing:function(height,width){ $('#player').width(width); $("#tpContainerSizer").removeClass(); var mode=(width>768)?"desktop":((width>320)?"tablet":"mobile"); $("#tpContainerSizer").addClass(mode); $("#TPVideoPlayerContainer").css("width", width); $("#tpContainerSizer").css("width", width); $("#tpContainerSizer").parent().css("width", width); if (navigator.userAgent.toLowerCase().indexOf("msie")>-1){ $("#TPVideoPlayerContainer")[0].style.marginLeft="0px"; } $(".tpContainer").css("width", width); $(".tpLayout").css("width", width); $('#' + this.playerDivContainers.restState).css("width", width); $("#player").height(height); if ($("video").length>-1){ $("video").height(height); $("video").width(width); } if ($("#player").length>-1){ try{ $("#player")[0].firstChild.style.height=height; $("#player")[0].firstChild.style.width=width; $("#player")[0].firstChild.height=height; $("#player")[0].firstChild.width=width; } catch(e){ //no op } } if (this.restImage) { var obj2 = {}; obj2.height = height; obj2.width = width obj2.id = this.restImage.aimsByWidth(width); this.restImage.preSizeImage(); this.restImage.sizeImage(obj2); } $("#tpContainerSizer").css("height", height); $("#TPVideoEndSlate").css("height", height); }, SetVideoHeight: function (width) { if (!width){ if (this.enforcedSize){ width=this.enforcedSize; } else{ width = this.GetCorrectViewportWidth(); } } else{ this.enforcedSize=width; } var aimImager = new $pdk.NBCplayer.AimsImager(null); var obj = aimImager.getBestFit(width, width); var height = obj.height; if (height==0||width==0){ var timeoutcontext=this; if (!timeoutcontext.inc){ timeoutcontext.inc=0; } timeoutcontext.inc++; setTimeout(function(){ timeoutcontext.SetVideoHeight(); },1000); return; } this.EnforceSizing(height,width); }, onPlayerResize: function () { var w = $('body').innerWidth(); this.displayMode = (w < this.displayBreakPoints[1]) ? 'mobile' : (w < this.displayBreakPoints[2]) ? 'tablet' : (w < this.displayBreakPoints[3]) ? 'tablet-landscape' : 'desktop'; //console.log('onPlayerResize:: ',w,this.displayMode,this.playerMode); this.SetVideoHeight(); this.FreeWheelModule.setAdPosition(this.displayMode); switch (this.displayMode) { case 'mobile': $('#TPVideoFeaturePlayer').removeClass('tablet tablet-landscape desktop'); $('#TPVideoFeaturePlayer').addClass('mobile'); //$pdk.NBCplayer.FreeWheelModule.Hide300x250(); //$pdk.NBCplayer.FreeWheelModule.Hide300x60(); break; case 'tablet': $('#TPVideoFeaturePlayer').removeClass('mobile tablet-landscape desktop'); $('#TPVideoFeaturePlayer').addClass('tablet'); break; case 'tablet-landscape': $('#TPVideoFeaturePlayer').removeClass('mobile tablet desktop'); $('#TPVideoFeaturePlayer').addClass('tablet-landscape'); break; case 'desktop': $('#TPVideoFeaturePlayer').removeClass('tablet tablet-landscape mobile'); $('#TPVideoFeaturePlayer').addClass('desktop'); break; default: if (this.mainPlaylistDiv) { this.mainPlaylistDiv.show(); } break; } var timeoutcontext=this; setTimeout(function(){ timeoutcontext.SetVideoHeight(); },1000); }, PDKinit: function () { $pdk.NBCplayer.DebugLog('____:PDK initialize'); var context = this; setTimeout(function () { $pdk.initialize(); context.UIMessenger.reassign($('#tpContainerSizer')[0]); }, 100) }, OmnitureSetVar: function (evar, value) { //console.log('setting Omniture evar ',evar,' = ',value); }, OnPDKLoaded: function (e) { //this.PreCustomPDKLoadActions(e); //this.PostCustomPDKLoadActions(e); $pdk.NBCplayer.CCSupport.onPDKInitiazed(); }, OnPDKInitiazed: function (e) { }, OnMediaLoadStart: function (e) { this.PreCustomMediaStartActions(e); this.PreCustomPDKLoadActions(e); this.onPlayerResize(); $('#TPVideoPlayerLoading').hide(); }, OnMediaComplete: function (e) { //alert('onMediaComplete'); //console.log('OnMediaEnded::'); try { if (!e.data.baseClip.isAd) { if (!this.isMobileDevice) { this.VideoHasEndedLoadNext(); } } } catch (err) { } }, OnReleaseEnd: function (e) { //console.log('OnReleaseEnd::'); if (!this.isFlash && this.isMobileDevice) { $pdk.controller.showFullScreen(false); this.VideoHasEndedLoadNext(); } }, NewVideoOnError: function (e) { var context = $pdk.NBCplayer; if (context.DataStoreModule.mediaIndex) { context.DataStoreModule.mediaIndex++; } else { context.DataStoreModule.mediaIndex = 1; } var mUrl = context.DataStoreModule.mediaArray[context.DataStoreModule.mediaIndex]; if (mUrl) { $pdk.controller.setReleaseURL(mUrl, true); $pdk.controller.play(); } else { context.DataStoreModule.mediaIndex = 0; this.VideoHasEndedLoadNext(); } }, OnReleaseError: function (e) { this.NewVideoOnError(e); //console.log(e); }, OnMediaTimeout: function (e) { //console.error('OnMediaTimeout:: ',e.data.clip.title); //this.VideoHasEndedLoadNext(); }, VideoHasEndedLoadNext: function () { $pdk.NBCplayer.DebugLog('level:3', '::::: VideoHasEndedLoadNext - index = ', this.DataStoreModule.playlistIndex); var mainplaylistObj = $pdk.NBCplayer[$pdk.NBCplayer.playerDivContainers.mainPlaylist]; //console.error('VideoHasEndedLoadNext::', this.DataStoreModule.playlistIndex, this.DataStoreModule.feedData.entries.length); //console.log('attempting stop'); //$pdk.controller.playAll = false; //$pdk.controller.pause(true); if (this.continuousPlay && (this.DataStoreModule.playlistIndex < this.DataStoreModule.feedData.entries.length - 1)) { this.DataStoreModule.GetNextGuidInPlaylist(mainplaylistObj); } else { $pdk.NBCplayer.DebugLog('level:3', '::::: End of playlist!! index=', this.DataStoreModule.playlistIndex, 'total=', this.DataStoreModule.feedData.entries.length); //console.log('end of playlist!! lookup next playlist to use index=', this.DataStoreModule.playlistIndex, 'total=', this.DataStoreModule.feedData.entries.length); $pdk.controller.pause(true); var endstateFeedId = ""; if ($pdk.NBCplayer.DataStoreModule.sourceId != "") { endstateFeedId = $pdk.NBCplayer.DataStoreModule.sourceId; } else { if ($pdk.NBCplayer.debug) { console.error('no sourceId using default ', this.defaultFeedId); } endstateFeedId = this.defaultFeedId; } this.PostCustomMediaEndActions(endstateFeedId); } }, PreCustomMediaStartActions: function (e) { }, PostCustomMediaStartActions: function (e) { }, PreCustomPDKLoadActions: function (e) { }, PostCustomPDKLoadActions: function (e) { }, PostCustomMediaEndActions: function (e) { }, CustomRestStateForMobile: function () { }, CustomRestStateClick: function () { }, AdvanceMobilePlayList: function () { }, MobilePlayerPaused: function () { }, MobilePlayerPlaying: function () { }, GetFeedID: function (feedIdOverride) { var feedid; var feedidquerystring = $pdk.NBCplayer.GetQuery("feedid", ""); if (feedidquerystring != "") { //console.log('feedid from querystring'); feedid = feedidquerystring; } var divfeedid = $('#' + $pdk.NBCplayer.playerDivContainers.playerParentContainer).attr('feedid'); if (divfeedid && !feedid) { //console.log('feedid from div'); feedid = divfeedid; } if (feedIdOverride) { feedid = feedIdOverride; } if (feedid) { if (feedid == 'none') { this.feedUrl = ""; this.feedId = "none"; } else { this.SetFeedURL(feedid); } } else { this.feedUrl = ""; this.feedId = 'none'; } }, GetShowSource: function (defaultShowSource) { var showSource; if (defaultShowSource) { showSource = defaultShowSource; } var sourcequerystring = $pdk.NBCplayer.GetQuery("source", ""); if (sourcequerystring != "") { //console.log('feedid from querystring'); showSource = sourcequerystring; } var divsource = $('#' + $pdk.NBCplayer.playerDivContainers.showPlaylists).attr('source'); if (divsource && !showSource) { //console.log('feedid from div'); showSource = divsource; } this.showSource = showSource; }, CheckToUseMPXDev: function (force) { var newmpxaccount = $pdk.NBCplayer.GetQuery("usempxdev", ""); if (newmpxaccount != "" || force) { $pdk.NBCplayer.baseFeedUrl = $pdk.NBCplayer.baseFeedUrl.replace('2E2eJC','69ekLC'); $pdk.NBCplayer.baseGUIDUrl = $pdk.NBCplayer.baseGUIDUrl.replace('2E2eJC','69ekLC').replace($pdk.NBCplayer.defaultFeedId,'nbcnewsdev'); $pdk.NBCplayer.defaultFeedId = "nbcnewsdev"; $pdk.NBCplayer.DebugLog("---> Using MPX Dev account"); } }, LoadNewFeed: function (feedid) { //console.log('LoadNewFeed:: '+feedid); $pdk.NBCplayer.SetFeedURL(feedid); //console.log($pdk.NBCplayer.feedUrl); $pdk.NBCplayer.currentGuid = ""; $pdk.NBCplayer.DataStoreModule.GetAndSetActiveFeed(feedid, $pdk.NBCplayer.RefreshPlaylist); }, RefreshPlaylist: function (data) { if ($pdk.NBCplayer.mainPlaylist.RenderData) { //console.log('in RefreshPlaylist::',$pdk.NBCplayer.DataStoreModule.statusFlags.inRestState); $pdk.NBCplayer.mainPlaylist.RenderData({ id: $pdk.NBCplayer.playerDivContainers.mainPlaylist, data: $pdk.NBCplayer.DataStoreModule.feedData }) if ($pdk.NBCplayer.DataStoreModule.statusFlags.inRestState) { $pdk.NBCplayer.DataStoreModule.SetReleaseFromGUID($pdk.NBCplayer.currentGuid, $pdk.NBCplayer.RenderRestState); } else { $pdk.NBCplayer.mainPlaylist.MoveToSlide(0); } } if ($pdk.NBCplayer.mobileRestPlaylist.RenderData) { $pdk.NBCplayer.mobileRestPlaylist.RenderData({ id: 'mobileRestSlider', data: $pdk.NBCplayer.DataStoreModule.feedData }) if ($pdk.NBCplayer.DataStoreModule.statusFlags.inRestState) { $pdk.NBCplayer.DataStoreModule.SetReleaseFromGUID($pdk.NBCplayer.currentGuid, $pdk.NBCplayer.RenderRestState); } else { $pdk.NBCplayer.mobileRestPlaylist.MoveToSlide(0); } } }, SetFeedURL: function (feedid) { //console.log('SetFeedURL::'); this.feedId = feedid; this.feedUrl = this.baseFeedUrl + feedid; $pdk.controller.dispatchEvent('NBCplayerOnFeedChange', feedid); }, GetGUID: function (guidOverride) { var guid; var guidquerystring = $pdk.NBCplayer.GetQuery("guid", ""); if (guidquerystring != "") { //console.log('Guid from querystring'); guid = guidquerystring; } var divguid = $('#' + $pdk.NBCplayer.playerDivContainers.playerParentContainer).attr('guid'); if (divguid && !guid) { //console.log('Guid from div'); guid = divguid; } if (guidOverride) { // only for dev guid = guidOverride; } if (guid) { this.currentGuid = guid; } }, GetQuery: function (queryVar, defaultVar) { var check = new RegExp("[&|?]" + queryVar + "=([^&]*)", "ig"); var testValue = check.exec(location.search); return (testValue && (testValue[1] + "")) ? testValue[1] : defaultVar; }, GetKruxData: function(field) { var m, k='kx'+field; if (window.localStorage) { return window.localStorage[k] || ""; } else if (navigator.cookieEnabled) { m = document.cookie.match(k+'=([^;]*)'); return (m && unescape(m[1])) || ""; } else { return ''; } }, CreateKruxKeys: function(len) { var keyval =""; var kuser = this.GetKruxData('user'); var ksegs = this.GetKruxData('segs'); var deli = ""; if (kuser) { keyval = "kuid="+kuser; deli = "&"; } if (ksegs) { b = ksegs.split(","); for (var c=0;c= parseInt(dl[0]) && level <= parseInt(dl[1])) { if (console.debug) { if ($pdk.NBCplayer.isIE8) { console.log(args); } else { console.debug.apply(console, args); } } else { console.log(msg); // IE } } if (timing[1]) { if (this.debugLine == timing[1]) { stotalDate = new Date(timed- sstart); stime = stotalDate.getMinutes()+":"+stotalDate.getSeconds()+":"+stotalDate.getMilliseconds(); console.error('Time elapsed from item '+timing[0].toString()+' through '+timing[1].toString()+' =',stime); } } } }; //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ var VPNBCDataStoreModule = { version: "5/16/2013 1a", feedId: "", associatedFeedId: "", guid: "", title: "", description: "", source: "", canonical: "", date: "", // pubdate playerType: "", playlistIndex: 0, releaseURL: "", statusFlags: { adIsPlaying: false, inRestState: false, guidNotInPlaylist: false }, previousFeedId: "", previousGuid: "", currentItem: {}, feedData: {}, feeds: {}, onComplete: {}, RequestFeed: function (feedid, callback) { if (this.feeds[feedid]) { //console.log('RequestFeed:: from memory'); callback(this.feeds[feedid]); } else { this.GetFeedFromMPX(feedid, callback); } }, StoreFeed: function (data, context) { var feedid = context; var callback = this.onComplete[feedid].callback; if (data.isException) { if ($pdk.NBCplayer.debug) { console.error('bad data returned - using default feedid ', data); } if ($pdk.NBCplayer.badFeedRetryCount < $pdk.NBCplayer.maxFeedRetries) { $pdk.NBCplayer.badFeedRetryCount++; this.RequestFeed($pdk.NBCplayer.defaultFeedId, callback); } else { if ($pdk.NBCplayer.debug) { console.error('Feed Retry limit ', $pdk.NBCplayer.maxFeedRetries, 'reached'); } } } else { data.feedid = feedid; this.feeds[feedid] = data; //console.log('RequestFeed:: from MPX'); callback(data); } }, GetFeedFromMPX: function (feedid, callback) { this.onComplete[feedid] = {}; this.onComplete[feedid].callback = callback; var requestURL = $pdk.NBCplayer.baseFeedUrl + feedid + $pdk.NBCplayer.mpxFeedParameters + $pdk.NBCplayer.mpxFeedRange + "&callback=$pdk.NBCplayer.DataStoreModule.StoreFeed&context=" + feedid; $pdk.NBCplayer.DebugLog(':::::GetFeedFromMPX ', requestURL); $.ajax({ type: "GET", url: requestURL, async: false, cache: true, dataType: "script", crossDomain: true, error: function (xhr, textStatus, errorThrown) { $pdk.controller.dispatchEvent('NBCplayerOnFeedError', errorThrown); //alert(errorThrown); } }); }, GetAndSetActiveFeed: function (feedid, callback) { this.feedCallback = false; if (callback) { this.feedCallback = callback; } this.RequestFeed(feedid, $pdk.NBCplayer.DataStoreModule.ReadDataFromFeed); }, ReadDataFromFeed: function (data) { //console.log('ReadDataFromFeed:: ',$pdk.NBCplayer.currentGuid); var context = $pdk.NBCplayer.DataStoreModule; context.feedData = data; if ($pdk.NBCplayer.currentGuid == "") { //console.log('GUID from feeds first item',data); try { $pdk.NBCplayer.currentGuid = context.feedData.entries[0].guid; } catch (e) { if ($pdk.NBCplayer.debug) { console.error('No data in feed - reseting to ' + $pdk.NBCplayer.defaultFeedId); } $pdk.NBCplayer.currentGuid = ""; $pdk.NBCplayer.Init('', $pdk.NBCplayer.defaultFeedId, true); return; } } context.feedCallback(data); }, GetNextGuidInPlaylist: function (playlistObj) { this.playlistIndex++; //console.log('GetNextGuidInPlaylist', this.playlistIndex); if ($pdk.NBCplayer.mainPlaylist.MoveToSlide) { $pdk.NBCplayer.mainPlaylist.MoveToSlide(this.playlistIndex + 1); $pdk.NBCplayer.mainPlaylist.SetStatusLabel(this.playlistIndex); } var nextGuid = this.feedData.entries[this.playlistIndex].guid; this.SetReleaseFromGUID(nextGuid, $pdk.NBCplayer.StartPlayback); }, GetMediaUrls: function (data) { var mediaArray = new Array(); var media = {}; var mezzVersion = 0; if (data.nnd$mezzVersion) { mezzVersion = data.nnd$mezzVersion; } for (var mc in data.media$content) { var cMedia = data.media$content[mc]; if (cMedia.plfile$format&&cMedia.plfile$format.toLowerCase() == "f4m") { media.liveVideo = cMedia.plfile$url; } if (cMedia.plfile$format&&cMedia.plfile$format.toLowerCase() == "mpeg4") { if (cMedia.plfile$assetType&&cMedia.plfile$assetType.toLowerCase() == "akamai video") { media.akami = cMedia.plfile$url; $pdk.NBCplayer.isHD = true; } else { if (cMedia.plfile$bitrate == 0 && mezzVersion < 2) { media.unicorn = cMedia.plfile$url; } else { if (cMedia.plfile$width < 600 || cMedia.plfile$bitrate < 600000) { media.lo = cMedia.plfile$url; } else { media.hi = cMedia.plfile$url; } } } } } if (media.liveVideo) { mediaArray[mediaArray.length] = media.liveVideo; } else { if (media.akami) { mediaArray[mediaArray.length] = media.akami; } if (media.unicorn && mezzVersion < 2) { mediaArray[mediaArray.length] = media.unicorn; } if ($pdk.NBCplayer.isMobile) { mediaArray[mediaArray.length] = media.lo; mediaArray[mediaArray.length] = media.hi; } else { mediaArray[mediaArray.length] = media.hi; mediaArray[mediaArray.length] = media.lo; } } return mediaArray; }, SetReleaseFromGUID: function (guid, callback) { $pdk.NBCplayer.DebugLog(':::::SetReleaseFromGUID ', guid, this.feedData); if (callback) { this.guidCallBack = callback; } else { if ($pdk.NBCplayer.debug) {console.error('Uknown callback'); } this.guidCallBack = false; } var releaseURL; var singleItem; var context = this; try { $.each(this.feedData.entries, function (i, elem) { if (elem.guid === guid) { var mediaUrls = $pdk.NBCplayer.DataStoreModule.GetMediaUrls(elem); releaseURL = mediaUrls[0]; singleItem = elem; context.playlistIndex = i; return false; } }); } catch (e) { $pdk.NBCplayer.DebugLog(':::::', guid, 'not found in ', this.feedData); }; if (releaseURL) { this.releaseURL = releaseURL; this.SetVideoData(singleItem); if (this.guidCallBack) { this.guidCallBack(singleItem); } else { if ($pdk.NBCplayer.debug) { console.error('SetReleaseFromGUID:: unknown callback');} } } else { //console.log('From feed'); this.playlistIndex = 0; this.GetReleaseURLfromMasterFeed(guid); } }, setReportData: function (data) { var reportData = { fileName: data.guid, show: data.nnd$source, clipName: data.title, guid: data.guid, adSupport: (data.plmedia$adPolicyId != "http://data.delivery.theplatform.com/delivery/data/AdPolicy/31476") ? "true" : "Breaking News", issues: [], subIssues: [], topics: [], people: [], franchise: [], wbId: data.nnd$workbenchId }; for (var item in data.media$categories) { var cat = data.media$categories[item]; if (cat) { cat = cat["media$name"]; if (!cat){continue;} aCat = cat.toLowerCase().split("/"); if (aCat[0] == "msnbc") { var type = aCat[1]; var pushArray = ""; switch (type) { case "issues": reportData.issues.push(aCat[2]); if (aCat[3]) { pushArray = "subIssues"; } break; case "topics": switch (aCat[2]) { case "general": pushArray = "topics"; break; case "people": pushArray = "people"; break; case "franchise": pushArray = "franchise"; break; } break; } if (pushArray) { reportData[pushArray].push(aCat[3]); } } } } $pdk.controller.dispatchEvent('NBCplayerVideoInit', reportData); }, GetReleaseURLfromMasterFeed: function (guid) { var requestURL = $pdk.NBCplayer.baseGUIDUrl + guid + "&callback=$pdk.NBCplayer.DataStoreModule.GetSingleItem"; $pdk.NBCplayer.DebugLog('::::: GetReleaseURLfromMasterFeed::', requestURL); $.ajax({ type: "GET", url: requestURL, async: false, cache: true, dataType: "script", crossDomain: true, error: function (xhr, textStatus, errorThrown) { $pdk.controller.dispatchEvent('NBCplayerOnFeedError', errorThrown); } }); }, GetSingleItem: function (data) { var releaseURL = ""; try { this.SetVideoData(data.entries[0]); // single media in feed fix if (this.mediaArray[0] == undefined) { releaseURL = this.mediaArray[1]; } else { releaseURL = this.mediaArray[0]; } } catch (e) { if ($pdk.NBCplayer.debug) { console.error('Invalid GUID or data:', $pdk.NBCplayer.currentGuid); } if ($pdk.NBCplayer.DataStoreModule.feedData.length > 0) { $pdk.NBCplayer.DataStoreModule.SetReleaseFromGUID(this.feedData.entries[0].guid, $pdk.NBCplayer.DataStoreModule.guidCallBack); } else { if ($pdk.NBCplayer.debug) {console.error('GetSingleItem:: no feed data - re-init with default ' + $pdk.NBCplayer.defaultFeedId + ' feed'); } $pdk.NBCplayer.currentGuid = ""; $('#TPVideoPlayerLoading').hide(); $pdk.NBCplayer.Init('', $pdk.NBCplayer.defaultFeedId, true); } } if (releaseURL && releaseURL.length > 0) { if ($pdk.NBCplayer.DataStoreModule.feedData.entries) { if (data && data.entries) { $pdk.NBCplayer.DataStoreModule.feedData.entries.unshift(data.entries[0]); $pdk.NBCplayer.DataStoreModule.feedData.entries.pop(); } } else { $pdk.NBCplayer.DataStoreModule.feedData = data; } // check for existance of feeds $pdk.NBCplayer.DataStoreModule.statusFlags.guidNotInPlaylist = true; this.releaseURL = releaseURL; if (this.guidCallBack) { this.guidCallBack(data); } else { console.error('GetSingleItem:: no callback specified'); } } else { if ($pdk.NBCplayer.debug) { console.error('Bad data in feed - ensure media$content contains "F4M" or "mpeg4"'); } } }, GetAssociatedFeedId: function (url) { var associatedFeedId = ""; var feedArray = url.split("/"); if (feedArray.length > 1) { associatedFeedId = feedArray[(feedArray.length) - 1]; } return associatedFeedId.replace(/dev/ig, "nnd"); }, MoveItemToFront: function (guid) { if (!this.feedData.entries) { if ($pdk.NBCplayer.debug) {console.error('MoveItemToFront:: entries is blank'); } return; } playlistIndex = -1; $.each(this.feedData.entries, function (i, elem) { if (elem.guid === guid) { playlistIndex = i; return false; } }); if (playlistIndex > 0) { //console.log('MoveItemToFront:: Removing video at index ' + playlistIndex); var itemcopy = this.feedData.entries[playlistIndex]; this.feedData.entries.splice(playlistIndex, 1); this.feedData.entries.unshift(itemcopy); this.playlistIndex = 0; } if (playlistIndex == -1) { //console.log('MoveItemToFront:: not in playlist'); this.feedData.entries.unshift(this.currentItem); } }, OnFeedError: function (e) { console.error("Feed Error ", e); }, PopulateFromData: function (data, populationObject, populationArray) { for (var dpull in populationArray) { var ditem = populationArray[dpull]; populationObject[ditem[0]] = this.fillFromData(data, ditem[1], ditem[2]); } }, fillFromData: function (data, item, defaultValue) { var ret = data; for (var itm in item) { if(typeof(item[itm])=="function"){continue;} if (ret[item[itm]]) { ret = ret[item[itm]]; } else { ret = ""; } } if (!ret) { ret = defaultValue; } //console.log(ret); return ret; }, SetVideoData: function (datal) { var context = this; var dataNBCNEWSMatrix = [ ["mpxid", ["id"], ""], ["canonical", ["nnd$canonicalUrl", "href"], "http://www.msnbc.com/"], ["title", ["nnd$longTitle"], datal.title], ["description", ["description"], ""], ["guid", ["guid"], "corrupted_video"], ["source", ["nnd$source"], "msnbc"], ["mezzVersion", ["nnd$mezzVersion"], 0], ["sourceId", ["nnd$sourceId"], "nnd_18424721"], ["associatedPlaylist", ["nnd$associatedPlaylist", "href"], "http://feed.theplatform.com/f/2E2eJC/nnd_18424721"], ["thumb", ["plmedia$defaultThumbnailUrl"], "http://media2.s-nbcnews.com/i/msnbc/Components/Video/_Player/configurations/ni.jpg"], ["date", ["pubDate"], 1], ["videoType",["nnd$videoType"],"broadcast"], ["liveVideoStatus",["nnd$liveVideoStatus"],"unknown"] ]; this.PopulateFromData(datal, context, dataNBCNEWSMatrix); var tid = this.mpxid.split('/'); if (tid.length > 0) { this.mpxid = tid[tid.length-1]; } this.currentItem = datal; this.previousGuid = this.guid; this.previousFeedId = this.feedId; $("#player").attr("tp:playerUrl", this.canonical); this.mediaIndex = 0; this.videoType = this.FilterVideoType(this.videoType); if (this.videoType == "live") { $pdk.NBCplayer.LiveVideoStreamStatus = "unknown"; } this.mediaArray = $pdk.NBCplayer.DataStoreModule.GetMediaUrls(datal); this.feedId = $pdk.NBCplayer.feedId; this.feedTitle = this.feedData.title; this.playerType = "Offsite Embedded"; if (this.associatedPlaylist) { this.associatedFeedId = this.GetAssociatedFeedId(this.associatedPlaylist); this.lastGoodAssociatedFeedId = this.associatedFeedId; } else { this.associatedFeedId = ""; } this.date = this.FormatDate(this.date); this.sourceAndDate = this.source + " " + this.date; $pdk.NBCplayer.DebugLog(":::::VideoDataLoaded ", this); this.setReportData(datal); }, FormatDate: function (date) { return moment(date).zone("-05:00").format("MM/DD/YY"); }, FilterVideoType: function (type) { if (type.toLowerCase() == "non broadcast live video") { type= "live"; } return type; }, ParseQuotes: function (text) { text = text.replace(/^\x27(?=[!\x22#\$\%\x27()*+,\-.\/:;<=>?\@\[\\]\^_`{|}~]\B)/g, "‘"); text = text.replace(/^\x22(?=[!\x22#\$\%\x27()*+,\-.\/:;<=>?\@\[\\]\^_`{|}~]\B)/g, "“"); text = text.replace(/^\x22(?=\w)/g, "“"); text = text.replace(/^\x27(?=\w)/g, "‘"); text = text.replace(/\x22\x27(?=\w)/g, "“‘"); text = text.replace(/\x27\x22(?=\w)/g, "‘“"); text = text.replace(/\x27(?=\d{2}s)/g, "’") text = text.replace(/(>|\t|\n|\s| |--|&[mn]dash;|&\#8211;|&\#8212;|&\#x201[34];)\x27(?=\w)/g, "$1‘"); text = text.replace(/([^<>\\ \t\r\n\[\{\(\-])\x27(?=\s | s\b)/g, "$1’"); text = text.replace(/\x27/g, "’"); text = text.replace(/(>|\t|\n|\s| |--|&[mn]dash;|&\#8211;|&\#8212;|&\#x201[34];)\x22(?=\w)/g, "$1“"); text = text.replace(/([^<>\\ \t\r\n\[\{\(\-])\x22(?=\s | s\b)/g, "$1”"); text = text.replace(/\x22/ig, "”"); text.replace(/\.\.\./g, "…").replace (/\.\s\.\s\./g, "…"); return text; }, ConvertToFixedAims: function (imgsrc) { if (imgsrc.indexOf('/snappy/') < 1 && imgsrc.indexOf('/vocativ/') < 1) { imgsrc = imgsrc.toLowerCase().replace('.jpg', '.video_320x180.jpg').replace('/i/', '/j/'); } if (imgsrc.indexOf('/vocativ/') > 0) { var vocativThumbs = this.currentItem.media$thumbnails; for (i = 0;i < vocativThumbs.length;i++) { if (vocativThumbs[i].plfile$height == "315") { imgsrc = vocativThumbs[i].plfile$url; } } } return imgsrc; } }; //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ var VPNBCPlaylistModuleFLEX = function () { this.version = "6/03/2013 1t"; this.playlistData = {}; this.FlexApi = {}; this.id = "default"; this.updateMetaOnMove = false; this.divId = 0; this.defaultImageWidth = 170; this.defaultImageHeight = 90; this.mobileImgBuffer = []; this.isBuffered = false; var ctx = this; this.entryClickMethod = function (entry) { // Default MainPlaylist var release = new Object(); release.URL = entry.uri; entry.playlistType = "main"; $pdk.NBCplayer.DebugLog('level:3', '::::: mainPlayList Click - ad = ', $pdk.NBCplayer.FreeWheelModule.adIsRunning); //$(this)[0].FlexApi.flexAnimate($(entry).index()); if (!$pdk.NBCplayer.FreeWheelModule.adIsRunning) { var slideIndex = $(entry).index(); var total = this.FlexApi.count; if ((slideIndex + 1) < total) { this.MoveToSlide(slideIndex + 1); } this.SetStatusLabel(slideIndex); $pdk.controller.dispatchEvent('NBCplayerPlaylistClick', entry); $pdk.NBCplayer.PlayVideo(entry.guid); } }; this.InsertPlaylist = function (pconfig) { pconfig.context = this; this.divId = pconfig.id; this.CreatePlaylistContainer(pconfig); this.RenderData(pconfig); this.StartFlexSlider(pconfig); }; this.MoveToSlide = function (pos) { this.FlexApi.flexAnimate(pos); this.RenderPlayListPosition(); }; this.NextSlide = function () { this.FlexApi.flexslider('next'); this.RenderPlayListPosition(); }, this.PrevSlide = function () { this.FlexApi.flexslider('prev'); this.RenderPlayListPosition(); }, this.CreatePlaylistContainer = function (config) { var playlistHtml = '
'; if (config.parentDiv) { config.parentDiv.after(playlistHtml); } else { $('.tpContainer .tpLayout').append(playlistHtml); } }; this.InsertControls = function (id) { var context = this; $("#" + id).append('
'); context.posInfoDiv = $('#' + id + ' .playlistControls .positionInfo'); $("#" + id + ' .playlistControls .prevNav').click(function () { context.PrevSlide(); }) $("#" + id + ' .playlistControls .nextNav').click(function () { context.NextSlide(); }) }, this.RenderPlayListPosition = function () { var visibleStart = this.FlexApi.currentSlide + 1; var visibleEnd = visibleStart + this.FlexApi.visible - 1; var total = this.FlexApi.count; var posInfo; if (visibleEnd > 1) { posInfo = visibleStart + "-" + visibleEnd + " of " + total; } else { posInfo = visibleStart + " of " + total; } this.posInfoDiv.html(posInfo); if (this.updateMetaOnMove) { $pdk.NBCplayer.DataStoreModule.SetVideoData($pdk.NBCplayer.DataStoreModule.feedData.entries[this.FlexApi.currentSlide]); $pdk.NBCplayer.UpdateMetaData(); } }, this.SetStatusLabel = function (index) { if (this.id == "default") { $('#' + this.divId + ' .playlistholder').find('.statusText').hide(); var nowPlayling = $('#' + this.divId + ' .playlistholder .statusText:eq(' + index + ')'); var nextindex = index + 1; var upNext = $('#' + this.divId + ' .playlistholder .statusText:eq(' + nextindex + ')'); nowPlayling.html('now playing'); nowPlayling.show(); upNext.html('up next'); upNext.show(); } }, this.FadeOutPlaylist = function () { if (this.id == "default") { $('#' + this.divId + ' .playlistholder').fadeTo("slow", .3); $('#' + this.divId + ' .playlistControls').fadeTo("slow", .3); } }, this.FadeInPlaylist = function () { if (this.id == "default") { $('#' + this.divId + ' .playlistholder').fadeTo("slow", 1); $('#' + this.divId + ' .playlistControls').fadeTo("slow", 1); } }, this.RenderData = function (config) { this.playlistData.title = config.data.title; this.playlistData.start = 0; this.playlistData.displayCount = config.data.entries.length; this.playlistData.length = config.data.entries.length; if (this.playlistData.length > 42) { if ($pdk.NBCplayer.debug) {console.error('Feed exceeds 42 items. Truncating.'); } this.playlistData.length = 42; this.playlistData.displayCount = 42; } this.playlistData.entries = config.data.entries; this.playlistData.feedid = config.data.feedid; this.currentFeed = []; if (!config.imgWidth) { config.imgWidth = this.defaultImageWidth; } if (!config.imgHeight) { config.imgHeight = this.defaultImageHeight; } var entryholder = $('#' + config.id + ' .playlistholder')[0]; entryholder.innerHTML = ""; var len = 0; var context = this; for (var ipl = this.playlistData.start; ipl < this.playlistData.displayCount; ipl++) { var plItem = context.GeneratePlItem(this.playlistData.entries[ipl], { index: ipl, feedid: this.playlistData.feedid, imgWidth: config.imgWidth, imgHeight: config.imgHeight }); if (plItem) { plItem.num = len++; entryholder.appendChild(plItem); this.currentFeed[plItem.num] = plItem; } else { } } this.playlistData.displayCount = len; this.playlistData.length = len; entryholder.playlistData = this.playlistData; //entryholder.style.width = (this.playlistData.displayCount * 150) + "px"; }; this.GeneratePlItem = function (plEntry, config) { var entry = document.createElement("li"); entry.uri = ""; var dataMatrix = [ ["source", ["nnd$source"], "msnbc"], ["date", ["pubDate"], 1], ["canonical", ["nnd$canonicalUrl", "href"], "http://www.msnbc.com/"], ["erelease", ["media$content"], ""], ["entryHead", ["title"], ""], ["associatedPlaylist", ["nnd$associatedPlaylist", "href"], "http://feed.theplatform.com/f/2E2eJC/nnd_18424721"], ["guid", ["guid"], "corrupted_video"], ["tThumb", ["plmedia$defaultThumbnailUrl"], "http://media2.s-nbcnews.com/i/msnbc/Components/Video/_Player/configurations/ni.jpg"], ["videoType",["nnd$videoType"],"broadcast"] ]; $pdk.NBCplayer.DataStoreModule.PopulateFromData(plEntry, entry, dataMatrix); entry.videoType = $pdk.NBCplayer.DataStoreModule.FilterVideoType(entry.videoType) entry.date = $pdk.NBCplayer.DataStoreModule.FormatDate(entry.date); entry.feedid = config.feedid; entry.associatedPlayList = $pdk.NBCplayer.DataStoreModule.GetAssociatedFeedId(entry.associatedPlaylist); if (entry.erelease && entry.erelease[0] && entry.erelease[0]["plfile$url"]) { entry.uri = entry.erelease[0]["plfile$url"].substr(0, entry.erelease[0]["plfile$url"].indexOf("?")); } else { entry.uri = ""; } context = this; entry.onclick = function () { ctx.entryClickMethod(entry); }; entry.className = "playlistItem"; var imgElement = document.createElement("img"); if ($pdk.NBCplayer.inMobileRestState) { if (entry.videoType == "live" && $pdk.NBCplayer.DataStoreModule.LiveVideoStatusUrl) { entry.tThumb = $pdk.NBCplayer.DataStoreModule.LiveVideoStatusUrl; config.noPlayButton = true; } this.mobileImgBuffer[config.index] = entry.tThumb; entry.tThumb = this.mobileImgBuffer[0]; this.isBuffered = true; } if (!entry.tThumb) { return ""; } var imgsrc = entry.tThumb; var tThumbContainer = this.createThumbContainer(entry, config); entry.appendChild(tThumbContainer); var tDoc = document.createElement("div"); tDoc.title = this.limitText(entry.entryHead, 45, true); tDoc.className = "shortTitle"; tDoc.innerHTML = $pdk.NBCplayer.DataStoreModule.ParseQuotes(entry.entryHead); tDoc.style.overflow = "hidden"; entry.appendChild(tDoc); return entry; }; this.limitText = function (text, limit, elipse) { if (text && text.length > limit) { text = text.substr(0, limit) + ((elipse) ? "..." : ""); } return text; }, this.createThumbContainer = function (entry, config) { var tThumbContainer = document.createElement("div"); tThumbContainer.className = "thumbContainer"; var tNext = document.createElement("div"); var tPlay = document.createElement("div"); tPlay.className = "playArrow"; if (config.noPlayButton) { tPlay.style.display = "none"; } var sGraphic = document.createElement("span"); sGraphic.className = "sprite-graphic"; tPlay.appendChild(sGraphic); tThumbContainer.appendChild(tPlay); tNext.className = "statusText"; tNext.innerHTML = ""; tThumbContainer.appendChild(tNext); if (entry.videoType == "live") { tNext.style.display = "none"; var livePad = document.createElement("div"); livePad.className = "liveVideoStatusPadding"; livePad.innerHTML = ""; tThumbContainer.appendChild(livePad); } var tSourceDate = document.createElement("div"); tSourceDate.className = "sourceDate"; var tSource = document.createElement("div"); tSource.className = "source"; tSource.innerHTML = this.limitText(entry.source, 18) + " - "; tSourceDate.appendChild(tSource); var tDate = document.createElement("div"); tDate.className = "date"; tDate.innerHTML = entry.date; tSourceDate.appendChild(tDate); tThumbContainer.appendChild(tSourceDate); var tFigure = document.createElement("div"); tFigure.className = "image"; var thumbImage = new $pdk.NBCplayer.AimsImager(tFigure); if ($pdk.NBCplayer.displayMode != "mobile" && $pdk.NBCplayer.playerFlavor == "FeaturePlayer") { var imgElement = document.createElement("img"); imgsrc = $pdk.NBCplayer.DataStoreModule.ConvertToFixedAims(entry.tThumb); imgElement.src = imgsrc; tFigure.appendChild(imgElement); } else { thumbImage.create(entry.tThumb, config.imgWidth, config.imgHeight); } tThumbContainer.appendChild(tFigure); return tThumbContainer; } this.StartFlexSlider = function (config) { var playlistItem = "playlistItem"; if (!config.startAt) { config.startAt = 0; } if (!config.itemWidth) { config.itemWidth = this.defaultImageWidth; } setTimeout(function () { $('#' + config.id).flexslider({ animation: "slide", animationLoop: false, move: 1, startAt: config.startAt, selector: ".playlistholder > ." + playlistItem, itemWidth: config.itemWidth, itemMargin: 30, minItems: 1, maxItems: 6, slideshowSpeed: 5000, animationDuration: 200, controlNav: false, directionNav: false, slideshow: false, initDelay: 0, after: function () { config.context.RenderPlayListPosition(); } }); var ref = $("#" + config.id).data(); config.context.ref = ref; config.context.FlexApi = ref.flexslider; $pdk.NBCplayer[config.id] = ref.flexslider; // flexslider forces the element to the bottom. arg.. config.context.InsertControls(config.id); config.context.RenderPlayListPosition(config.id); config.context.SetStatusLabel(0); //console.log('$pdk.NBCplayer.'+config.id+' :: created.'); config.callback(ref.flexslider); }, 0); }; this.Hide = function () { this.ref.hide(); }; this.Show = function () { this.ref.show(); }; this.getGridSize = function (id) { //320px,768px,1024px,1230px var cWidth = $('#' + id).width(); gsize = (cWidth < 300) ? 2 : (cWidth < 590) ? 3 : 4; //console.log('getGridSize::',cWidth,gsize); return gsize; }; }; //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ var VPNBCFreeWheelModule = { version: "5/6/2013 1c", adContainer300x250: null, adContainer300x60: null, adIsRunning: false, Init: function () { if ($pdk.NBCplayer.adCompanions) { this.CreateAdContainers(); } //console.log('VPNBCFreeWheel Module Initiazed.'); }, CreateAdContainers: function () { this.fw300x250adHTML = '
advertisement
'; this.fw300x60adHTML = '
advertisement
'; $pdk.NBCplayer.GetMainContainer(); var playerContainer = $pdk.NBCplayer.mainPlayerDiv; if (playerContainer.length < 1) { console.error('AdContainers:: Main container not found!'); } playerContainer.after('
' + this.fw300x60adHTML + '
'); playerContainer.after('
' + this.fw300x250adHTML + '
'); this.adContainer300x60 = $('#' + $pdk.NBCplayer.playerDivContainers.ad300x60); this.adContainer300x250 = $('#' + $pdk.NBCplayer.playerDivContainers.ad300x250); if ($pdk.NBCplayer.playerMode == "show") { this.adContainer300x60.addClass('showPlayer'); this.adContainer300x250.addClass('showPlayer'); } if (this.adContainer300x60.length > 0) { this.adContainer300x60.hide(); this.adContainer300x250.hide(); } }, reassign300x60: function (child) { try { if (!child) { child = "TPVideoPlayerPlaylistTitle"; } var tpva3x6 = document.getElementById("TPVideoPlayerAd300x60"); var tpvppt = document.getElementById(child); var tpparent = tpvppt.parentNode; tpparent.appendChild(tpva3x6); } catch (e) { } }, setAdPosition: function (mode) { //console.log('setAdPositon:: ',mode); switch (mode) { case "mobile": if (this.adContainer300x250) { this.adContainer300x250.hide(); } if (this.adContainer300x60) { this.adContainer300x60.hide(); } //$('#TPVideoPlayerAd300x60').prependTo('#TPVideoPlayerMeta'); break; case "tablet": this.reassign300x60(); break; case "tablet-landscape": this.reassign300x60(); break; default: this.reassign300x60("TPVideoMainPlaylist"); //$('#TPVideoPlayerAd300x60').insertAfter('#TPVideoMainPlaylist'); break; } }, AdListener: function (e) { if (e.evt == "AdStart") { //console.error('AdStart'); this.adIsRunning = true; //this.FadeIn300x250(); //this.FadeOut300x60(); } if (e.evt == "AdComplete") { //console.error('ad complete'); this.adIsRunning = false; //this.FadeOut300x250(); //this.FadeIn300x60(); } }, Hide300x250: function () { if (this.adContainer300x250.length > 0) { this.adContainer300x250.hide(); } }, Hide300x60: function () { if (this.adContainer300x60.length > 0) { this.adContainer300x60.hide(); } }, FadeIn300x250: function () { if (this.adContainer300x250.length > 0) { //console.error('FadeIn300x250'); this.adContainer300x250.css('opacity', 0); this.adContainer300x250.show(); this.adContainer300x250.fadeTo(2000, 1); } }, FadeOut300x250: function () { var context = this; if (this.adContainer300x250.length > 0) { //console.error('FadeOut300x250'); context.adContainer300x250.fadeTo("slow", 0, function () { $(this).hide(); context.adContainer300x250.html(context.fw300x250adHTML); }); } }, FadeIn300x60: function () { if ($pdk.NBCplayer.displayMode != "mobile") { if (this.adContainer300x60.length > 0) { //console.error('FadeIn300x60'); this.adContainer300x60.css('opacity', 0); this.adContainer300x250.show(); this.adContainer300x60.fadeTo(2000, 1); } } }, FadeOut300x60: function () { if (this.adContainer300x60.length > 0) { //console.error('FadeOut300x60'); this.adContainer300x60.fadeTo("slow", 0, function () { $(this).hide(); }); } }, FreeWheelEvents: function (e) { //console.log('FreewheelEvent: ',e); }, OnAdClickEvent: function (e) { //console.log('OnAdClickEvent',e); } }; //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ var AimsSizes = { "16x9": { id: "16x9", wRatio: (9 / 16), hRatio: (16 / 9), aimssizes: [{ id: "video_115x65", width: 115, height: 65 }, { id: "video_200x113", width: 200, height: 113 }, { id: "video_320x180", width: 320, height: 180 }, { id: "video_560x315", width: 560, height: 315}] }, "3x4": { id: "3x4", wRatio: (3 / 4), hRatio: (4 / 3), aimssizes: [{ id: "video-260x195", width: 260, height: 195 }, { id: "video_640x480", width: 640, height: 480 }, { id: "video_1280x960", width: 1280, height: 960}] }, "thumb": { id: "thumb", wRatio: (3 / 4), hRatio: (4 / 3), aimssizes: [{ id: "thumb-m", width: 92, height: 69}] } }; var VPMSNBCAimsImager = function (owner) { this.image = ""; this.expectedType = "16x9"; this.responsive = false; this.fillToOwner = true; this.resizeOwner = false; this.create = function (src, w, h) { this.image = document.createElement("img"); var obj = this.getBestFit(w, h); obj.src = src; obj.id = this.aimsByWidth(obj.width); this.sizeImage(obj); owner.appendChild(this.image); if (this.responsive) { var currentResizeMethods = window.onresize; var resizeContext = this; window.onresize = function (e) { resizeContext.resize(); if (currentResizeMethods) { currentResizeMethods(e); } } } }; this.resizeMethod = function (obj) { }; var context = this; this.resize = function () { if (!this.inresize) { this.inresize = true; var width = owner.clientWidth; var height = owner.clientHeight; if (!this.fillToOwner) { var width = $pdk.NBCplayer.playerWidth(); //(window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth); var height = $pdk.NBCplayer.playerHeight(); //(window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight); \ } var obj = this.getBestFit(width, height); obj.id = this.aimsByWidth(obj.width); this.preSizeImage(); this.sizeImage(obj); if (this.resizeOwner) { owner.style.width = obj.width; owner.style.height = obj.height; } this.resizeMethod(obj); setTimeout(function () { context.inresize = false; }, 100); } }; this.sizeImage = function (obj) { var replaceText; if (!obj.src) { replaceText = this.image.src; } else { replaceText = obj.src; } // supperfast snapy quick fix -- need to rewrite var origImage = replaceText; var preText = replaceText.substr(replaceText.lastIndexOf("/")); var postText = preText.substr(preText.indexOf(".")); replaceText = replaceText.replace(postText, "." + obj.id + ".jpg"); replaceText = replaceText.replace(/\/i\//, "\/j\/"); testNonAims = $pdk.NBCplayer.DataStoreModule.ConvertToFixedAims(origImage); if (testNonAims == origImage) { replaceText = origImage; } if (testNonAims.indexOf('/vocativ/') > 0) { replaceText = testNonAims; } this.image.src = replaceText; this.image.width = obj.width; this.image.height = obj.height; if (this.resizeOwner) { owner.style.width = obj.width; owner.style.height = obj.height; } this.resizeMethod(obj); }; this.preSizeImage = function () { this.image.width = 10; this.image.height = 10; if (this.resizeOwner) { owner.style.width = 10; owner.style.height = 10; } }; this.getBestFit = function (width, height) { var ratio = this.getRatio(); var rObj = { height: height, width: width }; if (ratio.hRatio > ratio.wRatio) { rObj.height = Math.round(width * ratio.wRatio); } else { rObj.width = Math.round(height * ratio.hRatio); } if (rObj.width > width) { rObj.width = width; rObj.height = Math.round(width * ratio.wRatio); } if (rObj.height > height) { rObj.height = height; rObj.width = Math.round(height * ratio.hRatio); } return rObj; }; this.getRatio = function () { return (AimsSizes[this.expectedType]) ? AimsSizes[this.expectedType] : AimsSizes["16x9"]; }; this.aimsByWidth = function (width) { var aimz = this.getRatio().aimssizes; for (var i in aimz) { if (aimz[i].width > width) { return aimz[i].id; break; } } return aimz[aimz.length - 1].id; }; }; var VPNBCShowPlayerTaxonomyModule = { version: "5/28/2013 1t", feedList: [], renderTaxonomyList: function () { if ($pdk.NBCplayer.showSource) { this.RequestList($pdk.NBCplayer.showSource); } else { if ($pdk.NBCplayer.debug) {console.error('no source specified using default'); } this.RequestList('test'); } //showLists.hide(); }, RequestList: function (sourceName) { //var urlList = "http://www.nbcnews.com/id/52024383&callback=$pdk.NBCplayer.ShowPlayerTaxonomy.GetList"; var urlList = "http://data.nbcnews.com/VideoRendering/PlaylistTemplate/" + sourceName + "?jsoncallback=$pdk.NBCplayer.ShowPlayerTaxonomy.GetList"; if ($pdk.NBCplayer.debug) { urlList += "&cb=" + Math.floor(Math.random() * 80003); } $pdk.NBCplayer.DebugLog(':::::Requesting Taxonomy from ', urlList); $.ajax({ type: "GET", url: urlList, async: false, cache: true, dataType: "script", crossDomain: true, error: function (xhr, textStatus, errorThrown) { $pdk.controller.dispatchEvent('NBCplayerOnFeedError', errorThrown); //alert(errorThrown); } }); }, GetList: function (data) { //console.log('GetList:: '); //console.log(data); var showListDiv = $('#' + $pdk.NBCplayer.playerDivContainers.showPlaylists); if (showListDiv.length < 1) { //console.log('Mode is show and no playlistcontainer - creating it'); $('body').prepend('
'); showListDiv = $('#' + $pdk.NBCplayer.playerDivContainers.showPlaylists); } $('#TPVideoPlaylistTaxonomyContainer').after(''); var mobileShowList = $('#mobileTaxonomy'); var oneItem = '
Name
'; var mobileOneItem = '' showListDiv.html(''); //var firstline = "
"; //showListDiv.append(firstline); var itemSelected = 0; var itemindex = 0; if (data.playlistTaxonomy) { for (var i = 0; i < data.playlistTaxonomy.length; i++) { iType = data.playlistTaxonomy[i].type; switch (iType) { case "item": menuName = data.playlistTaxonomy[i].reference.name; feedId = data.playlistTaxonomy[i].reference.feed; this.feedList[itemindex] = feedId; itemClass = data.playlistTaxonomy[i].reference.id; newItem = oneItem.replace('Name', menuName).replace('FeedId', feedId); mobileNewItem = mobileOneItem.replace('Name', menuName).replace('FeedId', feedId); showListDiv.append(newItem); mobileShowList.append(mobileNewItem); $('#TPVideoPlaylistTaxonomyContainer .' + feedId).parent().parent().bind('click', function (e) { // Triggers select box. Keeping div menu for legacy purposes $('#mobileTaxonomy').val($(this).find('div')[1].className).change(); $('#TPVideoPlaylistTaxonomyContainer .showTaxListItem').removeClass('selected'); $(this).addClass('selected'); }); if (itemSelected == itemindex) { $('#TPVideoPlaylistTaxonomyContainer .' + feedId).parent().parent().addClass('selected'); } itemindex++; break; } } $('#mobileTaxonomy').bind('change', function (e) { pid = $("select option:selected").attr('value'); $pdk.NBCplayer.LoadNewFeed(pid); }); } else { //console.error('unable to load playlistTaxonomy'); } //console.log('sourceFeed ',this.feedList[0]); $pdk.NBCplayer.SetVideoHeight(); $pdk.NBCplayer.SetFeedURL(this.feedList[0]); $pdk.NBCplayer.GetPlayerData(); } }; //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ var VPNBCReportModule = { report0: true, reportAd0: true, report25: true, report50: true, report75: true, report999: true, reportStart: true, reportEnd: true, reportAdStart: true, reportAdEnd: true, currentTime: 0, cc: false, fullscreen: false, Init: function () { }, report: function (evtObj) { evtObj.fullscreen = this.fullscreen; evtObj.closedCaption = this.cc; evtObj.duration=this.duration; evtObj.canonoical = $pdk.NBCplayer.DataStoreModule.canonical; $pdk.controller.dispatchEvent("NBCplayerReport", evtObj); }, reportOnStart: function (adRunning) { // var eventData = { reportType: (adRunning) ? "videoAdStart" : "videoStart", // time: 0 // } // this.report(eventData); }, reportOnEnd: function (adRunning) { adIsRunning=$pdk.NBCplayer.isCurrentlyAd; if (adIsRunning){return;} var eventData = { reportType: (adRunning) ? "videoAdEnd" : "videoEnd", time: this.currentTime } this.report(eventData); }, reportPause: function (adRunning) { adIsRunning=$pdk.NBCplayer.isCurrentlyAd; var eventData = { reportType: (adRunning) ? "videoAdPause" : "videoPause", time: this.currentTime } this.report(eventData); }, playerError: function (eType, eMsg) { var eventData = { reportType: "playerError", errorType: eType, errorMsg: eMsg, time: this.currentTime } this.report(eventData); }, reportScrub: function () { var eventData = { reportType: "videoScrub", time: this.currentTime } this.report(eventData); }, reportOnTime: function (e, adIsRunning) { adIsRunning=$pdk.NBCplayer.isCurrentlyAd; try { var context = this; var percent = e.data.percentComplete; context.currentTime = e.data.currentTime; context.duration=e.data.duration; var eventData = { time: context.currentTime }; if ($pdk.NBCplayer.DataStoreModule.videoType == "live" && !adIsRunning) { percent = 0.1; } switch (true) { case (!adIsRunning) && context.report999 && (percent > 99.8): context.report999 = false; eventData.reportType = "video100Complete"; context.report(eventData); break; case (adIsRunning) && context.reportAdEnd && (percent > 90): context.reportAdEnd = false; eventData.reportType = "videoAdEnd"; setTimeout(function(){$pdk.NBCplayer.isCurrentlyAd=false;},3000); context.report(eventData); break; case (!adIsRunning) && context.report75 && (percent > 74): context.report75 = false; eventData.reportType = "video75Complete"; context.report(eventData); break; case (!adIsRunning) && context.report50 && (percent > 49): context.report50 = false; eventData.reportType = "video50Complete"; context.report(eventData); break; case (!adIsRunning) && context.report25 && (percent > 24): context.report25 = false; eventData.reportType = "video25Complete"; context.report(eventData); break; case (percent > 0): if (!adIsRunning) { if (context.report0) { context.report0 = false; var eventData = { reportType: "videoStart", time: 0 } context.report(eventData); } } else { if (context.reportAd0) { context.reportAd0 = false; var eventData = { reportType: "videoAdStart", time: 0 } context.report(eventData); } } break; } } catch (err) { // nothing } }, setFullscreen: function () { this.fullscreen = !this.fullscreen; }, setCC: function () { this.cc = !this.cc; }, reset: function () { this.report0 = true; this.reportAd0 = true; this.report25 = true; this.report50 = true; this.report75 = true; this.report999 = true; this.reportStart = true; this.reportEnd = true; this.reportAdStart = true; this.reportAdEnd = true; this.currentTime = 0; } }; var VPNBChashCheck = { change: 0, original: ";", grabHash: function () { var z = location.hash; if (z != this.original && z != "#") { var asplit=z.split("-"); z=asplit[0]; var wdth=asplit[1]; if (z){ console.log(z); } if (z == "#resetvideo") { location.hash = "#"; setTimeout(function(){ $pdk.NBCplayer.SetVideoHeight(wdth); $pdk.controller.pause(true); },100); } else{ if (wdth) { if (!isNaN(parseInt(wdth,10))){ $pdk.NBCplayer.SetVideoHeight(parseInt(wdth,10)); } } } if (z == "#pause") { $pdk.controller.pause(true); location.hash = "#"; } if (z == "#play") { $pdk.controller.pause(false); location.hash = "#"; } if (z == "#embed") { $pdk.controller.pause(true); location.hash = "#"; } } var context = this; setTimeout(function () { context.grabHash(); }, 200); } }; var VPNBCmessaging = { loading: {}, loadItem: {}, loadingOnMessage: { restStateRendered: false, startPlayback: true }, loadImage: "http://media4.s-nbcnews.com/i/MSNBC/Components/Video/_Player/configurations/thePlatform/assets/pinwheel4.gif", init: function (render) { this.loadItem = document.createElement("div"); var imgdiv = document.createElement("div"); var img = document.createElement("img"); img.width = 128; img.height = 40; imgdiv.style.width = "128px"; imgdiv.style.height = "40px"; imgdiv.style.top = "50%"; img.src = this.loadImage; imgdiv.style.margin = "auto"; imgdiv.style.position = "relative"; imgdiv.appendChild(img); this.loadItem.appendChild(imgdiv); this.loadItem.style.position = "absolute"; this.loadItem.style.top = "0px"; this.loadItem.style.left = "0px"; this.loadItem.style.width = "100%"; this.loadItem.style.height = "100%"; this.loadItem.style.zIndex = "999999"; this.loadItem.style.background = "black"; this.loadItem.setAttribute("id","TPVideoPlayerLoading"); render.appendChild(this.loadItem); }, reassign: function (owner) { try{ owner.appendChild(this.loadItem); } catch(errrrr){ } }, loadInactive: function () { if (this.loadItem && this.loadItem.style){ this.loadItem.style.display = "none"; } }, loadActive: function () { if (this.loadItem && this.loadItem.style){ this.loadItem.style.display = "block"; } }, Message: function (m) { if (this.loadingOnMessage[m]) { this.loadActive() } else { this.loadInactive(); } } } var VPNBCccSupport = { init: function () { $('#TPVideoPlayerContainer .tpContainer').after(this.ui()); }, onPDKInitiazed: function () { $pdk.controller.addPlayerCard("forms", "tpSubtitleStylesCard", document.getElementById("tpSubtitleStylesCard").outerHTML, "urn:theplatform:pdk:area:player", {title: 'CC Settings', instructions: "Edit your caption styles below", apply: 'Apply', close: 'Close'}, $pdk.NBCplayer.CCSupport.presenter, 100); }, onCCPreview: function(release) { var durationCheck = (isNaN(release.duration)) ? -1 : release.duration; if (durationCheck < 1) { return true; } if (release.captions.length > 0) { return true; } else { return false; } }, onCCMedia: function(clip) { var durationCheck = (isNaN(clip.baseClip.duration)) ? -1 : clip.baseClip.duration; if (durationCheck < 1) { return true; } if (clip.baseClip.availableSubtitles.length > 0) { return true; } else { return false; } }, setReleaseCall: function () { var val = document.getElementById('url').value; $pdk.controller.setReleaseURL(val); }, presenter: { show: function(initVars) { var me = this; this.card = initVars.card; this.initVars = initVars; if (!this.controller) { this.controller = initVars.controller; if (!this.loadedLanguage || !this.loadStyles) { this.card.style.display = "none"; } this.listeners = {}; } $pdk.jQuery(this.card).find(".tpFormActions .tpButton").click(function() { me.apply(); }) $pdk.jQuery(this.card).find(".tpFontColor").click(function(e) { $pdk.jQuery(me.card).find(".tpFontColor").css('border-color', ''); $pdk.jQuery(e.target).css('border-color', "#FFFFFF"); var color; try { color = me.colorToHex($pdk.jQuery(this).css('background-color'));//.attr('style').split(": ")[1]; } catch (e) { color = ""; } $pdk.jQuery(me.card).find("#fontColor").val(color); } ); $pdk.jQuery(this.card).find(".tpFontBackgroundColor").click(function(e) { $pdk.jQuery(me.card).find(".tpFontBackgroundColor").css('border-color', ''); $pdk.jQuery(e.target).css('border-color', "#FFFFFF"); var color = $pdk.jQuery(this).css('background-color'); if (color == "rgba(0, 0, 0, 0)") { color = null; } else { color = me.colorToHex(color); } $pdk.jQuery(me.card).find("#backgroundColor").val(color); } ); $pdk.jQuery(this.card).find(".tpFontEdgeColor").click(function(e) { $pdk.jQuery(me.card).find(".tpFontEdgeColor").css('border-color', ''); $pdk.jQuery(e.target).css('border-color', "#FFFFFF"); var color = me.colorToHex($pdk.jQuery(this).css('background-color')); $pdk.jQuery(me.card).find("#fontEdgeColor").val(color); } ); if (!this.listeners.lang) { initVars.controller.addEventListener("OnGetSubtitleLanguage", this.listeners.lang = function (e) { me.loadLanguage(e) }); initVars.controller.addEventListener("OnGetSubtitleStyle", this.listeners.style = function (e) { me.loadStyles(e) }); } // initVars.controller.addEventListener("OnSubtitleCuePoint", this.listeners.cue = function(e) { me.cuePoint(e) }); this.loadedStyles = false; this.loadedLanguage = false; $pdk.controller.getSubtitleStyle(); $pdk.controller.getSubtitleLanguage(); }, hide: function() { initVars.controller.removeEventListener("OnGetSubtitleLanguage", this.listeners.lang); initVars.controller.removeEventListener("OnGetSubtitleStyle", this.listeners.style); // $pdk.controller.removeEventListener("OnSubtitleCuePoint", this.listeners.cue); }, colorToHex: function(color) { if (!color) return; if (color.substr(0, 1) === '#') { return color; } var digits = /(.*?)rgb\((\d+), (\d+), (\d+)\)/.exec(color); if (!digits) { digits = /(.*?)rgba\((\d+), (\d+), (\d+), (\d+)\)/.exec(color); } if (!digits || digits.length < 5) return; var red = parseInt(digits[2]); var green = parseInt(digits[3]); var blue = parseInt(digits[4]); var rgb = blue | (green << 8) | (red << 16); return "#" + (0x1000000 | rgb).toString(16).substring(1); // return digits[1] + '#' + rgb.toString(16); }, loadStyles: function(e) { if (e.data) { this.loadedStyles = true; if (e.data.fontSize == 0 || isNaN(e.data.fontSize)) { $pdk.jQuery(this.card).find("#fontSize")[0].value = ""; } else { $pdk.jQuery(this.card).find("#fontSize")[0].value = (isNaN(e.data.fontSize) || e.data.fontSize == null ? "5" : e.data.fontSize); } $pdk.jQuery(this.card).find("#fontColor")[0].value = e.data.fontColor; $pdk.jQuery(this.card).find("#fontFamily")[0].value = (e.data.fontFamily ? e.data.fontFamily : ""); $pdk.jQuery(this.card).find("#fontEdge")[0].value = (e.data.fontEdge ? e.data.fontEdge : ""); $pdk.jQuery(this.card).find("#fontEdgeColor")[0].value = e.data.fontEdgeColor; $pdk.jQuery(this.card).find("#backgroundColor")[0].value = e.data.backgroundColor; $pdk.jQuery(this.card).find("#opacity")[0].value = (isNaN(e.data.opacity) || e.data.opacity == null ? "100" : e.data.opacity); $pdk.jQuery(this.card).find("#padding")[0].value = (isNaN(e.data.padding) || e.data.padding == null ? "0" : e.data.padding); $pdk.jQuery(this.card).find("#bold")[0].checked = Boolean(e.data.bold); $pdk.jQuery(this.card).find("#italic")[0].checked = Boolean(e.data.italic); $pdk.jQuery(this.card).find("#underline")[0].checked = Boolean(e.data.underline); $pdk.jQuery(this.card).find("#textAlign")[0].value =(e.data.textAlign ? e.data.textAlign : ""); $pdk.jQuery(this.card).find("#textAlignVertical")[0].value = (e.data.textAlignVertical ? e.data.textAlignVertical : ""); var me = this; var tiles = $pdk.jQuery(this.card).find('.tpFontColor'); var found = false; for (var i=0; i