summaryrefslogtreecommitdiffstats
path: root/assets/javascript/utils/sharing.js
blob: 8feb7414c1687151668f8a89cfe71209a5281d51 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
    };
});