diff options
Diffstat (limited to 'assets/javascript')
-rw-r--r-- | assets/javascript/app.js | 7 | ||||
-rw-r--r-- | assets/javascript/utils/sharing.js | 32 |
2 files changed, 38 insertions, 1 deletions
diff --git a/assets/javascript/app.js b/assets/javascript/app.js index b3c2805..f1ba529 100644 --- a/assets/javascript/app.js +++ b/assets/javascript/app.js @@ -2,11 +2,13 @@ require([ "jQuery", "utils/storage", "utils/analytic", + "utils/sharing", + "core/state", "core/exercise", "core/progress", "core/sidebar" -], function($, storage, analytic, _state, exercise, progress, sidebar){ +], function($, storage, analytic, sharing, _state, exercise, progress, sidebar){ $(document).ready(function() { var state = _state(); var $book = state.$book; @@ -30,6 +32,9 @@ require([ // Bind exercise exercise.init(); + // Bind sharing button + sharing.init(); + // Show progress progress.show(); }); 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 |