Last active
August 29, 2015 14:27
-
-
Save joshuarule/ebabc05ca35e9cd0b4c4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
facebookHelper.prototype.getMedia = function (post) { | |
console.log(post.type); | |
console.log(post.caption); | |
var imageUrl = post.type == "link" ? (post.picture ? this.cleanImageUrl(post.picture.match(/(url=)(.+)$/)[2]) : null) : (this.fbFeedUrl + "{objectId}/picture?type=normal&redirect=true&access_token={token}" | |
.replace("{objectId}", post.object_id) | |
.replace("{token}", this.accessToken)); | |
if (post.type == "link" || post.type == "photo" || post.type == "event") { | |
return imageUrl ? this.imgTemplate.replace(/{url}/g, imageUrl).replace(/{description}/g, post.description) : "" | |
+ (post.type == "link" ? | |
this.linkTemplate.replace(/{linkText}/g, post.name ? post.name : post.story).replace(/{href}/g, post.link) + (post.description ? this.descriptionTemplate.replace(/{description}/g, post.description) : '') | |
: "" | |
); | |
} | |
// videos that have no caption | |
else if (post.type == "video" && post.caption == undefined) { | |
return imageUrl ? this.imgTemplate.replace(/{url}/g, imageUrl).replace(/{description}/g, post.description) : "" | |
+ (post.type == "link" ? | |
this.linkTemplate.replace(/{linkText}/g, post.name ? post.name : post.story).replace(/{href}/g, post.link) + (post.description ? this.descriptionTemplate.replace(/{description}/g, post.description) : '') | |
: "" | |
); | |
} | |
// any video that the caption isn't soundcloud | |
else if (post.type == "video" && post.caption != "soundcloud.com") { | |
var videoId = post.link.split('/'); | |
videoId = videoId[videoId.length - 1]; | |
return this.videoTemplate.replace(/{videoId}/g, videoId) | |
} else { | |
return this.soundCloudTemplate.replace(/{soundCloudUrl}/g, this.getSoundCloudUrl(post.source)) | |
} | |
} | |
facebookHelper.prototype.cleanImageUrl = function (url) { | |
var imageUrl = decodeURIComponent(url); | |
return (imageUrl.indexOf('&') != -1 ? imageUrl.split('&')[0] : imageUrl); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment