summaryrefslogtreecommitdiffstats
path: root/theme/javascript/utils/sharing.js
diff options
context:
space:
mode:
Diffstat (limited to 'theme/javascript/utils/sharing.js')
-rw-r--r--theme/javascript/utils/sharing.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/theme/javascript/utils/sharing.js b/theme/javascript/utils/sharing.js
new file mode 100644
index 0000000..f4354f1
--- /dev/null
+++ b/theme/javascript/utils/sharing.js
@@ -0,0 +1,33 @@
+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) {
+ if (e) e.preventDefault();
+ var type = $(this).data("sharing");
+
+ types[type]($(this));
+ })
+ };
+
+ return {
+ init: init
+ };
+}); \ No newline at end of file