Created
April 2, 2015 23:50
-
-
Save SachaG/980b1bbabedf1d8deb4a to your computer and use it in GitHub Desktop.
Twitter Widget
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var capitaliseFirstLetter = function (string){ | |
return string.charAt(0).toUpperCase() + string.slice(1); | |
} | |
var buildTwitterLink = function (text, url) { | |
var encodedUrl = encodeURIComponent(url); | |
var referrer = encodeURIComponent("http://communitybuildingguide.com"); | |
// var url = "http%3A%2F%2Fbook.discovermeteor.com%2Fstarter%3Futm_source%3Dstarter%26utm_medium%3Dtwitter%26utm_campaign%3Dstarter_tweet"; | |
return "https://twitter.com/intent/tweet?original_referer="+referrer+"&url="+encodedUrl+"&text="+encodeURIComponent(text)+"&hashtags=combuild&via=telescopeapp"; | |
} | |
var updateTweetLink = function () { | |
var text = $('.tweet-content').val(); | |
var url = encodeURIComponent("http://communitybuildingguide.com"); | |
var twitterLink = "https://twitter.com/intent/tweet?original_referer="+url+"&text="+encodeURIComponent(text); | |
var charRemaining = 151 - text.length; | |
$('.tweet-link').attr('href', twitterLink); | |
$('.tweet-counter').text(charRemaining); | |
charRemaining <= 0 ? $('.tweet-counter').addClass('danger') : $('.tweet-counter').removeClass('danger'); | |
} | |
$(function(){ | |
if ($('.tweet-content').length) { | |
updateTweetLink(); | |
$('.tweet-content').keyup(function () { | |
updateTweetLink(); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment