/*-------------------------------------------------------------------------------- Youmax BIZ v2.6 by Jake H. from CodeHandling https://codecanyon.net/item/youmax-grow-your-youtube-and-vimeo-business/9989505 ---------------------------------------------------------------------------------*/ /*------------------------------------------------------------------ [Table of contents] 1. Youmax Settings 2. DOM Initialization 3. Options Initialization 4. Source Validation 5. Getters 5.1 Channel Details 5.2 Channel Playlists 5.3 Playlist Videos 5.4 Video Statistics 6. Setters 6.1 Video Objects 6.2 Playlist Objects 6.3 Statistic Setters 7. Display List 8. Video Display Mechanisms 8. Sorting Handlers 9. Tab Handlers 9. Animation Handler 10.Load More Handler 12.Youmax Display Handler 11.Resize Handler 12.Utility Functions 13.Youmax Main Function -------------------------------------------------------------------*/ var youmaxLoggedInUser = { name :null, id :null, picture :null, token :null, apiKey :null }; (function($) { "use strict"; var localSettings = { apiKey :"AIzaSyAlhAqP5RS7Gxwg_0r_rh9jOv_5WfaJgXw", channelLinkForHeader :"https://www.youtube.com/user/yogahousem", tabs:[ { name:"Uploads", type:"youtube-channel-uploads", link:"https://www.youtube.com/user/yogahousem" } ], maxResults :"10", videoDisplayMode :"popup", minimumViewsPerDayForTrendingVideos:"5", displayFirstVideoOnLoad :true, defaultSortOrder :"recent-first", youmaxDisplayMode :"grid", youmaxBackgroundColor :"#ECEFF1", itemBackgroundColor :"#fbfbfb", headerBackgroundColor :"rgb(0, 147, 165)", descriptionColor :"#686868", viewsColor :"#6f6f6f", controlsTextColor :"black", titleFontFamily :"Open Sans", generalFontFamily :"Roboto Condensed", offerBackgroundColor :"#fbfbfb", offerTextColor :"#686868", offerHighlightColor :"#FFC107", titleFontSize :"0.9", titleFontWeight :"normal", descriptionFontSize :"0.85", viewsDateFontSize :"0.75", baseFontSize :"16px", offerTitleFontSize :"1.3", offerDescriptionFontSize:"0.85", offerButtonFontSize :"1", responsiveBreakpoints :[600,900,1050,1600], gridThumbnailType :"full", dateFormat :"relative", loadMoreText :"  Show me more videos..", ctaText :"  Get me a consultation..", ctaLink :null, previousButtonText :"  Previous", nextButtonText :"Next  ", loadingText :"loading...", allDoneText :"  All done..", showFixedPlayIcon :false, iconShape :"circle", //circle|square showHoverAnimation :false, playlistNavigation :false, carouselMode :false, videoCache :[], aspectRatio :360/640, pageToken :null, nextPageToken :null, currentPageToken :null, previousPageToken :null, clearListOnDisplay :true, channelIdForSearch :null, searchFlag :false, allDoneFlag :false, previousTabId :null, popupAlignTop :true, }, init = function($youmaxPro) { var settings = $youmaxPro.data("settings"); var youmaxWrapperStart = "
" var youmaxWrapperEnd = "
" var listWrapperStart = "
"; var listWrapperEnd = "
"; var channelHeader = "
" var gridListSwitch = "
"; var listHeader = "
"+gridListSwitch+"
"; var inlineContainer = "
"; var playlistNavigationName = "
"; var listContainer = "

"; var loadMoreButton = "
"+settings.loadMoreText+"
"; var previousButton = "
"+settings.previousButtonText+"
"; var nextButton = "
"+settings.nextButtonText+"
"; var ctaButton = ""; var calloutContainer = "
"; var loadingMechanism = ""; if(settings.ctaLink!=null) { ctaButton = "
"+settings.ctaText+"
"; }/* else { $youmaxPro.addClass("yl-no-cta"); }*/ if(settings.loadingMechanism=="load-more") { loadingMechanism = loadMoreButton; } else { loadingMechanism = previousButton + nextButton; } $youmaxPro.empty().append(youmaxWrapperStart+channelHeader+listWrapperStart+listHeader+inlineContainer+playlistNavigationName+listContainer+loadingMechanism+ctaButton+calloutContainer+listWrapperEnd+youmaxWrapperEnd); showLoader($youmaxPro); }, doOptions = function($youmaxPro){ var customCSS = ""; var headerBackgroundColor,lightHeaderColor; var settings = $youmaxPro.data("settings"); var youmaxId = $youmaxPro.attr("id"); clearSettings($youmaxPro); settings.minimumViewsPerDayForTrendingVideos = parseInt(settings.minimumViewsPerDayForTrendingVideos,10); //set date format if(settings.dateFormat=="relative") { convertDate = convertToRelativeDate; } else if(settings.dateFormat=="specific") { convertDate = convertToSpecificDate; } //set view - grid|list|double-list handleYoumaxDisplay($youmaxPro); //Youmax Background Color customCSS += "#"+youmaxId+".youmax-pro {background-color: "+settings.youmaxBackgroundColor+";}"; customCSS += "#"+youmaxId+" .yl-load-more-button:hover {background: linear-gradient(to right,"+settings.youmaxBackgroundColor+","+settings.itemBackgroundColor+" 30%);}" //Item Background Color customCSS += "#"+youmaxId+" .yl-list-title select, #"+youmaxId+" .yl-item, #"+youmaxId+" .yl-load-more-button, #"+youmaxId+" .yl-previous-button, #"+youmaxId+" .yl-next-button {background-color: "+settings.itemBackgroundColor+";}" //Views Color customCSS += "#"+youmaxId+" .yl-view-bucket {color: "+settings.viewsColor+"; border-color: "+settings.viewsColor+";}"; customCSS += "#"+youmaxId+" .yl-date-bucket{color: "+settings.viewsColor+";}"; customCSS += "#"+youmaxId+" .yl-view-string{color: "+settings.viewsColor+";}"; customCSS += "#"+youmaxId+" .yl-selected-tab:after{background-color:"+settings.viewsColor+";}"; //Description Color customCSS += "#"+youmaxId+" .yl-description, #"+youmaxId+" .yl-item, #"+youmaxId+" .yl-loader, #"+youmaxId+" .yl-list-title {color:"+settings.descriptionColor+";}"; //Header Color customCSS += "#"+youmaxId+" .yl-view-bucket-seen {background-color: "+settings.headerBackgroundColor+";border-color: "+settings.headerBackgroundColor+"; color:white;}"; customCSS += "#"+youmaxId+" .yl-grid .yl-view-bucket-seen {color: "+settings.headerBackgroundColor+"; background-color:inherit;}"; customCSS += "#"+youmaxId+" .yl-loader {border-color: "+settings.headerBackgroundColor+";}"; customCSS += "#"+youmaxId+" .yl-load-more-button, #"+youmaxId+" .yl-previous-button {box-shadow: 0 0px 2px rgba(0, 0, 0, 0.2), -0.2em 0px 0px 0px "+settings.headerBackgroundColor+";}"; customCSS += "#"+youmaxId+" .yl-list-title select{box-shadow: 0 0px 2px rgba(0, 0, 0, 0.2), -0.2em 0px 0px 0px "+settings.headerBackgroundColor+";}"; customCSS += "#"+youmaxId+" .yl-header, #"+youmaxId+" .yl-cta-button, #"+youmaxId+" .yl-switch, #"+youmaxId+" .yl-showing-playlist-name{background-color:"+settings.headerBackgroundColor+"; color:"+settings.headerTextColor+";}"; customCSS += "#"+youmaxId+" .yl-description a, .yp-popup-description a, .yp-comment span {color: "+settings.headerBackgroundColor+";}"; customCSS += ".yp-share:hover, .yp-post-likes:hover, .yp-add-comment-button:hover {background-color: "+settings.headerBackgroundColor+"; box-shadow: 0px 0px 0px 1px "+settings.headerBackgroundColor+";}"; customCSS += "#"+youmaxId+" .yl-play-fill-color{background-color:"+settings.headerBackgroundColor+";}"; //Title Color customCSS += "#"+youmaxId+" .yl-title {color: "+settings.titleColor+";}"; //customCSS += ".yl-tab-container{box-shadow: -0.2em 0px 0px 0px "+settings.viewsColor+";}"; //Controld Text Color customCSS += "#"+youmaxId+" .yl-list-title select, #"+youmaxId+" .yl-load-more-button, #"+youmaxId+" .yl-previous-button, #"+youmaxId+" .yl-next-button {color:"+settings.controlsTextColor+";}"; //Tabs Color customCSS += "#"+youmaxId+" .yl-tab-container{color: "+settings.tabsColor+";}"; //Offer Color customCSS += "#"+youmaxId+" .yl-callout-buy-button, #"+youmaxId+" .yl-callout-preview-button, #"+youmaxId+" .yl-offer-button{background-color:"+settings.offerHighlightColor+"; color:"+settings.offerBackgroundColor+";}"; customCSS += "#"+youmaxId+" .yl-callout, #"+youmaxId+" .yl-offer{box-shadow: 0px 0px 13px 2px rgba(0,0,0,0.2), 0.2em 0px 0px 0px "+settings.offerHighlightColor+";}"; customCSS += ".yl-grid-callouts .yl-callout{box-shadow: 0px 0px 13px 2px rgba(0,0,0,0.2);}"; customCSS += ".yl-callout-title,.yl-offer-title {color: "+settings.offerTextColor+";}"; customCSS += ".yl-callout-description,.yl-offer-description {color:"+settings.offerTextColor+";}"; customCSS += ".yl-callout-right,.yl-offer {background-color: "+settings.offerBackgroundColor+";}" headerBackgroundColor = settings.headerBackgroundColor; if(headerBackgroundColor.indexOf("rgb")!=-1) { //convert rgb format to rgba format lightHeaderColor = headerBackgroundColor.substring(0,headerBackgroundColor.length-1) + ",0.5)"; lightHeaderColor = lightHeaderColor.replace("rgb","rgba"); customCSS += ".yl-views-per-day{border-color: "+lightHeaderColor+";}"; customCSS += "#"+youmaxId+" .yl-load-more-button:hover {background: linear-gradient(to right,"+lightHeaderColor+","+settings.itemBackgroundColor+" 20%);}" customCSS += "#"+youmaxId+" .yl-loading {background: "+lightHeaderColor+" !important;}"; } //font size styles customCSS += ".yl-title {font-size:"+settings.titleFontSize+"em !important; font-weight:"+settings.titleFontWeight+" !important;}"; customCSS += ".yl-description {font-size:"+settings.descriptionFontSize+"em !important;}"; customCSS += ".yl-date-bucket,.yl-view-string {font-size:"+settings.viewsDateFontSize+"em !important;}"; customCSS += ".youmax-pro,.mfp-container{font-size: "+settings.baseFontSize+";}"; //offer font sizes customCSS += ".yl-offer-title,.yl-callout-title {font-size:"+settings.offerTitleFontSize+"em !important;}"; customCSS += ".yl-offer-description, .yl-callout-description {font-size:"+settings.offerDescriptionFontSize+"em !important;}"; customCSS += ".yl-offer-button, .yl-callout-buy-button, .yl-callout-preview-button {font-size:"+settings.offerButtonFontSize+"em !important;}"; //font-family customCSS += ".yl-item,.yl-callout,.yl-offer{font-family:"+settings.generalFontFamily+";}"; customCSS += ".yl-title,.yl-offer-title,.yl-callout-title {font-family:"+settings.titleFontFamily+";}"; //hiding options if(settings.hideHeader) { customCSS += "#"+youmaxId+" .yl-header {display:none;}"; } if(settings.hideSearch) { customCSS += "#"+youmaxId+" .yl-channel-search {display:none;}"; } if(settings.hideTabs) { customCSS += "#"+youmaxId+" .yl-tab-container {display:none;}"; } if(settings.hideSorting) { customCSS += "#"+youmaxId+" #yl-sort-order {display:none;}"; } if(settings.hideViewSwitcher) { customCSS += "#"+youmaxId+" .yl-switch {display:none;}"; } if(settings.hideLoadingMechanism) { customCSS += "#"+youmaxId+" .yl-load-more-button, #"+youmaxId+" .yl-previous-button, #"+youmaxId+" .yl-next-button{display:none;}"; customCSS += "#"+youmaxId+" .yl-cta-button{width:100%;}"; } if(settings.hideCtaButton) { customCSS += "#"+youmaxId+" .yl-cta-button{display:none;}"; customCSS += "#"+youmaxId+" .yl-load-more-button {width: 100%;} #"+youmaxId+" .yl-previous-button, #"+youmaxId+" .yl-next-button {width: 48.5%;}"; } if(settings.hidePopupDetails) { if(settings.videoDisplayMode=="inline") { customCSS += "#"+youmaxId+" .yp-popup-details {display:none;}"; } else if(settings.videoDisplayMode=="popup") { customCSS += ".yp-popup-details {display:none;}"; settings.popupAlignTop = false; } } if(settings.hideDuration) { customCSS += "#"+youmaxId+" .yl-duration {display:none;}"; } if(settings.hideThumbnailShadow) { customCSS += "#"+youmaxId+" .yl-item {box-shadow:none;}"; } //remove styles if already existing $(".youmax-added-styles-"+youmaxId).remove(); //add new styles $("body").append(""); }, clearSettings = function($youmaxPro){ var settings = $youmaxPro.data("settings"); settings.videoCache = []; settings.nextPageToken = null; settings.clearListOnDisplay = true; settings.searchFlag = false; settings.allDoneFlag = false; $youmaxPro.data("settings",settings); }, initHeader = function($youmaxPro){ var identifierJSON; var settings = $youmaxPro.data("settings"); identifierJSON = sanitizeLink("youtube-channel-uploads",settings.channelLinkForHeader); if(identifierJSON.identifier=="error") { return; } getChannelDetails(identifierJSON.identifierType,identifierJSON.identifier,null,$youmaxPro); }, displayHeader = function(channelDetails,$youmaxPro){ var settings = $youmaxPro.data("settings"); var channelId = channelDetails.items[0].id; var channelName = channelDetails.items[0].snippet.localized.title; var channelLink = "//www.youtube.com/channel/"+channelId; var channelThumbnail = channelDetails.items[0].snippet.thumbnails.default.url; var $youmaxHeader = $youmaxPro.find(".yl-header"); var channelThumbnailHTML = "
"; var channelDetailsHTML = "
"+channelName+"
"; var channelSearchHTML = ""; $youmaxHeader.append(channelThumbnailHTML+channelDetailsHTML+channelSearchHTML); settings.channelIdForSearch = channelId; $youmaxPro.data("settings",settings); renderSubscribeButton(); }, //display youtube subscribe button renderSubscribeButton = function() { $.ajaxSetup({ cache: true }); $.getScript("https://apis.google.com/js/platform.js") .done(function( script, textStatus ) { }) .fail(function( jqxhr, settings, exception ) { }); }, createTabs = function($youmaxPro) { var identifierJSON,source,name,link,selected,channelId,channelUser,playlistId,tabId; var $youmaxTabContainer = $youmaxPro.find(".yl-tab-container"); var settings = $youmaxPro.data("settings"); for(var i=0; i"+name+""); if(source=="youtube-channel-uploads") { //update the tab with uploads's playlist id getChannelDetails(identifierJSON.identifierType,identifierJSON.identifier,tabId,$youmaxPro); } else if(source=="youtube-channel-playlists") { if(identifierJSON.identifierType=="youtube-channel-user") { //update the tab with channel id getChannelDetails(identifierJSON.identifierType,identifierJSON.identifier,tabId,$youmaxPro); } else { //load videos if default Tab if(settings.defaultTab==name) { $youmaxPro.find("#"+tabId).click(); } } } else if(source=="youtube-playlist-videos") { //load videos if default Tab if(settings.defaultTab==name) { $youmaxPro.find("#"+tabId).click(); } } else if(source=="vimeo-user-videos") { //load videos if default Tab if(settings.defaultTab==name) { $youmaxPro.find("#"+tabId).click(); } } } //for loop on tabs ends }, sanitizeLink = function(source,link) { var sanityIndex,channelId,channelUser,playlistId,userName; var identifierJSON = { identifier :"", identifierType :"" }; //remove trailing slashes link = link.replace(/\/$/, ""); //remove "/videos" from the end of URL link = link.replace("/videos",""); //remove "/playlists" from the end of URL link = link.replace("/playlists",""); if(source=="youtube-channel-uploads" || source=="youtube-channel-playlists") { sanityIndex = link.indexOf("/user/"); if(sanityIndex==-1) { sanityIndex = link.indexOf("/channel/"); if(sanityIndex==-1) { alert("\n\nChannel Link should be of the format: \nhttps://www.youtube.com/channel/UComP_epzeKzvBX156r6pm1Q \nOR\nhttps://www.youtube.com/user/designmilk\n\n"); identifierJSON.identifierType = "youtube-channel-id"; identifierJSON.identifier = "error"; } else { channelId = link.substring(sanityIndex+9); identifierJSON.identifierType = "youtube-channel-id"; identifierJSON.identifier = channelId; } } else { channelUser = link.substring(sanityIndex+6); identifierJSON.identifierType = "youtube-channel-user"; identifierJSON.identifier = channelUser; } } else if(source=="youtube-playlist-videos") { identifierJSON.identifierType = "youtube-playlist-id"; sanityIndex = link.indexOf("list="); if(sanityIndex==-1) { alert("\n\nPlaylist Link should be of the format: \nhttps://www.youtube.com/playlist?list=PL6_h4dV9kuuIOBDKgxu3q9DpvvJFZ6fB5\n\n"); identifierJSON.identifier = "error"; } else { playlistId = link.substring(sanityIndex+5); identifierJSON.identifier = playlistId; } } else if(source=="vimeo-user-videos") { identifierJSON.identifierType = "vimeo-user"; sanityIndex = link.indexOf("vimeo.com/"); if(sanityIndex==-1) { alert("\n\nVimeo User Link should be of the format: \nhttps://vimeo.com/user123\n\n"); identifierJSON.identifier = "error"; } else { userName = link.substring(sanityIndex+10); identifierJSON.identifier = userName; } } return identifierJSON; }, getChannelDetails = function(channelType,channelIdentifier,tabId,$youmaxPro) { var apiURL = ""; var settings = $youmaxPro.data("settings"); if(channelType=="youtube-channel-user") { apiURL = "https://www.googleapis.com/youtube/v3/channels?part=contentDetails%2Csnippet&forUsername="+channelIdentifier+"&key="+settings.apiKey; } else if(channelType=="youtube-channel-id") { apiURL = "https://www.googleapis.com/youtube/v3/channels?part=contentDetails%2Csnippet&id="+channelIdentifier+"&key="+settings.apiKey; } $.ajax({ url: apiURL, type: "GET", async: true, cache: true, dataType: 'json', success: function(response) { if(null==tabId) { displayHeader(response,$youmaxPro); } else { updateTabs(tabId,response,$youmaxPro); } }, error: function(html) { } }); }, getChannelPlaylists = function(channelId,$youmaxPro) { var apiURL, videoArray, pageTokenUrl = ""; var settings = $youmaxPro.data("settings"); if(settings.nextPageToken!=null) { pageTokenUrl = "&pageToken="+settings.nextPageToken; } apiURL = "https://www.googleapis.com/youtube/v3/playlists?part=contentDetails%2Csnippet&channelId="+channelId+"&maxResults="+settings.maxResults+pageTokenUrl+"&key="+settings.apiKey; $.ajax({ url: apiURL, type: "GET", async: true, cache: true, dataType: 'json', success: function(response) { videoArray = createPlaylistObjects(response.items,$youmaxPro); handleToken("youtube",response.nextPageToken,$youmaxPro); displayItems(videoArray,$youmaxPro); if(settings.playlistNavigation) { registerPlaylistNavigation($youmaxPro); } else { videoDisplayMechanism($youmaxPro); } }, error: function(html) { } }); }, getPlaylistVideos = function(playlistId,$youmaxPro) { var apiURL, pageTokenUrl = ""; var settings = $youmaxPro.data("settings"); if(settings.nextPageToken!=null) { pageTokenUrl = "&pageToken="+settings.nextPageToken; } apiURL = "https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId="+playlistId+"&maxResults="+settings.maxResults+pageTokenUrl+"&key="+settings.apiKey; $.ajax({ url: apiURL, type: "GET", async: true, cache: true, dataType: 'json', success: function(response) { createVideoObjects(response.items,$youmaxPro); handleToken("youtube",response.nextPageToken,$youmaxPro); }, error: function(html) { } }); }, getSearchVideos = function(searchText,$youmaxPro){ var apiURL, pageTokenUrl = ""; var settings = $youmaxPro.data("settings"); if(settings.nextPageToken!=null) { pageTokenUrl = "&pageToken="+settings.nextPageToken; } apiURL = "https://www.googleapis.com/youtube/v3/search?part=snippet&q="+searchText+"&order=relevance&channelId="+settings.channelIdForSearch+"&type=video&maxResults="+settings.maxResults+pageTokenUrl+"&key="+settings.apiKey; $.ajax({ url: apiURL, type: "GET", async: true, cache: true, dataType: 'json', success: function(response) { createSearchVideoObjects(response.items,$youmaxPro); handleToken("youtube",response.nextPageToken,$youmaxPro); }, error: function(html) { } }); }, getVimeoUserVideos = function (userId,$youmaxPro) { var apiURL, pageTokenUrl = ""; var videoArray; var settings = $youmaxPro.data("settings"); if(settings.nextPageToken!=null) { pageTokenUrl = "&"+settings.nextPageToken; } apiURL = "https://api.vimeo.com/users/"+userId+"/videos?access_token="+settings.vimeoAccessToken+"&per_page="+settings.maxResults+pageTokenUrl; $.ajax({ url: apiURL, type: "GET", async: true, cache: true, dataType: 'json', success: function(response) { videoArray = createVimeoVideoObjects(response.data,$youmaxPro); handleToken("vimeo",response.paging.next,$youmaxPro); displayItems(videoArray,$youmaxPro); videoDisplayMechanism($youmaxPro); }, error: function(html) { } }); }, /* getYouTubeVideoLikes = function(videoId,$youmaxPro) { var apiURL, postArray; var settings = $youmaxPro.data("settings"); apiURL = "https://www.googleapis.com/youtube/v3/commentThreads?part=id%2Csnippet&textFormat=plainText&videoId="+videoId+"&maxResults=6&key="+settings.apiKey+"&order=time"; $.ajax({ url: apiURL, type: "GET", async: true, cache: true, dataType: 'json', success: function(response) { displayYouTubeComments(response.items,$famaxPro); }, error: function(html) { } }); }, */ getYouTubeVideoComments = function(videoId,$youmaxPro) { var apiURL, postArray; var settings = $youmaxPro.data("settings"); apiURL = "https://www.googleapis.com/youtube/v3/commentThreads?part=id%2Csnippet&textFormat=plainText&videoId="+videoId+"&maxResults=6&key="+settings.apiKey+"&order=time"; $.ajax({ url: apiURL, type: "GET", async: true, cache: true, dataType: 'json', success: function(response) { displayYouTubeComments(response.items,$youmaxPro); }, error: function(html) { } }); }, handleToken = function(network,token,$youmaxPro) { var settings = $youmaxPro.data("settings"); if(token==null) { showAllDoneButtonText($youmaxPro); settings.nextPageToken = null; $youmaxPro.data("settings",settings); return; } showOriginalButtonText($youmaxPro); //token is not null.. next page is present if(network=="vimeo") { token = token.substring(token.lastIndexOf("&")+1); settings.nextPageToken = token; } else if(network="youtube") { settings.nextPageToken = token; } $youmaxPro.data("settings",settings); }, getVideoStatistics = function(videoIdArray,videoArray,$youmaxPro) { var settings = $youmaxPro.data("settings"); var apiURL = "https://www.googleapis.com/youtube/v3/videos?part=statistics%2CcontentDetails%2Csnippet&id="+videoIdArray+"&key="+settings.apiKey; var videoArray; $.ajax({ url: apiURL, type: "GET", async: true, cache: true, dataType: 'json', success: function(response) { videoArray = addStatisticsToVideos(response.items,videoArray,$youmaxPro); displayItems(videoArray,$youmaxPro); videoDisplayMechanism($youmaxPro); }, error: function(html) { } }); }, createVideoObjects = function(itemArray,$youmaxPro) { var videoIdArray = [], videoArray = []; var proSnippet; for(var i=0; i"+duration+" if(isPlaylist) { viewsText = itemCount + " videos"; playlistHTML = "
"+itemCount+"
VIDEOS


"; hoverPlayHTML = ""; fixedPlayHTML = ""; } else { viewsText = views + " views"; } if(viewsPerDay>settings.minimumViewsPerDayForTrendingVideos) { trendBoxHTML = "
"; } else { trendBoxHTML = ""; } if(null!=duration) { durationHTML = "
"+duration+"
"; } else { durationHTML = ""; } //viewboxHTML = "
"+viewsFancy+"
"; viewboxHTML = "
"+viewsText+"
"; viewStringHTML = "
"+viewsText+"
"; dateboxHTML = "
"+date+"
"; itemboxHTML = "
"+durationHTML+hoverPlayHTML+fixedPlayHTML+"

"+viewboxHTML+"
"+title+"
"+description+"
"+"
"+viewStringHTML+dateboxHTML+trendBoxHTML+"
"+playlistHTML+"
"; containerHTML += "
"+itemboxHTML+"
"; } if(isPlaylist) { $("body").addClass("yl-playlist"); } else { $("body").removeClass("yl-playlist"); } $youmaxContainer.append(containerHTML); }, displayPopupData = function($baseElement,$youmaxPro) { var popupTitleHTML,popupDescriptionHTML,popupMoreHTML,facebookShareHTML,twitterShareHTML,googleShareHTML; var youtubeLikesHTML, youtubeAddCommentHTML, youtubeCommentsHTML, youtubeCommentListHTML; var videoId, title, textTitle, description, link, likes,comments; var $popupBox; setTimeout(function(){ $popupBox = $(".yp-popup-details"); videoId = $baseElement.attr("id"); title = $baseElement.find(".yl-title").html(); textTitle = $baseElement.find(".yl-title").text(); description = $baseElement.find(".yl-description").html(); description = description.replace(/\n/g,"
"); link = $baseElement.find(".yl-focus").data("link"); link = encodeURIComponent(link); likes = $baseElement.data("likes"); comments = $baseElement.data("comments"); popupTitleHTML = "
"+title+"
"; popupDescriptionHTML = "
"+description+"
"; popupMoreHTML = "
show more..

"; facebookShareHTML = "
"; twitterShareHTML = "
"; googleShareHTML = "
"; youtubeLikesHTML = "
"+likes+"
likes
"; youtubeAddCommentHTML = "
Post
"; youtubeCommentListHTML = "
"; youtubeCommentsHTML = "
"+comments+"
comments
"; // $popupBox.empty(); $popupBox.append("
"+popupTitleHTML+popupDescriptionHTML+popupMoreHTML+youtubeLikesHTML+youtubeAddCommentHTML+youtubeCommentsHTML+youtubeCommentListHTML+"
"+"
"+facebookShareHTML+twitterShareHTML+googleShareHTML+"
"); getYouTubeVideoComments(videoId,$youmaxPro); }, 100); }, displayYouTubeComments = function(commentArray,$youmaxPro) { for(var i=0; i
"+commentArray[i].snippet.topLevelComment.snippet.authorDisplayName+"
"+commentArray[i].snippet.topLevelComment.snippet.textDisplay+"
"); $(".yp-post-comment-users").append(""); } }, clearList = function($youmaxPro) { $youmaxPro.find(".yl-item-container").empty(); }, videoDisplayMechanism = function($youmaxPro){ var settings = $youmaxPro.data("settings"); if(settings.videoDisplayMode=="popup") { registerPopup($youmaxPro); } else if(settings.videoDisplayMode=="inline") { registerInlineEmbed($youmaxPro); } else { registerLinkToYouTube($youmaxPro); } }, registerPopup = function($youmaxPro) { var currentTabId, playlistId, embedURL = ""; var settings = $youmaxPro.data("settings"); var autoPlayString = settings.autoPlay ? "&autoplay=1" : "&autoplay=0"; //get selected tab and handle the tab click currentTabId = $youmaxPro.find(".yl-selected-tab").attr("id"); playlistId = currentTabId.substring(currentTabId.indexOf("-",20)+1); if(currentTabId.indexOf("vimeo")!=-1) { embedURL = "//player.vimeo.com/video/%id%?badge=0&autopause=0&player_id=0"+autoPlayString; } else if(currentTabId.indexOf("youtube-channel-playlists")!=-1) { embedURL = "//www.youtube.com/embed?listType=playlist&list=%id%&rel=0"+autoPlayString; } else { embedURL = "//www.youtube.com/embed/%id%?&rel=0"+autoPlayString; } $youmaxPro.find(".yl-focus").magnificPopup({ gallery: { enabled: true }, type:'iframe', iframe:{ markup: '
'+ ''+ ''+ '
'+ '
'+ '
Loading...
', patterns: { youtube: { src: embedURL }, vimeo : { src: embedURL } } }, alignTop: settings.popupAlignTop, callbacks: { change: function() { // Triggers each time when content of popup changes var $baseElement = $(this.currItem.el[0].offsetParent); displayPopupData($baseElement,$youmaxPro); } } }); }, registerInlineEmbed = function($youmaxPro) { //get selected tab and handle the tab click var currentTabId = $youmaxPro.find(".yl-selected-tab").attr("id"); var playlistId = currentTabId.substring(currentTabId.indexOf("-",20)+1); var settings = $youmaxPro.data("settings"); $youmaxPro.on("click",".yl-focus", function(){ var embedURL = ""; var id = $(this).parents(".yl-item").attr("id"); var $youmaxInlineContainer = $youmaxPro.find(".yl-inline-container"); var autoPlayString = settings.autoPlay ? "&autoplay=1" : "&autoplay=0"; var videoContainerHTML, videoDataHTML; if(currentTabId.indexOf("vimeo")!=-1) { embedURL = "//player.vimeo.com/video/"+id+"?badge=0&autopause=0&player_id=0"+autoPlayString; } else if(currentTabId.indexOf("youtube-channel-playlists")!=-1) { embedURL = "//www.youtube.com/embed?listType=playlist&list="+id+"&rel=0"+autoPlayString; } else { embedURL = "//www.youtube.com/embed/"+id+"?rel=0"+autoPlayString; } videoContainerHTML = '
'; videoDataHTML = '
'; $youmaxInlineContainer.html(videoContainerHTML+videoDataHTML).css("display","inline-block"); $('html, body').animate({scrollTop: $youmaxInlineContainer.offset().top - 150},'slow'); var $baseElement = $(this).parent(".yl-item"); displayPopupData($baseElement,$youmaxPro); }); if(settings.displayFirstVideoOnLoad) { $youmaxPro.find(".yl-focus:first").click(); } }, registerLinkToYouTube = function($youmaxPro) { $youmaxPro.find(".yl-focus").each(function(i,v){ var $focusElement = $(v); var link = $focusElement.data("link"); $focusElement.wrap("
"); }); }, registerPlaylistNavigation = function($youmaxPro) { $youmaxPro.find(".yl-focus").click(function(){ var $item = $(this).parent(".yl-item"); var playlistId = $item.attr("id"); var playlistTitle = $item.find(".yl-title").text(); var settings = $youmaxPro.data("settings"); var $currentTab = $youmaxPro.find(".yl-selected-tab"); var $playlistTab = $youmaxPro.find(".yl-showing-playlist-name"); //remove selected tab $currentTab.removeClass("yl-selected-tab"); //set last tab id settings.previousTabId = $currentTab.attr("id"); $youmaxPro.data("settings",settings); //set playlist name $playlistTab.data("playlist-name",playlistTitle).attr("id","youtube-playlist-videos-"+playlistId).addClass("yl-playlist-tab"); handlePlaylistTabClick($playlistTab,$youmaxPro); }); }, popularFirstComparator = function(a,b) { return b.views - a.views; }, latestFirstComparator = function(a,b) { return (new Date(b.date).getTime()) - (new Date(a.date).getTime()); }, handleSortOrders = function($youmaxPro) { var seenVideos = []; var settings = $youmaxPro.data("settings"); $('#yl-sort-order').change(function() { seenVideos = saveSeenVideos($youmaxPro); showLoader($youmaxPro); //not needed as list is cleared in show loader //clearList($youmaxPro); //remove search flag as sorting needs to be done settings.searchFlag = false; displayItems(settings.videoCache,$youmaxPro); highlightSeenVideos(seenVideos,$youmaxPro); videoDisplayMechanism($youmaxPro); }); $youmaxPro.find("#yl-sort-order").val(settings.defaultSortOrder); }, handleGridListSwitch = function ($youmaxPro) { var $viewSwitch = $youmaxPro.find(".yl-switch"); var requiredView; var settings = $youmaxPro.data("settings"); if(settings.youmaxDisplayMode=="grid") { $viewSwitch.find("i").addClass("fa-bars").removeClass("fa-th-large") $viewSwitch.data("view","double-list"); } else { $viewSwitch.find("i").removeClass("fa-bars").addClass("fa-th-large") $viewSwitch.data("view","grid"); } $viewSwitch.click(function(){ requiredView = $viewSwitch.data("view"); settings.youmaxDisplayMode = requiredView; $youmaxPro.removeClass("yl-double-list yl-list yl-grid yl-1-col-grid yl-2-col-grid yl-3-col-grid yl-4-col-grid yl-5-col-grid"); handleYoumaxDisplay($youmaxPro); if(requiredView=="double-list") { $viewSwitch.find("i").removeClass("fa-bars").addClass("fa-th-large") $viewSwitch.data("view","grid"); } else { $viewSwitch.find("i").addClass("fa-bars").removeClass("fa-th-large") $viewSwitch.data("view","double-list"); } }); }, handleTabs = function ($youmaxPro) { $youmaxPro.on("click",".yl-tab",function() { handleTabClick($(this),$youmaxPro); }); $youmaxPro.on("click",".yl-playlist-tab",function() { //go back to last tab var settings = $youmaxPro.data("settings"); var previousTabId = settings.previousTabId; $youmaxPro.find("#"+previousTabId).click(); }); }, handleTabClick = function($tab,$youmaxPro) { clearSettings($youmaxPro); showLoader($youmaxPro); //add selected tab class to current tab $youmaxPro.find(".yl-tab").removeClass("yl-selected-tab"); $tab.addClass("yl-selected-tab"); displayTabItems($youmaxPro); }, handlePlaylistTabClick = function($tab,$youmaxPro) { var settings = $youmaxPro.data("settings"); var playlistName; clearSettings($youmaxPro); showLoader($youmaxPro); //add selected tab class to current tab $youmaxPro.find(".yl-tab").removeClass("yl-selected-tab"); $tab.addClass("yl-selected-tab"); playlistName = $tab.data("playlist-name"); $tab.append(" Showing playlist: "+playlistName).show(); displayTabItems($youmaxPro); }, displayTabItems = function($youmaxPro) { //get selected tab and handle the tab click var tabId = $youmaxPro.find(".yl-selected-tab").attr("id"); var identifier = tabId.substring(tabId.indexOf("-",17)+1); if(tabId.indexOf("youtube-channel-uploads")!=-1) { getPlaylistVideos(identifier,$youmaxPro); } else if(tabId.indexOf("youtube-channel-playlists")!=-1) { getChannelPlaylists(identifier,$youmaxPro); } else if(tabId.indexOf("youtube-playlist-videos")!=-1) { getPlaylistVideos(identifier,$youmaxPro); } else if(tabId.indexOf("vimeo-user-videos")!=-1) { getVimeoUserVideos(identifier,$youmaxPro); } }, handleSearch = function($youmaxPro) { var searchText; $youmaxPro.on('keyup','.yl-channel-search-input', function (e) { if (e.keyCode == 13) { clearSettings($youmaxPro); showLoader($youmaxPro); displaySearchItems($youmaxPro); return false; } }); }, displaySearchItems = function($youmaxPro) { var searchText; var settings = $youmaxPro.data("settings"); //set search flag as sorting needs to be doen on relevance settings.searchFlag = true; $youmaxPro.data("settings",settings); searchText = $youmaxPro.find('.yl-channel-search-input').val().replace(/ /g,"%20"); getSearchVideos(searchText,$youmaxPro); }, handlePopupButtons = function($youmaxPro) { /*$youmaxPro.on("mouseenter",".yl-focus",function() { $(this).find(".triangle-with-shadow").addClass("triangle-with-hover"); }); $youmaxPro.on("mouseleave",".yl-focus",function() { $(this).find(".triangle-with-shadow").removeClass("triangle-with-hover"); }); $youmaxPro.on("click",".yl-focus",function() { $(this).find(".yl-view-bucket").addClass("yl-view-bucket-seen"); $(this).find(".triangle-with-shadow").removeClass("triangle-with-hover"); });*/ $("body").on("click",".yp-popup-more-button",function() { $(this).remove(); $(".yp-show-less").removeClass("yp-show-less"); }); $(document).on("click", ".yp-post-likes", function(){ handleYouTubeLikes($youmaxPro); }); $(document).on("click", ".yp-add-comment-button", function(){ handleYouTubeComments($youmaxPro); }); }, handleAnimations = function($youmaxPro) { var settings = $youmaxPro.data("settings"); var customCSS; var youmaxId = $youmaxPro.attr("id"); if(settings.showFixedPlayIcon) { customCSS = "#"+youmaxId+" .yl-duration i{display:none;}" customCSS += "#"+youmaxId+" .yl-play-overlay-fixed {display: block;}"; //square or circle if(settings.iconShape=="circle") { customCSS += "#"+youmaxId+" .yl-play-icon-holder {width: 2.6em;height: 2.6em;border-radius: 100%;padding: 0.1em 0.25em;box-sizing: border-box;}"; } $("body").append(""); if(settings.showHoverAnimation) { $youmaxPro.on("mouseenter",".yl-focus",function() { $(this).find(".yl-play-icon-holder").addClass("yl-play-fill-color"); }); $youmaxPro.on("mouseleave",".yl-focus",function() { $(this).find(".yl-play-icon-holder").removeClass("yl-play-fill-color"); }); } } else if(settings.showHoverAnimation) { $youmaxPro.on("mouseenter",".yl-focus",function() { $(this).find(".yl-duration").addClass("yl-duration-big"); $(this).find(".yl-play-overlay").show(); }); $youmaxPro.on("mouseleave",".yl-focus",function() { $(this).find(".yl-duration").removeClass("yl-duration-big"); $(this).find(".yl-play-overlay").hide(); }); } }, handleLoadingMechanism = function($youmaxPro) { var settings = $youmaxPro.data("settings"); //Load More button handler $youmaxPro.on('click','.yl-load-more-button', function(){ //remove first video auto load flag settings.displayFirstVideoOnLoad = false; if(settings.allDoneFlag) { return; } $(this).addClass("yl-loading").html(settings.loadingText); //do not clear list during load mores settings.clearListOnDisplay = false; $youmaxPro.data("settings",settings); checkCache("next",$youmaxPro); }); //Next Button Handler $youmaxPro.on('click','.yl-next-button', function(){ //remove first video auto load flag settings.displayFirstVideoOnLoad = false; //cannot use alldone flag for prev-next buttons /*if(settings.allDoneFlag) { return; }*/ $(this).addClass("yl-loading").html(settings.loadingText); //Clear list during load mores settings.clearListOnDisplay = true; //fade out the current items $youmaxPro.find(".yl-item").addClass("yl-fading"); $youmaxPro.data("settings",settings); checkCache("next",$youmaxPro); }); //Previous Button Handler $youmaxPro.on('click','.yl-previous-button', function(){ //remove first video auto load flag settings.displayFirstVideoOnLoad = false; //cannot use alldone flag for prev-next buttons /*if(settings.allDoneFlag) { return; }*/ $(this).addClass("yl-loading").html(settings.loadingText); //fade out the current items $youmaxPro.find(".yl-item").addClass("yl-fading"); //Clear list during load mores settings.clearListOnDisplay = true; $youmaxPro.data("settings",settings); checkCache("previous",$youmaxPro); }); }, checkCache = function(direction,$youmaxPro) { var newCacheBlockStart, newCacheBlockEnd, videoArray, maxResults; var settings = $youmaxPro.data("settings"); maxResults = parseInt(settings.maxResults,10); if(direction=="previous") { //for previous navigation newCacheBlockStart = settings.currentCacheBlockStart - maxResults; newCacheBlockEnd = settings.currentCacheBlockStart; if(newCacheBlockStart<0) { newCacheBlockStart = 0; } if(newCacheBlockEnd<=0) { showAllDoneButtonText($youmaxPro); return; } } else if(direction=="next") { //for next navigation newCacheBlockStart = settings.currentCacheBlockEnd; newCacheBlockEnd = newCacheBlockStart + maxResults; if(newCacheBlockEnd>settings.videoCache.length) { newCacheBlockEnd = settings.videoCache.length; } if(newCacheBlockStart>=settings.videoCache.length) { showMoreVideosHandler($youmaxPro); return; } } settings.currentCacheBlockStart = newCacheBlockStart; settings.currentCacheBlockEnd = newCacheBlockEnd; $youmaxPro.data("settings",settings); videoArray = settings.videoCache.slice(newCacheBlockStart, newCacheBlockEnd); displayItems(videoArray,$youmaxPro); showOriginalButtonText($youmaxPro); }, showOriginalButtonText = function($youmaxPro) { var originalText; var $nextButton = $youmaxPro.find(".yl-next-button"); var $previousButton = $youmaxPro.find(".yl-previous-button"); var $loadMoreButton = $youmaxPro.find(".yl-load-more-button"); originalText = $nextButton.data("text"); $nextButton.removeClass("yl-loading").html(originalText); originalText = $previousButton.data("text"); $previousButton.removeClass("yl-loading").html(originalText); originalText = $loadMoreButton.data("text"); $loadMoreButton.removeClass("yl-loading").html(originalText); }, showAllDoneButtonText = function($youmaxPro) { var $loadingButton = $youmaxPro.find(".yl-loading"); var settings = $youmaxPro.data("settings"); if(null==$loadingButton || $loadingButton.length==0) { if(settings.loadingMechanism=="load-more") { $loadingButton = $youmaxPro.find(".yl-load-more-button"); } else { $loadingButton = $youmaxPro.find(".yl-next-button"); } } $loadingButton.removeClass("yl-loading").html(settings.allDoneText); settings.allDoneFlag = true; $youmaxPro.data("settings",settings); //remove fading for pagination $youmaxPro.find(".yl-item").removeClass("yl-fading"); }, showMoreVideosHandler = function($youmaxPro) { var settings = $youmaxPro.data("settings"); //do nothing if next token is not present if(settings.nextPageToken==null) { showAllDoneButtonText($youmaxPro); settings.nextPageToken = null; $youmaxPro.data("settings",settings); return; } if(settings.searchFlag) { displaySearchItems($youmaxPro); } else { displayTabItems($youmaxPro); } }, handleYoumaxDisplay = function($youmaxPro) { var settings = $youmaxPro.data("settings"); if(settings.youmaxDisplayMode=="double-list") { if($youmaxPro.width()=settings.responsiveBreakpoints[1]) { $youmaxPro.addClass("yl-double-list").removeClass("yl-grid").removeClass("yl-list"); } } if(settings.youmaxDisplayMode=="list") { if($youmaxPro.width()"; calloutTextHTML = "
"+calloutList[i].title+"
"+calloutList[i].description+"
"; calloutBuyButtonHTML = "
"+calloutList[i].buyButtonText+"
"; calloutPreviewButtonHTML = "
"; $calloutContainer.append("
"+calloutImageHTML+"
"+calloutTextHTML+calloutPreviewButtonHTML+calloutBuyButtonHTML+"
"); } }, handleOffers = function($youmaxPro) { var settings = $youmaxPro.data("settings"); if(null!=settings.offerLink) { //offer present $youmaxPro.addClass("yl-offer-enabled"); $youmaxPro.find(".yl-header").append("
"+settings.offerTitle+"
"+settings.offerDescription+"
"+settings.offerButtonText+"
"); } }, showLoader = function($youmaxPro) { $youmaxPro.find(".yl-inline-container").empty(); $youmaxPro.find(".yl-item-container").empty().append("
Getting
Videos..
"); $youmaxPro.find(".yl-showing-playlist-name").empty().hide(); }, saveSeenVideos = function($youmaxPro) { var seenVideos = []; $youmaxPro.find(".yl-seen").each(function(){ seenVideos.push($(this).attr("id")); }); return seenVideos; }, highlightSeenVideos = function(seenVideos,$youmaxPro) { for(var k=seenVideos.length;k>=0;k--) { $youmaxPro.find("#"+seenVideos[k]).addClass("yl-seen"); } }, convertViews = function(views) { var commaSeparatedViews = ""; views = ""+views; while(views.length>0) { if(views.length > 3) { commaSeparatedViews = ","+views.substring(views.length-3)+commaSeparatedViews; views = views.substring(0,views.length-3); } else { commaSeparatedViews = views + commaSeparatedViews; break; } } return commaSeparatedViews; }, convertDate = convertToSpecificDate, convertToSpecificDate = function(date) { //date incoming format "2016-08-26T21:48:14.000Z" var months = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]; var innerDate = date.substring(0,date.indexOf("T")); var splitDate = innerDate.split("-"); //var returnDate = splitDate[2]+"-"+months[splitDate[1]-1]+"-"+splitDate[0]; var returnDate = "
"+splitDate[2]+"
"+months[splitDate[1]-1]+"
"+splitDate[0]+"
"; //date outgoing format "26 Aug 2016" return returnDate; }, //utility function to display time convertDuration = function(videoDuration) { var duration,returnDuration; videoDuration = videoDuration.replace('PT','').replace('S','').replace('M',':').replace('H',':'); var videoDurationSplit = videoDuration.split(':'); returnDuration = videoDurationSplit[0]; for(var i=1; i=60) { hours = parseInt(min/60,10); min = min - (hours*60); if(min<10) { min="0"+min; } return hours+":"+min+":"+sec; } else { return min+":"+sec; } }, convertToRelativeDate = function (timestamp) { var dateDiffMS, dateDiffHR, dateDiffDY, dateDiffMH, dateDiffYR; if(null==timestamp||timestamp==""||timestamp=="undefined") return "?"; dateDiffMS = Math.abs(new Date() - new Date(timestamp)); dateDiffHR = dateDiffMS/1000/60/60; if(dateDiffHR>24) { dateDiffDY = dateDiffHR/24; if(dateDiffDY>30) { dateDiffMH = dateDiffDY/30; if(dateDiffMH>12) { dateDiffYR = dateDiffMH/12; dateDiffYR = Math.round(dateDiffYR); if(dateDiffYR<=1) { return dateDiffYR+" year ago"; } else { return dateDiffYR+" years ago"; } } else { dateDiffMH = Math.round(dateDiffMH); if(dateDiffMH<=1) { return dateDiffMH+" month ago"; } else { return dateDiffMH+" months ago"; } } } else { dateDiffDY = Math.round(dateDiffDY); if(dateDiffDY<=1) { return dateDiffDY+" day ago"; } else { return dateDiffDY+" days ago"; } } } else { dateDiffHR = Math.round(dateDiffHR); if(dateDiffHR<1) { return "just now"; }else if(dateDiffHR==1) { return dateDiffHR+" hour ago"; } else { return dateDiffHR+" hours ago"; } } }, processDescription = function(description) { var spotArray,replaceLink; description = description.replace(/"/g, "'"); spotArray = description.match(/(http(s)*:\/\/|www\.).+?(\s|\n|$)/g); if(null!=spotArray) { for(var i=0;i"+spotArray[i]+""); } } return description; }, youmaxLoginToYouTube = function($youmaxPro) { var settings = $youmaxPro.data("settings"); youmaxLoggedInUser.apiKey = settings.apiKey; gapi.auth.signIn({ 'clientid' : settings.youTubeClientId, 'cookiepolicy' : 'single_host_origin', 'callback' : 'youmaxSaveToken', 'scope' : 'https://www.googleapis.com/auth/youtube.force-ssl' }); }, handleYouTubeComments = function($youmaxPro) { if(youmaxLoggedInUser.token==null) { youmaxLoggedInUser.action="comment"; youmaxLoginToYouTube($youmaxPro); } else { youmaxPostYouTubeComment($youmaxPro); } }, handleYouTubeLikes = function($youmaxPro) { if(youmaxLoggedInUser.token==null) { youmaxLoggedInUser.action="like"; youmaxLoginToYouTube($youmaxPro); } else { youmaxPostYouTubeLike($youmaxPro); } }; $.fn.youmaxPro=function(options) { var $youmaxPro=this; var settings = $.extend({},localSettings,options); $youmaxPro.data("settings",settings); init($youmaxPro); doOptions($youmaxPro); initHeader($youmaxPro); handleTabs($youmaxPro); createTabs($youmaxPro); handleSearch($youmaxPro); handleSortOrders($youmaxPro); handleGridListSwitch($youmaxPro); handlePopupButtons($youmaxPro); handleAnimations($youmaxPro); handleLoadingMechanism($youmaxPro); handleResize($youmaxPro); handleCallouts($youmaxPro); handleOffers($youmaxPro); return this; } })(jQuery); function youmaxSaveToken(authResult) { if (authResult['status']['signed_in']) { youmaxLoggedInUser.token = authResult.access_token; if(youmaxLoggedInUser.action=="comment") { youmaxPostYouTubeComment(); youmaxLoggedInUser.action=null; } else if(youmaxLoggedInUser.action=="like") { youmaxPostYouTubeLike(); youmaxLoggedInUser.action=null; } } } function youmaxPostYouTubeComment() { var videoId = jQuery(".yp-post-likes").data("videoid"); var comment = jQuery("#yp-add-comment-text").val(); var postCommentURL = "https://www.googleapis.com/youtube/v3/commentThreads?part=snippet&shareOnGooglePlus=false&fields=snippet&key="+youmaxLoggedInUser.apiKey; var xmlComment = '{"snippet":{"videoId":"'+videoId+'","topLevelComment":{"snippet":{"textOriginal":"'+comment+'"}}}}'; jQuery.ajax({ url: postCommentURL, type: 'post', crossDomain: true, data:xmlComment, beforeSend: function(xhr){ xhr.setRequestHeader('Authorization','Bearer '+youmaxLoggedInUser.token); xhr.setRequestHeader('Content-Type','application/json'); xhr.setRequestHeader('Content-Length',xmlComment.length); }, success: function (data, status) { var authorName = data.snippet.topLevelComment.snippet.authorDisplayName; var authorImage = data.snippet.topLevelComment.snippet.authorProfileImageUrl; jQuery(".yp-post-comments").prepend("
"+authorName+"
"+comment+"
"); jQuery(".yp-post-comment-users").prepend(""); jQuery("#yp-add-comment-text").val(""); }, error: function (xhr, desc, err) { alert("Could not add comment"); console.log(err); } }); } function youmaxPostYouTubeLike() { if(youmaxLoggedInUser.likeListId==null) { getLikeListId(); } else { addYouTubeLike(); } } function getLikeListId() { var apiURL = "https://www.googleapis.com/youtube/v3/channels?mine=true&part=contentDetails%2Csnippet&key="+youmaxLoggedInUser.apiKey+"&access_token="+youmaxLoggedInUser.token; jQuery.ajax({ url: apiURL, type: "GET", async: true, cache: true, dataType: 'json', success: function(response) { youmaxLoggedInUser.likeListId = response.items[0].contentDetails.relatedPlaylists.likes; youmaxLoggedInUser.picture = response.items[0].snippet.thumbnails.default.url; youmaxLoggedInUser.name = response.items[0].snippet.customUrl; addYouTubeLike(); }, error: function(html) { alert("Could not add Like"); } }); } function addYouTubeLike() { var videoId = jQuery(".yp-post-likes").data("videoid"); var postLikeURL = "https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&fields=snippet&key="+youmaxLoggedInUser.apiKey; var xmlLike = '{"snippet": {"resourceId": {"videoId": "'+videoId+'","kind": "youtube#video"},"playlistId": "'+youmaxLoggedInUser.likeListId+'"}}'; jQuery.ajax({ url: postLikeURL, type: 'post', crossDomain: true, data:xmlLike, beforeSend: function(xhr){ xhr.setRequestHeader('Authorization','Bearer '+youmaxLoggedInUser.token); xhr.setRequestHeader('Content-Type','application/json'); xhr.setRequestHeader('Content-Length',xmlLike.length); }, success: function (data, status) { var authorImage = youmaxLoggedInUser.picture; jQuery(".yp-post-like-count").after(""); jQuery(".yp-post-likes").css("pointer-events","none"); }, error: function (xhr, desc, err) { alert("Could not add like"); console.log(err); } }); }