/*--------------------------------------------------------------------------------
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 = "";
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 = "";
hoverPlayHTML = "";
fixedPlayHTML = "";
} else {
viewsText = views + " views";
}
if(viewsPerDay>settings.minimumViewsPerDayForTrendingVideos) {
trendBoxHTML = "
";
} else {
trendBoxHTML = "";
}
if(null!=duration) {
durationHTML = ""+duration+"
";
} else {
durationHTML = "";
}
//viewboxHTML = "";
viewboxHTML = "";
viewStringHTML = ""+viewsText+"
";
dateboxHTML = ""+date+"
";
itemboxHTML = "
"+durationHTML+hoverPlayHTML+fixedPlayHTML+"
"+viewboxHTML+"
"+"
"+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 = "";
popupDescriptionHTML = "";
popupMoreHTML = "
";
facebookShareHTML = "
";
twitterShareHTML = "";
googleShareHTML = "
";
youtubeLikesHTML = "";
youtubeAddCommentHTML = "";
youtubeCommentListHTML = "";
youtubeCommentsHTML = "";
//
$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";
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("");
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);
}
});
}