// neu var o2YouTubeFrame = {}; (function(o2YouTubeFrame) { "use strict"; /*global vars*/ var youTubeObject = []; var configObject = { /*Class selectors always to there parent, parents are identified by id*/ iframeJsClass : ".js-youtube-iframe", relatedList: ".js-youtube-application", relatedClass: ".js-related-video", youTubeContent : { titleSelector: ".js-youtube-title" }, box:$('.lightbox-content') }; /*end global vars*/ function createYouTubeFrame(videoId){ /*create view object*/ this.view = new YouTubeFrame(videoId,configObject); this.view.youTubeItem = this.view.setYouTubeUrl(videoId); this.view.setBoxHeight(); this.view.getMainVideoInformation(); this.controller = new YouTubeReleatedEvent(this.view); this.controller.bindClickEvent(this.view.config.relatedList); } function YouTubeFrame(videoId,config){ this.config = config; this.videoId = videoId; this.youTubeItem = []; this.youTubeRelated = {}; var view = this; /* setYouTubeUrl creates Url for JSON Call * @para: Id from the YouTube Video */ this.setBoxHeight = function(){ var viewportHeight = $(window).height(); configObject.box.css("max-height",viewportHeight+"px"); }; this.setYouTubeUrl = function(youTubeId){ this.youTubeId = youTubeId; var urlPartBeforeId = "http://gdata.youtube.com/feeds/api/videos/"; var relatedOption = "/related"; var urlPartAfterId = "?v=2&alt=jsonc"; var youTubeEmbed = "http://www.youtube.com/embed/"; return { youTubeLink: urlPartBeforeId + this.youTubeId + urlPartAfterId, youTubeRelatedLink: urlPartBeforeId + this.youTubeId + relatedOption + urlPartAfterId, youTubeEmbedSrc: youTubeEmbed + this.youTubeId, youTubeVideoId: youTubeId }; }; /*getMainVideoInformation makes call to youtube to get further information of the video in current view *@para: in the current implementation the source come from the youTubeObject (return statement form setYouTubeUrl) */ this.getMainVideoInformation = function(){ var _self = this; $.support.cors = true; $.getJSON(this.youTubeItem.youTubeLink) .done(function( data ) { _self.buildMainVideoSource( _self.youTubeItem.youTubeVideoId, data.data.title); }); _self.getRelatedVideoInformation(_self.youTubeItem.youTubeRelatedLink); }; this.buildMainVideoSource = function( videoId,title ){ //var youTubeSource = source; $("[data-iframeSource='" + this.videoId + "']").find('param[name=movie]').attr("value","http://www.youtube.com/v/" + videoId +"?version=3&autoplay=0"); $("[data-iframeSource='" + this.videoId + "']").find('embed').attr("src","http://www.youtube.com/v/" + videoId +"?version=3&autoplay=0"); var value = $('.js-youtube-iframe').html(); $('.js-youtube-iframe').html(""); $('.js-youtube-iframe').html(value); }; this.getRelatedVideoInformation = function( relatedUrl ){ var _self = this; var temp=""; var counter = 0; // IE8 & 9 only Cross domain JSON GET request if ('XDomainRequest' in window && window.XDomainRequest !== null) { var xdr = new XDomainRequest(); // Use Microsoft XDR xdr.open('get', relatedUrl); xdr.onload = function () { var dom = new ActiveXObject('Microsoft.XMLDOM'), JSON = $.parseJSON(xdr.responseText); dom.async = false; if (JSON == null || typeof (JSON) == 'undefined') { JSON = $.parseJSON(data.firstChild.textContent); } var data = JSON; for( var item in data.data.items) { if(counter <= 2){ temp += "