Skip to content

Instantly share code, notes, and snippets.

@bkardell
Created February 1, 2012 18:33
Show Gist options
  • Save bkardell/1718520 to your computer and use it in GitHub Desktop.
Save bkardell/1718520 to your computer and use it in GitHub Desktop.
Facebook "Like" Hitch
/**
{
"title": "Facebook Like Hitch",
"type": "html",
"description": "Provides Facebook 'like' button as an HTML hitch",
"package": "bkardell.facebook.like",
"version": "1"
}
======
Some docs go here... This is a test.
**/
(function(){
var body = document.getElementsByTagName('body')[0];
var rootDiv = document.createElement('div');
rootDiv.setAttribute("id","fb-root");
body.appendChild(rootDiv);
(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_US/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
Hitch.add([{
name: 'data-fb-like',
base: '[data-fb-like]',
type: 'html',
init: function(m){
for(var i=0;i<m.length;i++){
m[i].className += ' fb-like';
m[i].setAttribute('data-href',m[i].getAttribute("href") || window.location.href);
m[i].setAttribute('data-send', "false");
m[i].setAttribute('data-show-faces', "true");
};
}
}]);
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment