Skip to content

Instantly share code, notes, and snippets.

@peterk
Created September 15, 2015 15:23
Show Gist options
  • Save peterk/604ef8a70b363e983c21 to your computer and use it in GitHub Desktop.
Save peterk/604ef8a70b363e983c21 to your computer and use it in GitHub Desktop.
Tweaks
Denna rade görs om:
var twitterBtn = '<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>';
till:
var twitterBtn = '';
Hela detta block
<script type="text/javascript" charset="utf-8">
<!--
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1&appId=372059436147227";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
//-->
</script>
Raderna
getLatestTweet(TwitterName);
getLatestFacebookUpdate(FacebookId, AccessToken);
Hela detta block:
var getLatestTweet = function(name) {
var url = 'http://twitter.com/statuses/user_timeline.json?screen_name=' + name + '&count=1&callback=?';
var twitterIcon = '<img src="' + imgUrl + 'twitter.png" alt="twitter icon" width= "26" height="26" />';
$.getJSON(url, function(data) {
var tweet = data[0].text;
// process links and reply
tweet = tweet.replace(/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig, function(url) {
return '<a href="' + url + '">' + url + '</a>';
}).replace(/B@([_a-z0-9]+)/ig, function(reply) {
return reply.charAt(0) + '<a href="http://twitter.com/' + reply.substring(1) + '">'+ reply.substring(1) + '</a>';
});
var text = '<p>' + twitterIcon + tweet + '</p>';
animateStatus('#tweet', text);
});
};
var getLatestFacebookUpdate = function(id, accessToken) {
var url = 'https://graph.facebook.com/'+ id + '/feed?access_token='+ accessToken;
var facebookIcon = '<a href="http://facebook.com/kungligabiblioteket">'+'<img src="' + imgUrl + 'facebook.png" alt="facebook icon" width= "24" height="24" />'+'</a>';
$.ajax({
url: url,
dataType: 'jsonp',
success: function(json) {
var descr = getString(json.data[0].message);
var name= getString(json.data[0].name);
descr = getShortenedText(descr);
if(!json.data[0].link) {
var html = '<p>' + facebookIcon + descr;
}
else {
var html = '<p>' + facebookIcon + descr + '<a href="'+ json.data[0].link + '">' + name + '</a></p>';
}
if(descr){ animateStatus('#facebook', html);
}
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment