Created
October 5, 2016 16:51
-
-
Save caionorder/920cb93da85546e2f38094455265b9ea to your computer and use it in GitHub Desktop.
This file contains hidden or 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
window.fbAsyncInit = function() { | |
FB.init({ | |
appId : '1791499064407302', | |
xfbml : true, | |
version : 'v2.7' | |
}); | |
FB.api( | |
'/874332389305736/feed', | |
'GET', | |
{ | |
access_token : "1791499064407302|mPURG-tea6uQEDVg2PgcjlI0B5g", | |
'fields':'full_picture,message,link,created_time,type' | |
}, | |
function(response) { | |
facebookItem(response); | |
// Insert your code here | |
} | |
); | |
}; | |
function facebookItem($obj){ | |
$total = $obj.data.length; | |
$html = ''; | |
for (var i = 0; i < $total; i++) { | |
$msg = $obj.data[i].message; | |
$pic = $obj.data[i].full_picture; | |
$link = $obj.data[i].link; | |
$date = formataData($obj.data[i].created_time); | |
$type = $obj.data[i].type; | |
if($type == 'photo' && $msg){ | |
$msg = truncar($msg,250); | |
$html += '<div class="card-item">' | |
+'<a class="photo" href="'+$link+'" target="_blank" style="background-image:url('+$pic+')"></a>' | |
+'<p class="message">'+$msg+'</p>' | |
+'<hr>' | |
+'<p>' | |
+' Postado '+$date+' <a href="'+$link+'" target="_blank"><i class="fa fa-facebook" aria-hidden="true"></i></a>' | |
+'</p>' | |
+'</div>'; | |
} | |
} | |
$('.cards').append($html); | |
} | |
function truncar(texto,limite){ | |
if(texto.length>limite){ | |
limite--; | |
last = texto.substr(limite-1,1); | |
while(last!=' ' && limite > 0){ | |
limite--; | |
last = texto.substr(limite-1,1); | |
} | |
last = texto.substr(limite-2,1); | |
if(last == ',' || last == ';' || last == ':'){ | |
texto = texto.substr(0,limite-2) + '...'; | |
} else if(last == '.' || last == '?' || last == '!'){ | |
texto = texto.substr(0,limite-1); | |
} else { | |
texto = texto.substr(0,limite-1) + '...'; | |
} | |
} | |
return texto; | |
} | |
function formataData($obj){ | |
var date1 = new Date($obj); | |
var date2 = new Date(); | |
var diferenca = Math.abs(date2.getTime() - date1.getTime()); | |
var dias = Math.ceil(diferenca / (1000 * 3600 * 24)); | |
if(dias > 0){ | |
return dias+' dias atrás'; | |
} else { | |
return 'hoje'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment