Skip to content

Instantly share code, notes, and snippets.

@yannickcr
Created February 28, 2012 15:59
Show Gist options
  • Save yannickcr/1933321 to your computer and use it in GitHub Desktop.
Save yannickcr/1933321 to your computer and use it in GitHub Desktop.
Insert GooglePlus and Facebook buttons (use the HTML5 embedding code)
/*
* Google Plus
*
* Include Google Plus One if there is a "g-plusone" button in the page
*
*/
$(document).ready(function() {
if (!$('.g-plusone').length) return;
window.___gcfg = {lang: 'fr-FR'};
var g = document.createElement('script');
g.async = true;
g.src = document.location.protocol + 'apis.google.com/js/plusone.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(g, s);
});
/*
* Facebook
*
* Include Facebook API if there is a "fb-like" button in the page
*
*/
$(document).ready(function() {
if (!$('.fb-like').length) return;
$('<div></div>').attr('class', 'fb-root').appendTo(document.body);
var f = document.createElement('script');
f.async = true;
f.src = document.location.protocol + 'connect.facebook.net/fr_FR/all.js#xfbml=1';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(f, s);
});
@zebden
Copy link

zebden commented Feb 28, 2012

$(document).ready(function() {

/* Twitter */
var g = document.createElement('script'); g.async = true;
g.src = document.location.protocol + '//platform.twitter.com/widgets.js';
$('.tw-root').append(g);

/* G+ */
window.___gcfg = {lang: 'fr'};

var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/plusone.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);

/* FB */
var js, fjs = document.getElementsByTagName('script')[0];
if (document.getElementById('facebook-jssdk')) {return;}
js = document.createElement('script'); js.id = 'facebook-jssdk';
js.src = "//connect.facebook.net/fr_FR/all.js#xfbml=1&appId=170266383069878";
fjs.parentNode.insertBefore(js, fjs);

});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment