diff --git a/public/js/compose.js b/public/js/compose.js index 8d5c9b6..a02b04b 100644 --- a/public/js/compose.js +++ b/public/js/compose.js @@ -39,7 +39,7 @@ return urlBase.concat('?message=',message,'&from=',from,'&graph=',graphName); }; - //this is called once we have a short url from the google url-shortener + //this is called once we have a short url from the TinyURL var shareCallback = function(shareLink){ $shareLink.val(shareLink); var tweetUrl = "https://twitter.com/intent/tweet?text=" @@ -52,11 +52,17 @@ showShare(); }; - //TODO: hook up a new link shortener! var share = function(){ $body.addClass('is-loading'); var longUrl = getLongUrl(); - shareCallback(longUrl); + + // shorten longUrl using TinyURL API + $.get("https://tinyurl.com/api-create.php?url=" + encodeURIComponent(longUrl)) + .done(shareCallback) + .fail(function () { + // share longUrl if TinyURL API call fails + shareCallback(longUrl); + }); }; //this is the code that interacts with the graphpaper