UNPKG

aping-plugin-facebook

Version:
8 lines 10.6 kB
/** @name: aping-plugin-facebook @version: 0.7.8 (28-01-2016) @author: Jonathan Hornung @url: https://github.com/JohnnyTheTank/apiNG-plugin-facebook @license: MIT */ "use strict";angular.module("jtt_aping_facebook",["jtt_facebook"]).directive("apingFacebook",["apingFacebookHelper","apingUtilityHelper","facebookFactory","facebookPagesImages",function(a,b,c,d){return{require:"?aping",restrict:"A",replace:"false",link:function(e,f,g,h){var i=h.getAppSettings(),j=b.parseJsonFromAttributes(g.apingFacebook,a.getThisPlatformString(),i);j.forEach(function(e){var f={model:i.model,showAvatar:e.showAvatar||!1};"undefined"!=typeof i.getNativeData?f.getNativeData=i.getNativeData:f.getNativeData=!1;var g={page:e.page,access_token:b.getApiCredentials(a.getThisPlatformString(),"access_token")};if("undefined"!=typeof e.items?g.limit=e.items:g.limit=i.items,0===g.limit||"0"===g.limit)return!1;if((g.limit<0||isNaN(g.limit))&&(g.limit=void 0),g.limit>100&&(g.limit=100),e.page)switch(i.model){case"social":f.showAvatar===!0||"true"===f.showAvatar?c.getPageById({page:g.page,access_token:g.access_token}).then(function(b){b&&b.data&&b.data.id&&b.data.cover&&b.data.cover.source&&(d[b.data.id]=b.data.cover.source),c.getPostsFromPageById(g).then(function(b){b&&h.concatToResults(a.getObjectByJsonData(b,i))})}):c.getPostsFromPageById(g).then(function(b){b&&h.concatToResults(a.getObjectByJsonData(b,i))});break;case"video":f.showAvatar===!0||"true"===f.showAvatar?c.getPageById({page:g.page,access_token:g.access_token}).then(function(b){b&&b.data&&b.data.id&&b.data.cover&&b.data.cover.source&&(d[b.data.id]=b.data.cover.source),c.getVideosFromPageById(g).then(function(b){b&&h.concatToResults(a.getObjectByJsonData(b,i))})}):c.getVideosFromPageById(g).then(function(b){b&&h.concatToResults(a.getObjectByJsonData(b,i))});break;case"image":c.getPhotosFromPageById(g).then(function(b){b&&h.concatToResults(a.getObjectByJsonData(b,i))});break;case"event":f.showAvatar===!0||"true"===f.showAvatar?c.getPageById({page:g.page,access_token:g.access_token}).then(function(b){b&&b.data&&b.data.id&&b.data.cover&&b.data.cover.source&&(d[b.data.id]=b.data.cover.source),c.getEventsFromPageById(g).then(function(b){b&&h.concatToResults(a.getObjectByJsonData(b,i))})}):c.getEventsFromPageById(g).then(function(b){b&&h.concatToResults(a.getObjectByJsonData(b,i))})}})}}}]),angular.module("jtt_aping_facebook").service("apingFacebookHelper",["apingModels","apingTimeHelper","apingUtilityHelper","facebookPagesImages",function(a,b,c,d){this.getThisPlatformString=function(){return"facebook"},this.getThisPlatformLink=function(){return"https://facebook.com/"},this.getRatioFromFormatObject=function(a){var b={width:void 0,height:void 0};return"undefined"!=typeof a&&a.constructor===Array?(angular.forEach(a,function(a,c){"undefined"!=typeof a.filter&&"native"===a.filter&&("undefined"!=typeof a.width&&(b.width=a.width),"undefined"!=typeof a.height&&(b.height=a.height))}),b):void 0},this.getDifference=function(a,b){return a>b?a-b:b-a},this.getImagesFromArray=function(a,b){angular.isUndefined(b)&&(b="source");var c=this,d={thumb_url:void 0,thumb_width:void 0,thumb_height:void 0,img_url:void 0,img_width:void 0,img_height:void 0,native_url:void 0,native_width:void 0,native_height:void 0};return a.constructor===Array&&angular.forEach(a,function(a,e){angular.isDefined(a[b])&&(angular.isUndefined(d.thumb_url)?(d.thumb_url=a[b],d.thumb_width=a.width,d.thumb_height=a.height):c.getDifference(d.thumb_width,200)>c.getDifference(a.width,200)&&a.width>=200&&(d.thumb_url=a[b],d.thumb_width=a.width,d.thumb_height=a.height),angular.isUndefined(d.img_url)?(d.img_url=a[b],d.img_width=a.width,d.img_height=a.height):c.getDifference(d.img_width,700)>c.getDifference(a.width,700)&&(d.img_url=a[b],d.img_width=a.width,d.img_height=a.height),angular.isUndefined(d.native_url)?(d.native_url=a[b],d.native_width=a.width,d.native_height=a.height):a.width>d.native_width&&(d.native_url=a[b],d.native_width=a.width,d.native_height=a.height))}),d},this.getObjectByJsonData=function(a,b){var c=[];if(a){var d=this;a.data&&a.data.data&&angular.forEach(a.data.data,function(a,e){var f;f=b.getNativeData===!0||"true"===b.getNativeData?a:d.getItemByJsonData(a,b),f&&c.push(f)})}return c},this.getItemByJsonData=function(a,b){var c={};if(a&&b.model)switch(b.model){case"social":c=this.getSocialItemByJsonData(a,b);break;case"video":c=this.getVideoItemByJsonData(a,b);break;case"image":c=this.getImageItemByJsonData(a,b);break;case"event":c=this.getEventItemByJsonData(a,b);break;default:return!1}return c},this.getSocialItemByJsonData=function(c,e){var f=a.getNew("social",this.getThisPlatformString());switch(angular.extend(f,{blog_name:c.from.name,blog_id:c.from.id,blog_link:this.getThisPlatformLink()+c.from.id+"/",intern_type:c.type,intern_id:c.id,thumb_url:c.picture,img_url:c.full_picture,native_url:c.full_picture,timestamp:b.getTimestampFromDateString(c.created_time,1e3,36e5)}),f.date_time=new Date(f.timestamp),c.type){case"photo":f.type="image",f.post_url=c.link,f.text=c.message;break;case"status":f.type="post";break;case"link":f.type="link",f.post_url=this.getThisPlatformLink()+c.id+"/",f.content_url=c.link,f.caption=c.name;break;case"video":f.type="video",c.name&&(f.caption=c.name);break;case"event":f.type="event",f.text=c.description,f.caption=c.caption||c.name||void 0}return f.text||(f.text=c.message),f.text||(f.text=c.name),f.post_url||(c.id?f.post_url=this.getThisPlatformLink()+c.id+"/":f.post_url=c.link),e.showAvatar!==!0&&"true"!==e.showAvatar||f.img_url||d[c.from.id]&&(f.img_url=d[c.from.id]),f},this.getVideoItemByJsonData=function(c,e){var f=a.getNew("video",this.getThisPlatformString());if(angular.extend(f,{blog_name:c.from.name,blog_id:c.from.id,blog_link:this.getThisPlatformLink()+c.from.id+"/",intern_id:c.id,post_url:c.permalink_url,timestamp:b.getTimestampFromDateString(c.created_time,1e3,36e5),text:c.description,markup:c.embed_html||void 0,source:c.source||void 0}),f.date_time=new Date(f.timestamp),"undefined"!=typeof c.length&&(f.length=c.length),"undefined"!=typeof c.format&&c.format.length>0){var g=this.getImagesFromArray(c.format,"picture");g.thumb_width=void 0,g.thumb_height=void 0,g.img_width=void 0,g.img_height=void 0,g.native_width=void 0,g.native_height=void 0,angular.extend(f,g);var h=this.getRatioFromFormatObject(c.format);"undefined"!=typeof h.width&&(f.width=h.width),"undefined"!=typeof h.height&&(f.height=h.height)}return e.showAvatar!==!0&&"true"!==e.showAvatar||f.img_url||d[c.from.id]&&(f.img_url=d[c.from.id]),f},this.getImageItemByJsonData=function(c,d){var e=a.getNew("image",this.getThisPlatformString());if(angular.extend(e,{blog_name:c.from.name,blog_id:c.from.id,blog_link:this.getThisPlatformLink()+c.from.id+"/",intern_id:c.id,post_url:c.link,timestamp:b.getTimestampFromDateString(c.created_time,1e3,36e5),text:c.name||void 0,source:c.images||void 0}),e.date_time=new Date(e.timestamp),c.images.length>0){var f=this.getImagesFromArray(c.images,"source");angular.extend(e,f)}return e},this.getEventItemByJsonData=function(c,e){var f=a.getNew("event",this.getThisPlatformString());return angular.extend(f,{artist_name:c.owner.name,artist_id:c.owner.id,artist_link:this.getThisPlatformLink()+c.owner.id+"/",intern_id:c.id,event_url:this.getThisPlatformLink()+c.owner.id+"_"+c.id+"/",ticket_url:c.ticket_uri||void 0,start_timestamp:b.getTimestampFromDateString(c.start_time,1e3,36e5),end_timestamp:c.end_time?b.getTimestampFromDateString(c.end_time,1e3,36e5):void 0,caption:c.name||void 0,text:c.description||void 0,img_url:c.cover?c.cover.source:void 0}),f.start_timestamp&&(f.start_date_time=new Date(f.start_timestamp)),f.end_timestamp&&(f.end_date_time=new Date(f.end_timestamp)),c.place&&(f.place_name=c.place.name||void 0,c.place.location&&(f.city=c.place.location.city||void 0,f.country=c.place.location.country||void 0,f.latitude=c.place.location.latitude||void 0,f.longitude=c.place.location.longitude||void 0,f.street=c.place.location.street||void 0,f.zip=c.place.location.zip||void 0)),e.showAvatar!==!0&&"true"!==e.showAvatar||f.img_url||d[c.from.id]&&(f.img_url=d[c.from.id]),f}}]),angular.module("jtt_aping_facebook").config(["$provide",function(a){a.value("facebookPagesImages",{})}]),angular.module("jtt_facebook",[]).factory("facebookFactory",["$http","facebookSearchDataService",function(a,b){var c={};return c.getPostsFromPageById=function(c){var d=b.getNew("postsFromPageById",c);return a({method:"GET",url:d.url,params:d.object})},c.getPhotosFromPageById=function(c){var d=b.getNew("photosFromPageById",c);return a({method:"GET",url:d.url,params:d.object})},c.getVideosFromPageById=function(c){var d=b.getNew("videosFromPageById",c);return a({method:"GET",url:d.url,params:d.object})},c.getEventsFromPageById=function(c){var d=b.getNew("eventsFromPageById",c);return a({method:"GET",url:d.url,params:d.object})},c.getPageById=function(c){var d=b.getNew("pageById",c);return a({method:"GET",url:d.url,params:d.object})},c}]).service("facebookSearchDataService",function(){this.getApiBaseUrl=function(a){var b;return b=a&&"undefined"!=typeof a.version?a.version+"/":"v2.5/","https://graph.facebook.com/"+b},this.fillDataInObjectByList=function(a,b,c){return angular.forEach(c,function(c,d){"undefined"!=typeof b[c]&&(a.object[c]=b[c])}),a},this.getNew=function(a,b){var c={object:{access_token:b.access_token||void 0},url:""};switch("undefined"!=typeof b.limit&&(c.object.limit=b.limit),a){case"postsFromPageById":c.object.fields="id,message,story,created_time,full_picture,from,link,description,type,shares,source,picture,object_id",c=this.fillDataInObjectByList(c,b,["__paging_token","until","since","__previous"]),c.url=this.getApiBaseUrl()+b.page+"/posts?";break;case"photosFromPageById":c.object.fields="id,created_time,from,link,picture,album,name,images,width,height",c=this.fillDataInObjectByList(c,b,["before","after"]),c.url=this.getApiBaseUrl()+b.page+"/photos?";break;case"videosFromPageById":c.object.fields="id,created_time,from,description,source,picture,format,title,embed_html,permalink_url,length",c=this.fillDataInObjectByList(c,b,["before","after"]),c.url=this.getApiBaseUrl()+b.page+"/videos?";break;case"eventsFromPageById":c.object.fields="id,owner,description,picture{url},end_time,name,cover,category,place,start_time,ticket_uri",c=this.fillDataInObjectByList(c,b,["before","after"]),c.url=this.getApiBaseUrl()+b.page+"/events?";break;case"pageById":c.object.fields="cover,link,picture{url},username,name",c.object.limit=void 0,c.url=this.getApiBaseUrl()+b.page+"/"}return c}});