|
| 1 | +$(function(){ |
| 2 | + |
| 3 | + // sticky scroll |
| 4 | + $(window).scroll(function(){ |
| 5 | + if($(this).scrollTop() > 114){ |
| 6 | + $('.navBar').addClass('stuck') |
| 7 | + } else { |
| 8 | + $('.navBar').removeClass('stuck') |
| 9 | + } |
| 10 | + }) |
| 11 | + |
| 12 | + // if on the homepage, gather recent tweets/commits |
| 13 | + if($('body').attr('id')=='Cover'){ |
| 14 | + |
| 15 | + // recent tweets |
| 16 | + $.getJSON('/content/static/feeds/twitter.php', function(data) { |
| 17 | + $.each(data, function(i, tweet) { |
| 18 | + var time = parse_date(tweet.created_at); |
| 19 | + var timeText = format_relative_time(extract_relative_time(time)); |
| 20 | + |
| 21 | + var tweet_html = '<li><div>'+tweet.text.parseURL().parseUsername().parseHashtag(); |
| 22 | + tweet_html += ' about'; |
| 23 | + tweet_html += '<a href="https://www.twitter.com/processingOrg/status/' + tweet.id_str + '">' + timeText + '<\/a>'; |
| 24 | + tweet_html += '<\/div><\/li>'; |
| 25 | + |
| 26 | + $('.latest-tweets').append(tweet_html) |
| 27 | + }) |
| 28 | + }) |
| 29 | + |
| 30 | + // recent commits |
| 31 | + $.getJSON('/content/static/feeds/github.php', function(data) { |
| 32 | + $.each(data, function(i, commit) { |
| 33 | + if(i<=3){ |
| 34 | + var time = parse_date(commit.commit.committer.date); |
| 35 | + var timeText = format_relative_time(extract_relative_time(time)); |
| 36 | + |
| 37 | + var commit_html = '<li><img class="github-avatar" src="http://www.gravatar.com/avatar/' + commit.author.gravatar_id + '?s=20"/>'; |
| 38 | + commit_html += '<div><a href="' + commit.author.html_url + '">' + commit.author.login + '<\/a> commited'; |
| 39 | + commit_html += ' <a href="https://github.com/processing/processing/commit/' + commit.sha + '">"' + commit.commit.message + '"<\/a>'; |
| 40 | + commit_html += ' about ' + timeText + '<\/div>'; |
| 41 | + |
| 42 | + $('.latest-commits').append(commit_html) |
| 43 | + } |
| 44 | + }) |
| 45 | + }) |
| 46 | + |
| 47 | + } |
| 48 | + |
| 49 | +}); |
| 50 | + |
| 51 | + |
| 52 | +// Functions |
| 53 | + |
1 | 54 | /* Twitter Parsing Functions */ |
2 | 55 | String.prototype.parseUsername = function() { |
3 | 56 | return this.replace(/[@]+[A-Za-z0-9-_]+/g, function(u) { |
@@ -42,46 +95,3 @@ function format_relative_time(time_ago) { |
42 | 95 | if ( time_ago.seconds > 1 ) return ' ' + time_ago.seconds + ' seconds ago'; |
43 | 96 | return 'just now'; |
44 | 97 | } |
45 | | - |
46 | | -$(function(){ |
47 | | - $(window).scroll(function(){ |
48 | | - if($(this).scrollTop() > 114){ |
49 | | - $('.navBar').addClass('stuck') |
50 | | - } else { |
51 | | - $('.navBar').removeClass('stuck') |
52 | | - } |
53 | | - }) |
54 | | - |
55 | | - // recent tweets |
56 | | - $.getJSON('/content/static/feeds/twitter.php', function(data) { |
57 | | - $.each(data, function(i, tweet) { |
58 | | - var time = parse_date(tweet.created_at); |
59 | | - var timeText = format_relative_time(extract_relative_time(time)); |
60 | | - |
61 | | - var tweet_html = '<li><div>'+tweet.text.parseURL().parseUsername().parseHashtag(); |
62 | | - tweet_html += ' about'; |
63 | | - tweet_html += '<a href="https://www.twitter.com/processingOrg/status/' + tweet.id_str + '">' + timeText + '<\/a>'; |
64 | | - tweet_html += '<\/div><\/li>'; |
65 | | - |
66 | | - $('.latest-tweets').append(tweet_html) |
67 | | - }) |
68 | | - }) |
69 | | - |
70 | | - // recent commits |
71 | | - $.getJSON('/content/static/feeds/github.php', function(data) { |
72 | | - $.each(data, function(i, commit) { |
73 | | - if(i<=3){ |
74 | | - var time = parse_date(commit.commit.committer.date); |
75 | | - var timeText = format_relative_time(extract_relative_time(time)); |
76 | | - |
77 | | - var commit_html = '<li><img class="github-avatar" src="http://www.gravatar.com/avatar/' + commit.author.gravatar_id + '?s=20"/>'; |
78 | | - commit_html += '<div><a href="' + commit.author.html_url + '">' + commit.author.login + '<\/a> commited'; |
79 | | - commit_html += ' <a href="https://github.com/processing/processing/commit/' + commit.sha + '">"' + commit.commit.message + '"<\/a>'; |
80 | | - commit_html += ' about ' + timeText + '<\/div>'; |
81 | | - |
82 | | - $('.latest-commits').append(commit_html) |
83 | | - } |
84 | | - }) |
85 | | - }) |
86 | | - |
87 | | -}); |
|
0 commit comments