diff options
author | Samy Pessé <samypesse@gmail.com> | 2014-04-02 20:17:46 -0700 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2014-04-02 20:17:46 -0700 |
commit | aa4e3abc33727ae9e03d11ee1a9e024ee4e9a473 (patch) | |
tree | 8193465b16fe37da3dfb7b57b4605910b22ac265 /assets/javascript/utils | |
parent | f24a7fbb6e0495642a78384d3fcbc573dc03ec1b (diff) | |
download | gitbook-aa4e3abc33727ae9e03d11ee1a9e024ee4e9a473.zip gitbook-aa4e3abc33727ae9e03d11ee1a9e024ee4e9a473.tar.gz gitbook-aa4e3abc33727ae9e03d11ee1a9e024ee4e9a473.tar.bz2 |
Add sharing links in header
Diffstat (limited to 'assets/javascript/utils')
-rw-r--r-- | assets/javascript/utils/sharing.js | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/assets/javascript/utils/sharing.js b/assets/javascript/utils/sharing.js new file mode 100644 index 0000000..8feb741 --- /dev/null +++ b/assets/javascript/utils/sharing.js @@ -0,0 +1,32 @@ +define([ + "jQuery" +], function($) { + var url = location.href; + var title = $("title").text(); + + var types = { + "twitter": function($el) { + window.open("http://twitter.com/home?status="+encodeURIComponent(title+" "+url)) + }, + "facebook": function($el) { + window.open("http://www.facebook.com/sharer/sharer.php?s=100&p[url]="+encodeURIComponent(url)) + }, + "google-plus": function($el) { + window.open("https://plus.google.com/share?url="+encodeURIComponent(url)) + } + }; + + + // Bind all sharing button + var init = function() { + $("a[data-sharing]").click(function(e) { + var type = $(this).data("sharing"); + + types[type]($(this)); + }) + }; + + return { + init: init + }; +});
\ No newline at end of file |