Skip to content

Instantly share code, notes, and snippets.

@putzflorian
Last active December 16, 2015 22:39
Show Gist options
  • Save putzflorian/5508025 to your computer and use it in GitHub Desktop.
Save putzflorian/5508025 to your computer and use it in GitHub Desktop.
$('html').attr('xmlns:fb','http://www.facebook.com/2008/fbml');
$('html').attr('xmlns:og', 'http://opengraphprotocol.org/schema/');
var cache = $.ajaxSettings.cache,
langCode;
$.ajaxSettings.cache = true;
// Define a var lang = 'LANGUAGE'; before this code
switch( lang ){
case 'de':
langCode = 'de_DE';
break;
case 'it':
langCode = 'it_IT';
break;
case 'fr':
langCode = 'fr_FR';
break;
case 'es':
langCode = 'es_ES';
break;
case 'ru':
langCode = 'ru_RU';
break;
case 'pl':
langCode = 'pl_PL';
break;
case 'cs':
langCode = 'cs_CZ';
break;
case 'cz':
langCode = 'cs_CZ';
break;
case 'nl':
langCode = 'nl_NL';
break;
default:
langCode = 'en_US';
break;
}
$.getScript('http://connect.facebook.net/' + langCode + '/all.js', function() {
FB.init({status: true, cookie: true, xfbml: true});
});
$.ajaxSettings.cache = cache;
// edit the #socialmedia where you would like to add the Button (class or id)
// Feel free to edit the URL Params like load Faces, breite, höhe, colorsheme, font, layout...
$('#socialmedia').append('<div id="fb-root"><fb:like href="' + window.location.href + '" layout="button_count" show_faces="false" width="450" height="35" action="like" colorscheme="light" font="trebuchet ms" allowTransparency="true"></fb:like></div>');
You need jQuery 1.6 and upper.
Facebook:
For the FB reload you also need a Variable called "lang" in js with the language code (de, en, it, fr...)
For more information show comments in the file facebook.js
Google Plus:
You only need jQuery and edit the selector (id,class) where you would like to show g+
$.ajax( {
type: 'GET',
url: 'https://apis.google.com/js/plusone.js',
timeout: 2000, // Timeout after 2 seconds
dataType: 'script',
cache: true,
success:
function() {
window.___gcfg = { lang: lang };
}
});
// edit the #socialmedia where you would like to add the Button (class or id)
$('#socialmedia').append('<div id="gplusButton"><div class="g-plusone" data-size="medium"></div></div>');
if($('a.twitter-share-button').length > 0){
$('head').append('<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>');
var tweet_button = new twttr.TweetButton( $('a.twitter-share-button') );
tweet_button.render();
}
<a href="http://twitter.com/share" class="twitter-share-button">Tweet</a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment