diff options
author | Samrat Man Singh <samratmansingh@gmail.com> | 2012-07-07 08:31:08 +0545 |
---|---|---|
committer | Samrat Man Singh <samratmansingh@gmail.com> | 2012-07-07 08:31:08 +0545 |
commit | 2ce26b4ed17e153d9834e6dd21ec0da92d71139e (patch) | |
tree | 9b59308831e99ed534f28aac51b5b236ac54ce87 /syte/static/js/components/twitter.js | |
parent | 705357519b7345422a003d8970d1f396579d91b2 (diff) | |
download | pelican-themes-2ce26b4ed17e153d9834e6dd21ec0da92d71139e.tar.gz |
Move syte-pelican to syte
Diffstat (limited to 'syte/static/js/components/twitter.js')
-rw-r--r-- | syte/static/js/components/twitter.js | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/syte/static/js/components/twitter.js b/syte/static/js/components/twitter.js new file mode 100644 index 0000000..4a8bb30 --- /dev/null +++ b/syte/static/js/components/twitter.js @@ -0,0 +1,82 @@ + +function setupTwitter(url, el) { + var href = el.href; + + if ($('#twitter-profile').length > 0) { + window.location = href; + return; + } + + var params = url.attr('path').split('/').filter(function(w) { + if (w.length) + return true; + return false; + }) + + if (params.length == 1) { + var username = params[0]; + + var spinner = new Spinner(spin_opts).spin(); + $('#twitter-link').append(spinner.el); + + require(["json!/twitter/" + username, "text!templates/twitter-view.html"], + function(twitter_data, twitter_view) { + if (twitter_data.error || twitter_data.length == 0) { + window.location = href; + return; + } + + var template = Handlebars.compile(twitter_view); + + var tweets = []; + $.each(twitter_data, function(i, t) { + if (i > 3) + return; + + //'ddd MMM DD HH:mm:ss ZZ YYYY' + t.formated_date = moment(t.created_at).fromNow(); + t.f_text = twitterLinkify(t.text); + tweets.push(t); + }); + + var user = twitter_data[0].user; + user.statuses_count = numberWithCommas(user.statuses_count); + user.friends_count = numberWithCommas(user.friends_count); + user.followers_count = numberWithCommas(user.followers_count); + user.f_description = twitterLinkify(user.description); + + var template_data = { + "user": user, + "tweets": tweets + } + + $(template(template_data)).modal().on('hidden', function () { + $(this).remove(); + adjustSelection('home-link'); + }) + + spinner.stop(); + }); + + return; + } + + window.location = href; +} + +function twitterLinkify(text) { + text = text.replace(/(https?:\/\/\S+)/gi, function (s) { + return '<a href="' + s + '">' + s + '</a>'; + }); + + text = text.replace(/(^|) @(\w+)/gi, function (s) { + return '<a href="http://twitter.com/' + s + '">' + s + '</a>'; + }); + + text = text.replace(/(^|) #(\w+)/gi, function (s) { + return '<a href="http://search.twitter.com/search?q=' + s.replace(/#/,'%23') + '">' + s + '</a>'; + }); + + return text; +} + |