@@ -16,163 +16,33 @@ String.prototype.parseURL = function() {
1616 return url . link ( url ) ;
1717 } ) ;
1818} ;
19+
20+ /* Time Parsing */
1921function parse_date ( date_str ) {
20- return Date . parse ( date_str . replace ( / ^ ( [ a - z ] { 3 } ) ( [ a - z ] { 3 } \d \d ? ) ( .* ) ( \d { 4 } ) $ / i, '$1,$2$4$3' ) ) ;
22+ return Date . parse ( date_str . replace ( / ^ ( [ a - z ] { 3 } ) ( [ a - z ] { 3 } \d \d ? ) ( .* ) ( \d { 4 } ) $ / i, '$1,$2$4$3' ) ) ;
2123}
22-
2324function extract_relative_time ( date ) {
24- var toInt = function ( val ) { return parseInt ( val , 10 ) ; } ;
25- var relative_to = new Date ( ) ;
26- var delta = toInt ( ( relative_to . getTime ( ) - date ) / 1000 ) ;
27- if ( delta < 1 ) delta = 0 ;
28- return {
29- days : toInt ( delta / 86400 ) ,
30- hours : toInt ( delta / 3600 ) ,
31- minutes : toInt ( delta / 60 ) ,
32- seconds : toInt ( delta )
33- } ;
25+ var toInt = function ( val ) { return parseInt ( val , 10 ) ; } ;
26+ var relative_to = new Date ( ) ;
27+ var delta = toInt ( ( relative_to . getTime ( ) - date ) / 1000 ) ;
28+ if ( delta < 1 ) delta = 0 ;
29+ return {
30+ days : toInt ( delta / 86400 ) ,
31+ hours : toInt ( delta / 3600 ) ,
32+ minutes : toInt ( delta / 60 ) ,
33+ seconds : toInt ( delta )
34+ } ;
3435}
3536function format_relative_time ( time_ago ) {
36- if ( time_ago . days > 2 ) return ' ' + time_ago . days + ' days ago' ;
37- if ( time_ago . hours > 24 ) return ' a day ago' ;
38- if ( time_ago . hours > 2 ) return ' ' + time_ago . hours + ' hours ago' ;
39- if ( time_ago . minutes > 45 ) return ' an hour ago' ;
40- if ( time_ago . minutes > 2 ) return ' ' + time_ago . minutes + ' minutes ago' ;
41- if ( time_ago . seconds > 1 ) return ' ' + time_ago . seconds + ' seconds ago' ;
42- return 'just now' ;
37+ if ( time_ago . days > 2 ) return ' ' + time_ago . days + ' days ago' ;
38+ if ( time_ago . hours > 24 ) return ' a day ago' ;
39+ if ( time_ago . hours > 2 ) return ' ' + time_ago . hours + ' hours ago' ;
40+ if ( time_ago . minutes > 45 ) return ' an hour ago' ;
41+ if ( time_ago . minutes > 2 ) return ' ' + time_ago . minutes + ' minutes ago' ;
42+ if ( time_ago . seconds > 1 ) return ' ' + time_ago . seconds + ' seconds ago' ;
43+ return 'just now' ;
4344}
4445
45- /* Commit Widget */
46- ( function ( $ ) {
47- function widget ( element , options , callback ) {
48- this . element = element ;
49- this . options = options ;
50- this . callback = $ . isFunction ( callback ) ? callback : $ . noop ;
51- }
52-
53- widget . prototype = ( function ( ) {
54-
55- function getCommits ( user , repo , branch , callback ) {
56- $ . ajax ( {
57- url : "https://api.github.com/repos/" + user + "/" + repo + "/commits?sha=" + branch ,
58- //url: "/content/static/feeds/github.php",
59- dataType : 'jsonp' ,
60- success : callback
61- } ) ;
62- }
63-
64- function _widgetRun ( widget ) {
65- if ( ! widget . options ) {
66- widget . element . append ( '<span class="error">Options for widget are not set.</span>' ) ;
67- return ;
68- }
69- var callback = widget . callback ;
70- var element = widget . element ;
71- var user = widget . options . user ;
72- var repo = widget . options . repo ;
73- var branch = widget . options . branch ;
74- var avatarSize = widget . options . avatarSize || 20 ;
75- var last = widget . options . last === undefined ? 0 : widget . options . last ;
76- var limitMessage = widget . options . limitMessageTo === undefined ? 0 : widget . options . limitMessageTo ;
77-
78- element . append ( '<p>Loading commits...</p>' ) ;
79- getCommits ( user , repo , branch , function ( data ) {
80- var commits = data . data ;
81- var totalCommits = ( last < commits . length ? last : commits . length ) ;
82-
83- element . empty ( ) ;
84-
85- var list = $ ( '<ul class="github-commits-list">' ) . appendTo ( element ) ;
86- for ( var c = 0 ; c < totalCommits ; c ++ ) {
87- var commit = commits [ c ] ;
88- list . append (
89- '<li ' + itemClass ( c , totalCommits ) + ' >' +
90- ' ' + ( ( commit . author !== null ) ? avatar ( commit . author . gravatar_id , avatarSize ) : '' ) +
91- ' ' + ( ( commit . author !== null ) ? author ( commit . author . login ) : commit . commit . committer . name ) +
92- ' committed ' + message ( replaceHtmlTags ( commit . commit . message ) , commit . sha ) +
93- ' ' + when ( commit . commit . committer . date ) +
94- '</li>' ) ;
95- }
96- callback ( element ) ;
97-
98- function itemClass ( current , totalCommits ) {
99- if ( current === 0 ) {
100- return 'class="first"' ;
101- } else if ( current === totalCommits - 1 ) {
102- return 'class="last"' ;
103- }
104- return '' ;
105- }
106-
107- function avatar ( hash , size ) {
108- return '<img class="github-avatar" src="http://www.gravatar.com/avatar/' + hash + '?s=' + size + '"/>' ;
109- }
110-
111- function author ( login ) {
112- return '<div><a class="github-user" href="https://github.com/' + login + '">' + login + '</a>' ;
113- }
114-
115- function message ( commitMessage , sha ) {
116- var originalCommitMessage = commitMessage ;
117- if ( limitMessage > 0 && commitMessage . length > limitMessage )
118- {
119- commitMessage = commitMessage . substr ( 0 , limitMessage ) + '...' ;
120- }
121- return '"' + '<a class="github-commit" title="' + originalCommitMessage + '" href="https://github.com/' + user + '/' + repo + '/commit/' + sha + '">' + commitMessage + '</a>"' ;
122- }
123-
124- function replaceHtmlTags ( message ) {
125- return message . replace ( / & / g, "&" )
126- . replace ( / > / g, ">" )
127- . replace ( / < / g, "<" )
128- . replace ( / " / g, """ ) ;
129- }
130-
131- function when ( commitDate ) {
132- var commitTime = new Date ( commitDate ) . getTime ( ) ;
133- var todayTime = new Date ( ) . getTime ( ) ;
134-
135- var differenceInDays = Math . floor ( ( ( todayTime - commitTime ) / ( 24 * 3600 * 1000 ) ) ) ;
136- if ( differenceInDays === 0 ) {
137- var differenceInHours = Math . floor ( ( ( todayTime - commitTime ) / ( 3600 * 1000 ) ) ) ;
138- if ( differenceInHours === 0 ) {
139- var differenceInMinutes = Math . floor ( ( ( todayTime - commitTime ) / ( 600 * 1000 ) ) ) ;
140- if ( differenceInMinutes === 0 ) {
141-
142- return 'just now' ;
143- }
144-
145- return 'about ' + differenceInMinutes + ' minutes ago' ;
146- }
147-
148- return 'about ' + differenceInHours + ' hours ago' ;
149- } else if ( differenceInDays == 1 ) {
150- return 'yesterday' ;
151- }
152- return differenceInDays + ' days ago</div>' ;
153- }
154- } ) ;
155- }
156-
157- return {
158- run : function ( ) {
159- _widgetRun ( this ) ;
160- }
161- } ;
162-
163- } ) ( ) ;
164-
165- $ . fn . githubInfoWidget = function ( options , callback ) {
166- this . each ( function ( ) {
167- new widget ( $ ( this ) , options , callback )
168- . run ( ) ;
169- } ) ;
170- return this ;
171- } ;
172-
173- } ) ( jQuery ) ;
174-
175-
17646$ ( function ( ) {
17747 $ ( window ) . scroll ( function ( ) {
17848 if ( $ ( this ) . scrollTop ( ) > 114 ) {
@@ -182,6 +52,7 @@ $(function(){
18252 }
18353 } )
18454
55+ // recent tweets
18556 $ . getJSON ( '/content/static/feeds/twitter.php' , function ( data ) {
18657 $ . each ( data , function ( i , tweet ) {
18758 var time = parse_date ( tweet . created_at ) ;
@@ -196,6 +67,21 @@ $(function(){
19667 } )
19768 } )
19869
199- $ ( ".latest-commits" ) . githubInfoWidget ( { user : 'processing' , repo : 'processing' , branch : 'master' , last : 4 } ) ;
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+ } )
20086
20187} ) ;
0 commit comments