/*-------------------------------------------------------------------------------- Famax PRO v6.2 by Jake H. from CodeHandling https://codecanyon.net/item/famax-facebook-fan-page-on-your-website/10287995?ref=codehandling ---------------------------------------------------------------------------------*/ /*------------------------------------------------------------------ [Table of contents] 1. Famax Settings 2. DOM Initialization 3. Options Initialization 4. Source Validation 5. Getters 5.1 Page Details 5.2 Page Posts 5.3 Page Videos 5.4 Page Photos 6. Setters 6.1 Post Objects 6.2 Photo Objects 6.3 Video Setters 7. Display List 8. Item Display Mechanisms 8. Sorting Handlers 9. Tab Handlers 9. Popup Button Handler 10.Load More Handler 12.Famax Display Handler 11.Resize Handler 12.Utility Functions 13.Facebook Login 14.Famax Main Function -------------------------------------------------------------------*/ (function($) { "use strict"; var settings = { appId:'852602131447787', accessToken: 'EAAJTO0BbbJUBAHSW6a0dfzb7Nx5BADMHk3OlaQFEBFDlTmenOSAMes2JZAjaEDy0YGa2NZBbhZAicjCznslFkwTlQcjlRnZCpz9kOOWekXw4dYxzJaPRoXvuy9vgKVf0k2VHaFQBxpbmcU9tyCYkkzmIqcfapY8ZD', fanPageLinkForHeader:'http://www.facebook.com/adidas', tabs:[ { name:"Posts", type:"facebook-page-posts", link:"https://www.facebook.com/adidas", }, { name:"Photos", type:"facebook-page-photos", link:"http://www.facebook.com/adidas" }, { name:"Videos", type:"facebook-page-videos", link:"http://www.facebook.com/adidas" }, { name:"Album Pics", type:"facebook-album-photos", link:"https://www.facebook.com/pg/adidas/photos/?tab=album&album_id=191308754225385" }, ], defaultTab:"Posts", itemDisplayMode:"popup", maxResults:12, defaultSortOrder:"recent-first", famaxDisplayMode:"grid", dateFormat:"relative", famaxBackgroundColor :"#ECEFF1", itemBackgroundColor :"#fbfbfb", headerBackgroundColor :"rgb(244, 67, 54)", titleColor :"rgb(97, 93, 93)", likesColor :"#6f6f6f", controlsTextColor :"black", titleFontFamily :"Roboto Condensed", generalFontFamily :"Roboto Condensed", titleFontSize :"1", titleFontWeight :"normal", likesDateFontSize :"0.85", baseFontSize :"16px", responsiveBreakpoints :[600,1200,2000,2500], loadMoreText :"  Show me more posts..", ctaText :"  Check out our store!", ctaLink :"http://www.adidas.co.in/heretocreate", postList :[], popupAlignTop :true, aspectRatio :360/640, nextPageToken :null, clearListOnDisplay :true, channelIdForSearch :null, searchFlag :false, famaxLoggedInUser : { name :null, id :null, picture :null, token :null, } }, init = function($famaxPro) { var facebookWrapperStart = "
" var facebookWrapperEnd = "
" var listWrapperStart = "
"; var listWrapperEnd = "
"; var pageHeader = "
" var listHeader = "
"; //var inlineContainer = "
"; var listContainer = "
"; var loadMoreButton = "
"+settings.loadMoreText+"
"; var ctaButton = ""; var calloutContainer = "
"; var albumNavigationName = "
"; var popupContainer = "
"; if(settings.ctaLink!=null) { ctaButton = "
"+settings.ctaText+"
"; } $famaxPro.append(facebookWrapperStart+pageHeader+listWrapperStart+listHeader+albumNavigationName+listContainer+loadMoreButton+ctaButton+listWrapperEnd+facebookWrapperEnd+popupContainer); showLoader($famaxPro); }, doOptions = function($famaxPro){ var customCSS = ""; var headerBackgroundColor,lightheaderBackgroundColor; clearSettings(); //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 handleFamaxDisplay($famaxPro); //Famax Background Color customCSS += ".facebook-pro {background-color: "+settings.famaxBackgroundColor+";}"; customCSS += ".fp-load-more-button:hover {background: linear-gradient(to right,"+settings.famaxBackgroundColor+","+settings.itemBackgroundColor+" 30%);}" //Item Background Color customCSS += ".fp-list-title select, .fp-item, .fp-load-more-button, .fp-channel-search {background-color: "+settings.itemBackgroundColor+";}" //Likes Color customCSS += ".fp-view-string{color: "+settings.likesColor+";}"; //Header Color customCSS += ".fp-grid .fp-view-bucket-seen {color: "+settings.headerBackgroundColor+"; background-color:inherit;}"; customCSS += ".fp-loader {border-color: "+settings.headerBackgroundColor+";}"; customCSS += ".fp-load-more-button{box-shadow: 0 0px 2px rgba(0,0,0,.2), -0.2em 0px 0px 0px "+settings.headerBackgroundColor+";}"; customCSS += ".fp-list-title select{box-shadow: 0 1px 2px rgba(0,0,0,.2), -0.2em 0px 0px 0px "+settings.headerBackgroundColor+";}"; customCSS += ".fp-header,.fp-cta-button,.fp-showing-album-name{background-color:"+settings.headerBackgroundColor+"; color:"+settings.headerTextColor+";}"; customCSS += ".fp-title a, .fp-popup-title a, .fp-comment span{color:"+settings.headerBackgroundColor+"; }"; customCSS += ".fp-popup-button:hover, .fp-add-comment-button:hover, .fp-post-like-button:hover, .fp-view-string {background-color: "+settings.headerBackgroundColor+"; box-shadow: 0px 0px 0px 1px "+settings.headerBackgroundColor+";}"; //Title color customCSS += ".fp-title, .fp-views-per-day {color: "+settings.titleColor+";}"; customCSS += ".fp-date-bucket{color: "+settings.titleColor+";}"; //customCSS += ".fp-tab-container{box-shadow: -0.2em 0px 0px 0px "+settings.likesColor+";}"; customCSS += ".fp-selected-tab:after{background-color:"+settings.titleColor+";}"; customCSS += ".fp-item, .fp-loader {color:"+settings.titleColor+";}"; //Controls Text Color customCSS += ".fp-list-title select, .fp-load-more-button, .fp-channel-search {color:"+settings.controlsTextColor+";}"; customCSS += ".fp-tab-container{color: "+settings.controlsTextColor+";}"; headerBackgroundColor = settings.headerBackgroundColor; if(headerBackgroundColor.indexOf("rgb")!=-1) { //convert rgb format to rgba format lightheaderBackgroundColor = headerBackgroundColor.substring(0,headerBackgroundColor.length-1) + ",0.5)"; lightheaderBackgroundColor = lightheaderBackgroundColor.replace("rgb","rgba"); customCSS += ".fp-views-per-day{border-color: "+lightheaderBackgroundColor+";}"; customCSS += ".fp-load-more-button:hover {background: linear-gradient(to right,"+lightheaderBackgroundColor+","+settings.itemBackgroundColor+" 20%);}" } //font size styles customCSS += ".fp-title {font-size:"+settings.titleFontSize+"em !important; font-weight:"+settings.titleFontWeight+" !important;}"; customCSS += ".fp-date-bucket,.fp-count-string,.fp-view-string {font-size:"+settings.likesDateFontSize+"em !important;}"; customCSS += ".famax-pro,.mfp-container{font-size: "+settings.baseFontSize+";}"; //font-family customCSS += ".fp-item,.fp-callout,.fp-offer{font-family:"+settings.generalFontFamily+";}"; customCSS += ".fp-title,.fp-offer-title,.fp-callout-title {font-family:"+settings.titleFontFamily+";}"; //hiding options if(settings.hideHeader) { customCSS += " .fp-header {display:none;}"; } if(settings.hideTabs) { customCSS += " .fp-tab-container {display:none;}"; } if(settings.hideSorting) { customCSS += " #fp-sort-order {display:none;}"; } if(settings.hideLoadingMechanism) { customCSS += " .fp-load-more-button, .fp-previous-button, .fp-next-button{display:none;}"; customCSS += " .fp-cta-button{width:100%;}"; } if(settings.hideCtaButton) { customCSS += " .fp-cta-button{display:none;}"; customCSS += " .fp-load-more-button {width: 100%;} .fp-previous-button, .fp-next-button {width: 48.5%;}"; } if(settings.hidePopupDetails) { customCSS += ".fp-popup-details {display:none;}"; settings.popupAlignTop = false; } if(settings.hideThumbnailLikesCommentsDate) { customCSS += ".fp-separator-for-grid, .fp-likes, .fp-comments, .fp-date-bucket {display: none !important;}"; settings.popupAlignTop = false; } if(settings.hidePageAboutInfo) { customCSS += ".fp-about-info, .fp-website {display:none;}"; } //popup image max height try{ var maxHeight = $(window.top).height()*0.85; customCSS += ".mfp-img{max-height:"+maxHeight+"px !important;}"; } catch(e){ //must be in an iframe.. } //remove styles if already existing $(".facebook-added-styles").remove(); //add new styles $("body").append(""); }, clearSettings = function(){ settings.postList = []; settings.nextPageToken = null; settings.clearListOnDisplay = true; settings.searchFlag = false; }, initHeader = function($famaxPro){ var identifierJSON; identifierJSON = sanitizeLink("facebook-page-posts",settings.fanPageLinkForHeader); if(identifierJSON.identifier=="error") { alert("\n\nFacebook Page Link should be of the format: \nhttp://www.facebook.com/adidas \n\nPlease contact us via comments to get your page link in this format :)"); return; } getPageDetails(identifierJSON.identifier,null,$famaxPro); }, displayHeader = function(pageDetails,$famaxPro){ var pageId = pageDetails.id; var pageName = pageDetails.name; var pageLikes = pageDetails.likes; var pageTalkingAbout = pageDetails.talking_about_count; var pageBackgroundImage; if(null!=pageDetails.cover) { pageBackgroundImage = pageDetails.cover.source; } else { pageBackgroundImage=""; } var pageLink = "https://www.facebook.com/"+pageId; var pageThumbnail = pageDetails.picture.data.url; var pageAbout = pageDetails.about; var pageWebsite = pageDetails.website; var $facebookHeader = $famaxPro.find(".fp-header"); var pageThumbnailHTML = "
"; var pageLikeBoxHTML = ""; var pageDetailsHTML = "
"+pageName+"
"+pageLikeBoxHTML+"
"; var aboutDetails = "
"+pageAbout+"
"; var pageWebsite = "
"+pageWebsite+"
"; $facebookHeader.append("
"+pageThumbnailHTML+pageDetailsHTML+aboutDetails+pageWebsite+"
"); if(settings.showCoverImage) { $famaxPro.find(".fp-header").css("background-image","url("+pageBackgroundImage+")"); } settings.fanPageId = pageId; }, createTabs = function($famaxPro) { var identifierJSON,source,name,link,selected,channelId,channelUser,playlistId,tabId; var $facebookTabContainer = $famaxPro.find(".fp-tab-container"); for(var i=0; i"+name+""); if(source=="facebook-page-posts" || source=="facebook-page-photos" || source=="facebook-page-videos" || source=="facebook-page-albums") { //update the tab with page id getPageDetails(identifierJSON.identifier,tabId,$famaxPro); } else if(source=="facebook-album-photos") { //select if default if(settings.defaultTab==name) { $famaxPro.find("#"+tabId).click(); } } else if(source=="") { } } //for loop on tabs ends }, sanitizeLink = function(source,link) { var sanityIndex,pageUser,albumId; var identifierJSON = { identifier :"", identifierType :"" }; //remove trailing slashes link = link.replace(/\/$/, ""); if(source=="facebook-page-posts" || source=="facebook-page-photos" || source=="facebook-page-videos" || source=="facebook-page-albums") { //remove "/?nr" from the end of URL link = link.replace(/\/\?.*/,""); sanityIndex = link.lastIndexOf("/"); if(sanityIndex==-1) { identifierJSON.identifier = "error"; alert("\n\nFacebook Page Link should be of the format: \nhttp://www.facebook.com/adidas \n\nPlease contact us via comments to get your page link in this format :)"); } else { pageUser = link.substring(sanityIndex+1); //remove "." from the page name pageUser = pageUser.replace(/\./g,""); //keep only the last "-part" from the page name if(pageUser.indexOf("-")!=-1) { pageUser = pageUser.substring(pageUser.lastIndexOf("-")+1); } identifierJSON.identifierType = "facebook-page-user"; identifierJSON.identifier = pageUser; } } else if(source=="facebook-album-photos") { sanityIndex = link.indexOf("album_id="); if(sanityIndex==-1) { identifierJSON.identifier = "error"; alert("\n\nFacebook Album Link should be of the format: \nhttps://www.facebook.com/pg/adidas/photos/?tab=album&album_id=1067342993288619 \n\n"); } else { albumId = link.substring(sanityIndex+9); identifierJSON.identifierType = "facebook-album-useid"; identifierJSON.identifier = albumId; } } else if(source=="") { } return identifierJSON; }, getPageDetails = function(pageName,tabId,$famaxPro) { var apiURL = "https://graph.facebook.com/v2.8/"+pageName+"?access_token="+settings.accessToken+"&fields=talking_about_count,cover,likes,name,picture,about,website"; $.ajax({ url: apiURL, type: "GET", async: true, cache: true, dataType: 'json', success: function(response) { if(null==tabId) { displayHeader(response,$famaxPro); } else { updateTabs(tabId,response,$famaxPro); } }, error: function(html) { alert("Could not load Page Details.."); } }); }, getPagePosts = function(pageId,$famaxPro) { var apiURL, postArray; apiURL = "https://graph.facebook.com/v2.8/"+pageId+"/posts?limit="+settings.maxResults+"&access_token="+settings.accessToken+"&fields=type,message,message_tags,object_id,picture,full_picture,name,story,link,from,comments.limit(1).summary(true),likes.limit(1).summary(true),shares,created_time"; if(settings.nextPageToken!=null) { apiURL = settings.nextPageToken; } $.ajax({ url: apiURL, type: "GET", async: true, cache: true, dataType: 'json', success: function(response) { postArray = createPostObjects(response.data,$famaxPro); handleNextPageToken(response.paging,$famaxPro); displayItems(postArray,$famaxPro); videoDisplayMechanism($famaxPro); }, error: function(html) { } }); }, getPagePhotos = function(pageId,$famaxPro) { var apiURL, postArray; apiURL = "https://graph.facebook.com/v2.8/"+pageId+"/photos/uploaded?limit="+settings.maxResults+"&access_token="+settings.accessToken+"&fields=type,object_id,picture,images,name,name_tags,story,link,from,comments.limit(1).summary(true),likes.limit(1).summary(true),shares,created_time,album"; if(settings.nextPageToken!=null) { apiURL = settings.nextPageToken; } $.ajax({ url: apiURL, type: "GET", async: true, cache: true, dataType: 'json', success: function(response) { postArray = createPhotoObjects(response.data,$famaxPro); handleNextPageToken(response.paging,$famaxPro); displayItems(postArray,$famaxPro); videoDisplayMechanism($famaxPro); }, error: function(html) { } }); }, getPageAlbums = function(pageId,$famaxPro) { var apiURL, postArray; apiURL = "https://graph.facebook.com/v2.8/"+pageId+"/albums?limit="+settings.maxResults+"&access_token="+settings.accessToken+"&fields=cover_photo,description,photo_count,picture,images,name,name_tags,link,from,comments.limit(1).summary(true),likes.limit(1).summary(true),shares,created_time"; if(settings.nextPageToken!=null) { apiURL = settings.nextPageToken; } $.ajax({ url: apiURL, type: "GET", async: true, cache: true, dataType: 'json', success: function(response) { createAlbumObjects(response.data,$famaxPro); }, error: function(html) { } }); }, /* gatherAlbumCoverPhotos = function(albumArray,$famaxPro) { var coverId, coverIdArray = []; for(var i=0;i<=albumArray.length;i++) { coverId = albumArray[i].cover_photo.id; coverIdArray.push(coverId); } getAlbumCoverPhotos(coverIdArray,$famaxPro); }, */ getAlbumCoverPhotos = function(coverIdArray,processesPostArray,$famaxPro) { var apiURL, postArray; apiURL = "https://graph.facebook.com/v2.8?ids="+coverIdArray+"&access_token="+settings.accessToken+"&fields=images"; $.ajax({ url: apiURL, type: "GET", async: true, cache: true, dataType: 'json', success: function(response) { postArray = addCoverImagesToAlbums(response,processesPostArray,$famaxPro); displayAlbums(postArray,$famaxPro); registerAlbumNavigation($famaxPro); }, error: function(html) { } }); }, getPageVideos = function(pageId,$famaxPro) { var apiURL, postArray; apiURL = "https://graph.facebook.com/v2.8/"+pageId+"/videos?limit="+settings.maxResults+"&access_token="+settings.accessToken+"&fields=object_id,picture,permalink_url,thumbnails,description,link,from,comments.limit(1).summary(true),likes.limit(1).summary(true),shares,created_time"; if(settings.nextPageToken!=null) { apiURL = settings.nextPageToken; } $.ajax({ url: apiURL, type: "GET", async: true, cache: true, dataType: 'json', success: function(response) { postArray = createVideoObjects(response.data,$famaxPro); handleNextPageToken(response.paging,$famaxPro); displayItems(postArray,$famaxPro); videoDisplayMechanism($famaxPro); }, error: function(html) { } }); }, getAlbumPhotos = function(albumId,$famaxPro) { var apiURL, postArray; apiURL = "https://graph.facebook.com/v2.8/"+albumId+"/photos?limit="+settings.maxResults+"&access_token="+settings.accessToken+"&fields=type,object_id,picture,images,name,name_tags,story,link,from,comments.limit(1).summary(true),likes.limit(1).summary(true),shares,created_time,album"; if(settings.nextPageToken!=null) { apiURL = settings.nextPageToken; } $.ajax({ url: apiURL, type: "GET", async: true, cache: true, dataType: 'json', success: function(response) { postArray = createPhotoObjects(response.data,$famaxPro); handleNextPageToken(response.paging,$famaxPro); displayItems(postArray,$famaxPro); videoDisplayMechanism($famaxPro); }, error: function(html) { } }); }, getPostLikes = function(postId,$famaxPro) { var apiURL, postArray; apiURL = "https://graph.facebook.com/v2.8/"+postId+"/likes?access_token="+settings.accessToken+"&limit=6&fields=name,pic_square"; $.ajax({ url: apiURL, type: "GET", async: true, cache: true, dataType: 'json', success: function(response) { displayPostLikes(response.data,$famaxPro); }, error: function(html) { } }); }, getPostComments = function(postId,$famaxPro) { var apiURL, postArray; apiURL = "https://graph.facebook.com/v2.8/"+postId+"/comments?access_token="+settings.accessToken+"&limit=6&fields=from,message"; $.ajax({ url: apiURL, type: "GET", async: true, cache: true, dataType: 'json', success: function(response) { displayPostComments(response.data,$famaxPro); }, error: function(html) { } }); }, handleNextPageToken = function(token,$famaxPro) { if(token!=null) { token = token.next; settings.nextPageToken = token; $famaxPro.find(".fp-load-more-button").html(settings.loadMoreText).removeClass("fp-loading"); } else { $famaxPro.find('.fp-load-more-button').html("All Done"); } }, createPostObjects = function(postArray,$famaxPro) { var processesPostArray = []; var proSnippet; for(var i=0; i"; commentStringHTML = "
"+comments+"
"; dateboxHTML = "
"+date+"
"; itemboxHTML = "
"+playIconHTML+"

"+message+"
"+"
"+likeStringHTML+commentStringHTML+dateboxHTML+"
"; containerHTML += "
"+itemboxHTML+"
"; } $facebookContainer.append(containerHTML); }, displayAlbums = function(postArray,$famaxPro) { var viewboxHTML, dateboxHTML, trendBoxHTML, itemboxHTML, playIconHTML, countDisplayHTML, countStringHTML, sortOrder, containerHTML=""; var image, likes, comments, viewsPerDay, message, date, link, id, popupLink, popupClass, type, photoCount; var sortOrder = $famaxPro.find("#fp-sort-order").val(); var $facebookContainer = $famaxPro.find(".fp-item-container"); var list = postArray; //list = settings.postList if(sortOrder=="popular-first") { list.sort(popularFirstComparator); } else if(sortOrder=="recent-first") { list.sort(latestFirstComparator); } if(settings.clearListOnDisplay) { clearList($famaxPro); } for(var count=0; count"; countDisplayHTML = "
"+photoCount+"
PHOTOS


"; dateboxHTML = "
"+date+"
"; itemboxHTML = "
"+playIconHTML+"

"+countDisplayHTML+"
"+message+"
"+"
"+countStringHTML+dateboxHTML+"
"; containerHTML += "
"+itemboxHTML+"
"; } $facebookContainer.append(containerHTML); }, displayPopupData = function($baseElement,$famaxPro) { var popupTitleHTML,popupDescriptionHTML,popupMoreHTML,postLikesHTML,postCommentsHTML,postAddCommentHTML,facebookShareHTML,facebookLikeHTML,facebookCommentHTML,googleShareHTML,twitterShareHTML,addLikeButton; var postId, title, likes, description, link, encodedLink; var $popupBox,$photoLink; setTimeout(function(){ $popupBox = $("#fp-popup-details"); $photoLink = $(".fp-photo-link"); postId = $baseElement.attr("id"); title = $baseElement.find(".fp-title").html(); likes = $baseElement.find(".fp-view-string span").html(); //description = $baseElement.find(".yl-description").html(); link = $baseElement.find(".fp-focus").data("link"); encodedLink = encodeURIComponent(link); addLikeButton = "
"; popupTitleHTML = "
"+title+"
"; postLikesHTML = "
"+likes+"
likes
"+addLikeButton+"
"; postAddCommentHTML = "
Post
"; postCommentsHTML = "
"; /* facebookLikeHTML = "
"; facebookShareHTML = "
"; facebookCommentHTML = "
"; */ facebookShareHTML = "
"; twitterShareHTML = "
"; googleShareHTML = "
"; // $popupBox.empty(); $popupBox.append("
"+popupTitleHTML+postLikesHTML+postAddCommentHTML+postCommentsHTML+"
"+"
"+facebookShareHTML+twitterShareHTML+googleShareHTML+"
"); getPostLikes(postId); getPostComments(postId); if($popupBox.width()<500) { $("body").addClass("fp-simple-popup"); } else { $("body").removeClass("fp-simple-popup"); } if($photoLink!=null) { $photoLink.html("").unwrap().wrap("
"); } }, 100); }, displayPostLikes = function(likeArray, $famaxPro) { for(var i=0; i"); } }, displayPostComments = function(commentArray, $famaxPro) { var userImage; for(var i=0; i
"+commentArray[i].from.name+"
"+commentArray[i].message+"
"); } }, clearList = function($famaxPro) { $famaxPro.find(".fp-item-container").empty(); }, videoDisplayMechanism = function($famaxPro){ if(settings.itemDisplayMode=="popup") { registerPopup($famaxPro); } else { registerLinkToFacebook(".fp-focus",$famaxPro); } registerLinkToFacebook(".mfp-link",$famaxPro); }, registerPopup = function($famaxPro) { var currentTabId; $famaxPro.find(".mfp-image,.mfp-iframe").magnificPopup({ gallery: { enabled:true }, image: { markup: '
'+ '
'+ '
'+ '
'+ '
'+ ''+ '
', verticalFit: true, // Fits image in area vertically }, iframe:{ markup: '
'+ '
'+ ''+ '
'+ '
', patterns: { facebook : { index: 'facebook.com/', //id: '/videos/', //src: 'http://www.facebook.com/video/embed?video_id=%id%&autoplay=1' id: null, src: 'https://www.facebook.com/plugins/video.php?href=%id%&show_text=false&width=1000' }, } }, callbacks: { markupParse: function(template, values, item) { // Triggers each time when content of popup changes $('.famax-fb-fix').remove(); if(item.src.indexOf("facebook.com")!=-1 && item.src.indexOf("/videos/")!=-1 && null!=item.el) { var naturalWidth = item.el[0].clientWidth; var naturalHeight = item.el[0].clientHeight; var aspectRatio = naturalHeight/naturalWidth; var calculatedHeight = naturalHeight; var calculatedWidth = naturalWidth; calculatedHeight=430; calculatedWidth = calculatedHeight/aspectRatio; var style = $(''); $('html > head').append(style); } }, change: function() { // Triggers each time when content of popup changes var $baseElement = $(this.currItem.el[0].offsetParent); displayPopupData($baseElement,$famaxPro); } }, closeBtnInside:true, preloader: true, alignTop: settings.popupAlignTop, closeOnContentClick: false, closeOnBgClick: false, enableEscapeKey: true, }); }, registerLinkToFacebook = function(itemIdentifier,$famaxPro) { $famaxPro.find(itemIdentifier).each(function(i,v){ var $focusElement = $(v); var link = $focusElement.data("link"); $focusElement.wrap(""); }); }, registerAlbumNavigation = function($famaxPro) { $famaxPro.find(".fp-focus").click(function(){ var $item = $(this).parent(".fp-item"); var albumId = $item.attr("id"); var albumTitle = $item.find(".fp-title").text(); var $currentTab = $famaxPro.find(".fp-selected-tab"); var $albumTab = $famaxPro.find(".fp-showing-album-name"); //remove selected tab $currentTab.removeClass("fp-selected-tab"); //set last tab id settings.previousTabId = $currentTab.attr("id"); //set playlist name $albumTab.data("album-name",albumTitle).attr("id","facebook-album-photos-"+albumId).addClass("fp-playlist-tab"); handlePlaylistTabClick($albumTab,$famaxPro); }); }, popularFirstComparator = function(a,b) { return b.likes - a.likes; }, latestFirstComparator = function(a,b) { return (new Date(b.date).getTime()) - (new Date(a.date).getTime()); }, handleSortOrders = function($famaxPro) { var seenVideos = []; $('#fp-sort-order').change(function() { showLoader($famaxPro); //not needed as list is cleared in show loader //clearList($famaxPro); displayItems(settings.postList,$famaxPro); videoDisplayMechanism($famaxPro); }); $famaxPro.find("#fp-sort-order").val(settings.defaultSortOrder); }, handleTabs = function ($famaxPro) { $famaxPro.on("click",".fp-tab",function() { handleTabClick($(this),$famaxPro); }); $famaxPro.on("click",".fp-playlist-tab",function() { //go back to last tab var previousTabId = settings.previousTabId; $famaxPro.find("#"+previousTabId).click(); }); }, handleTabClick = function($tab,$famaxPro) { clearSettings(); showLoader($famaxPro); //add selected tab class to current tab $famaxPro.find(".fp-tab").removeClass("fp-selected-tab"); $tab.addClass("fp-selected-tab"); displayTabItems($famaxPro); }, handlePlaylistTabClick = function($tab,$famaxPro) { var albumName; clearSettings(); showLoader($famaxPro); //add selected tab class to current tab $famaxPro.find(".fp-tab").removeClass("fp-selected-tab"); $tab.addClass("fp-selected-tab"); albumName = $tab.data("album-name"); $tab.append(" Showing album: "+albumName).show(); displayTabItems($famaxPro); }, displayTabItems = function($famaxPro) { //get selected tab and handle the tab click var tabId = $famaxPro.find(".fp-selected-tab").attr("id"); var identifier = tabId.substring(tabId.indexOf("-",17)+1); if(tabId.indexOf("facebook-page-posts")!=-1) { getPagePosts(identifier,$famaxPro); } else if(tabId.indexOf("facebook-page-photos")!=-1) { getPagePhotos(identifier,$famaxPro); } else if(tabId.indexOf("facebook-page-videos")!=-1) { getPageVideos(identifier,$famaxPro); } else if(tabId.indexOf("facebook-page-albums")!=-1) { getPageAlbums(identifier,$famaxPro); } else if(tabId.indexOf("facebook-album-photos")!=-1) { getAlbumPhotos(identifier,$famaxPro); } }, handleSearch = function($famaxPro) { var searchText; $famaxPro.on('keyup','.fp-channel-search-input', function (e) { if (e.keyCode == 13) { clearSettings(); showLoader($famaxPro); displaySearchItems($famaxPro); return false; } }); }, displaySearchItems = function($famaxPro) { var searchText; //set search flag as sorting needs to be doen on relevance settings.searchFlag = true; searchText = $famaxPro.find('.fp-channel-search-input').val().replace(/ /g,"%20"); getSearchVideos(searchText,$famaxPro); }, handlePopupButtons = function($famaxPro) { /*$("body").on("click",".fp-video-iframe-hover",function() { $(this).remove(); //$(".mfp-content .mfp-iframe").click(); return true; });*/ $(document).on("click", ".fp-popup-button.fp-like", function(){ handleFacebookLikes(); }); $(document).on("click", ".fp-add-comment-button", function(){ handleFacebookComments(); }); $("body").on("click",".mfp-wrap",function(e){ if (e.target.id == "fp-popup-details" || $(e.target).parents("#fp-popup-details").length>0 || e.target.tagName=="BUTTON") { //do nothing } else { $.magnificPopup.close(); } }); //$("body").on("click",".fp-popup-details",function(){ return false; }); }, handleLoadMoreButton = function($famaxPro) { $famaxPro.on('click','.fp-load-more-button', function(){ var tabId; //do nothing if next token is not present if(settings.nextPageToken==null) { return; } //do not clear list during load mores settings.clearListOnDisplay = false; $(this).html("Loading..").addClass("fp-loading"); if(settings.searchFlag) { //displaySearchItems($famaxPro); } else { displayTabItems($famaxPro); } }); }, handleFamaxDisplay = function($famaxPro) { /* if(settings.famaxDisplayMode=="double-list") { if($famaxPro.width()>=settings.responsiveBreakpoints[1]) { $famaxPro.addClass("fp-double-list").removeClass("fp-grid"); } else if($famaxPro.width()Famax
is loading..
"); $famaxPro.find(".fp-showing-album-name").empty().hide(); }, saveSeenVideos = function($famaxPro) { var seenVideos = []; $famaxPro.find(".fp-seen").each(function(){ seenVideos.push($(this).attr("id")); }); return seenVideos; }, highlightSeenVideos = function(seenVideos,$famaxPro) { for(var k=seenVideos.length;k>=0;k--) { $famaxPro.find("#"+seenVideos[k]).addClass("fp-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; }, convertToRelativeDate = function (timestamp) { var dateDiffMS, dateDiffHR, dateDiffDY, dateDiffMH, dateDiffYR; if(null==timestamp||timestamp==""||timestamp=="undefined") return "?"; //safari Nan Bug fix var a = timestamp.split(/[^0-9]/); timestamp = new Date (a[0],a[1]-1,a[2],a[3],a[4],a[5] ); dateDiffMS = Math.abs(new Date() - new Date(timestamp)); console.log(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"; } } }, processMessage = function(message,message_tags) { var tag, id, spotArray, replaceLink; if(null==message) { return ""; } message = message.replace(/"/g, "'"); message = message.replace(/\n/g,"
"); //replace links spotArray = message.match(/(http(s)*:\/\/|www\.).+?(\s|\n|$)/g); if(null!=spotArray) { for(var i=0;i"+spotArray[i]+""); } } //replace hahstags //spotArray = message.match(/#\w+\s*/g); spotArray = message.match(/#\w+?(\s|\n|$|\.)/g); if(null!=spotArray) { for(var i=0;i"+spotArray[i]+""); } } //replace message tags if(null==message_tags) { return message; } for(var i=0; i"+tag+""); } return message; }, handleFacebookLikes = function() { var postId = $(".fp-popup-button.fp-like").data("postid"); if(settings.famaxLoggedInUser.token==null) { famaxLoginToFacebook("like",postId); } else { famaxPostLike(postId); } }, handleFacebookComments = function() { var postId = $(".fp-add-comment-button").data("postid"); if(settings.famaxLoggedInUser.token==null) { famaxLoginToFacebook("comment",postId); } else { famaxPostComment(postId); } }, famaxPostLike = function(postId) { var postCommentURL = "https://graph.facebook.com/v2.4/"+postId+"/likes"; $.ajax({ url: postCommentURL, type: 'post', crossDomain: true, data: { access_token:settings.famaxLoggedInUser.token }, //contentType: "application/atom+xml", beforeSend: function(xhr){ xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); }, success: function (data, status) { $(".fp-post-likes").prepend("") }, error: function (xhr, desc, err) { alert("Could not add Like"); console.log(err); } }); }, famaxPostComment = function(postId) { var postCommentURL = "https://graph.facebook.com/v2.4/"+postId+"/comments"; var comment = $("#fp-add-comment-text").val(); $.ajax({ url: postCommentURL, type: 'post', crossDomain: true, data: { message:comment, access_token:settings.famaxLoggedInUser.token }, //contentType: "application/atom+xml", beforeSend: function(xhr){ xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); }, success: function (data, status) { $(".fp-post-comments").prepend("
@"+settings.famaxLoggedInUser.name+": "+comment+"
"); $("#fp-add-comment-text").val(""); }, error: function (xhr, desc, err) { alert("Could not add Comment"); console.log(err); } }); }, famaxLoginToFacebook = function(action,postId) { FB.login(function(response) { if (response.status === 'connected') { // Logged into your app and Facebook. settings.famaxLoggedInUser.token = response.authResponse.accessToken; saveUserName(action,postId); } else if (response.status === 'not_authorized') { // The person is logged into Facebook, but not your app. } else { // The person is not logged into Facebook, so we're not sure if // they are logged into this app or not. } }, {scope: 'publish_actions'}); }, saveUserName = function (action,postId) { FB.api('/me', function(response) { settings.famaxLoggedInUser.name = response.name; settings.famaxLoggedInUser.id = response.id; }); FB.api('/me/picture', function(response) { settings.famaxLoggedInUser.picture = response.data.url; if(action=="like") { famaxPostLike(postId); } else if(action=="comment") { famaxPostComment(postId); } }); }, handleFacebookLogin = function(){ //Facebook Login script $.getScript( "http://connect.facebook.net/en_US/sdk.js" ) .done(function( script, textStatus ) { FB.init({ appId : settings.appId, cookie : true, xfbml : false, version : 'v2.8' }); }) .fail(function( jqxhr, settings, exception ) { }); }; $.fn.famaxPro=function(options) { var $famaxPro=this; settings = $.extend(settings,options); init($famaxPro); doOptions($famaxPro); initHeader($famaxPro); handleTabs($famaxPro); createTabs($famaxPro); handleLoadMoreButton($famaxPro); handlePopupButtons($famaxPro); handleSortOrders($famaxPro); handleResize($famaxPro); handleFacebookLogin($famaxPro); return this; } })(jQuery);