Created
August 2, 2012 07:27
-
-
Save makotoworld/3234813 to your computer and use it in GitHub Desktop.
Social Button
This file contains 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
<div class="social-buttons" data-url="http://www.deafway.jp/"></div> | |
<script type="text/javascript"> | |
<!-- | |
$(document).ready(function() { | |
var mixi_favorite_parse = function() { | |
$('div[data-plugins-type="mixi-favorite"]:empty').each(function(i, e) { | |
new window.__MIXI_PLUGINS__.FavoriteFrame(e); | |
}); | |
}; | |
var make_gplusone = function(talk_url) { | |
return '<span class="button-gplusone"><g:plusone size="tall" annotation="none" href="' + talk_url + '"></g:plusone></span>'; | |
}; | |
var make_fb = function(talk_url) { | |
return '<span class="button-fblike"><div class="fb-like" data-href="' + talk_url + '" data-layout="button_count" data-send="false" data-width="50" data-show-faces="false"></div></span>'; | |
}; | |
var make_hatebu = function(talk_url) { | |
return '<span class="button-hatebu"><a href="http://b.hatena.ne.jp/entry/' + talk_url + '" class="hatena-bookmark-button" data-hatena-bookmark-layout="standard" title="このエントリーをはてなブックマークに追加"><img src="http://b.st-hatena.com/images/entry-button/button-only.gif" alt="このエントリーをはてなブックマークに追加" width="20" height="20" style="border: none;" /></a></span>'; | |
}; | |
var make_mixi = function(talk_url) { | |
return '<span class="button-mixi"><div data-plugins-type="mixi-favorite" data-service-key="" data-href="' + talk_url + '" data-show-faces="false" data-show-count="true" data-width="100"></div></span>'; | |
} | |
var make_buttons = function(talk_url) { | |
var pieces = [ make_fb(talk_url), make_gplusone(talk_url), make_mixi(talk_url), make_hatebu(talk_url) ]; | |
return pieces.join(""); | |
}; | |
var fired; | |
var render_on_scroll = function() { | |
if (fired) { | |
return; | |
} | |
fired = true; | |
setTimeout(function() { | |
var w = $(window); | |
var bottom = w.scrollTop() + w.height(); | |
var render = false; | |
$("div.unhandled").each( function(i, e) { | |
e = $(e); | |
var offset = e.offset(); | |
if (bottom < offset.top) { | |
return; | |
} | |
render = true; | |
e.removeClass("unhandled"); | |
var buttons = $("div.social-buttons", e); | |
var url = buttons.attr("data-url"); | |
var html = make_buttons(url); | |
buttons.html( html ); | |
}); | |
if (render) { | |
try { | |
gapi.plusone.go(); | |
FB.XFBML.parse(); | |
mixi_favorite_parse(); | |
} catch(e) {} | |
} | |
fired = false; | |
}); | |
}; | |
$(window).scroll( render_on_scroll ); | |
render_on_scroll(); | |
}); | |
$([ | |
{ | |
src: "http://b.st-hatena.com/js/bookmark_button.js", | |
id: "hatena-bookmark" | |
}, | |
{ | |
src: "http://static.mixi.jp/js/plugins.js#lang=ja", | |
id: "mixi-check" | |
}, | |
{ | |
src: "http://platform.twitter.com/widgets.js", | |
id: "twitter-wjs" | |
}, | |
{ | |
src: "http://connect.facebook.net/ja_JP/all.js#xfbml=1&appId=xxxxxxxxxxxxx, | |
id: "facebook-jssdk" | |
}, | |
{ | |
src: 'https://apis.google.com/js/plusone.js', | |
id: "google-plusone" | |
} | |
]).each( function(i, e) { | |
var s = document.getElementById(e.id); | |
if (! s) { | |
s = document.createElement('script'); | |
s.id = e.id; | |
s.src = e.src; | |
s.async = true; | |
document.getElementsByTagName('head')[0].appendChild(s); | |
} | |
}); | |
--> | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment