@@ -139,13 +139,15 @@ var GitHub = (function () {
139139 var gitMethods = {
140140
141141 checkInteger : function ( value ) {
142+ // Check if value is integer
142143 if ( value === parseInt ( value , 10 ) )
143144 return true ;
144145 else
145146 return false ;
146147 } ,
147148
148149 getRenderedHTML : function ( template , data ) {
150+ // Get the rendered template with data
149151 if ( data ) {
150152 return _ . template ( template ) ( data ) ;
151153 } else {
@@ -154,14 +156,15 @@ var GitHub = (function () {
154156 } ,
155157
156158 getUserProfileHTML : function ( username ) {
157-
159+ // Get User profile HTML
158160 var userUrl = gitApiUrl + 'users/' + username ;
159161 return gitMethods . getData ( userUrl , function ( data ) {
160162 return gitMethods . getRenderedHTML ( gitTemplates . userProfileTpl , data ) ;
161163 } ) ;
162164 } ,
163165
164166 getRepoProfileHTML : function ( username , reponame ) {
167+ // Get the repository profile HTML with language stats
165168 var repoUrl = gitApiUrl + 'repos/' + username + '/' + reponame ;
166169 var languageUrl = repoUrl + '/languages' ;
167170 var languageHtml = gitMethods . getData ( languageUrl , gitMethods . getLanguageHTML ) ;
@@ -173,25 +176,28 @@ var GitHub = (function () {
173176 } ,
174177
175178 getOrgProfileHTML : function ( orgname ) {
179+ // Get organization profile HTML
176180 var orgUrl = gitApiUrl + 'orgs/' + orgname ;
177181 return gitMethods . getData ( orgUrl , function ( data ) {
178182 return gitMethods . getRenderedHTML ( gitTemplates . orgProfileTpl , data ) ;
179183 } ) ;
180184 } ,
181185
182186 getPublicActivityHTML : function ( data ) {
183-
187+ // Get all the public activities of user/repo/organization
184188 var html = '<div class="gt-activity-cnt gt-scrollbar">' ;
185189 var length = ( gitMethods . activityLimit < data . length ) ? gitMethods . activityLimit : data . length ;
186190
187191 if ( length == 0 ) {
192+ // If no activity in last 90 days
188193 html += gitMethods . getRenderedHTML ( gitTemplates [ 'noActivityTpl' ] ) ;
189194 }
190195 else {
196+ // Loop over all the activities
191197 for ( var index = 0 ; index < length ; index ++ ) {
192-
193198 var activity = data [ index ] ;
194199 var payload = activity . payload ;
200+ // Get attributes common to all activities
195201 activity . timeString = gitMethods . millisecondsToStr ( new Date ( ) - new Date ( activity . created_at ) ) ;
196202 activity . userLink = gitMethods . getGitHubLink ( activity . actor . login , activity . actor . login ) ;
197203 activity . repoLink = gitMethods . getGitHubLink ( activity . repo . name , activity . repo . name ) ;
@@ -207,6 +213,7 @@ var GitHub = (function () {
207213 activity . branchLink = gitMethods . getGitHubLink ( activity . repo . name + '/tree/' + activity . branch , activity . branch ) ;
208214 }
209215
216+ // Get the HTML of selected activity type
210217 switch ( activity . type ) {
211218 case 'CommitCommentEvent' : activity . commentLink = gitMethods . getLink ( payload . comment . html_url , activity . repo . name + '@' + payload . comment . commit_id . substring ( 0 , 6 ) ) ;
212219 break ;
@@ -241,7 +248,7 @@ var GitHub = (function () {
241248 case 'WatchEvent' :
242249 break ;
243250 }
244-
251+ // Get activity specific message
245252 activity . message = gitMethods . getRenderedHTML ( gitTemplates [ activity . type ] , activity ) ;
246253 html += gitMethods . getRenderedHTML ( gitTemplates [ 'gitActivityTpl' ] , activity ) ;
247254
@@ -253,7 +260,7 @@ var GitHub = (function () {
253260 } ,
254261
255262 getCommitsHTML : function ( activity ) {
256-
263+ // Form HTML for commits in PushEvent
257264 var html = '<ul class="gt-commit-list">' ;
258265 var liElement , shaLink , commitMessage , commit , index ,
259266 compareLink = '' ,
@@ -262,7 +269,7 @@ var GitHub = (function () {
262269 shaDiff = payload . before + '...' + payload . head ;
263270
264271 for ( index = 0 ; index < length ; index ++ ) {
265-
272+ // Get links for 2 or less commit
266273 if ( index > 1 ) break ;
267274 commit = payload . commits [ index ] ;
268275 liElement = '<li class="gt-commit-item" >' ;
@@ -274,6 +281,7 @@ var GitHub = (function () {
274281 html += liElement ;
275282 }
276283
284+ // Get the diff link between commits
277285 if ( length === 2 ) {
278286 compareLink = gitMethods . getGitHubLink ( activity . repo . name + '/compare/' + shaDiff , 'View comparison for these 2 commits »' , 'gt-compare-link' ) ;
279287 } else if ( length > 2 ) {
@@ -287,7 +295,7 @@ var GitHub = (function () {
287295 } ,
288296
289297 getData : function ( url , callback ) {
290-
298+ // Utility for synchronous AJAX calls
291299 var content , data , request ;
292300 request = new XMLHttpRequest ( ) ;
293301 request . open ( 'GET' , url , false ) ;
@@ -309,7 +317,7 @@ var GitHub = (function () {
309317 } ,
310318
311319 getLink : function ( url , title , cssClass ) {
312-
320+ // Get anchor tag HTML for URL
313321 if ( ! title )
314322 title = url ;
315323 if ( typeof ( cssClass ) === 'undefined' )
@@ -318,7 +326,7 @@ var GitHub = (function () {
318326 } ,
319327
320328 getGitHubLink : function ( url , title , cssClass ) {
321-
329+ // Get anchor tag HTML for non-github URL
322330 if ( ! title )
323331 title = url ;
324332 if ( typeof ( cssClass ) === 'undefined' )
@@ -333,22 +341,23 @@ var GitHub = (function () {
333341 } ,
334342
335343 getLanguageHTML : function ( data ) {
336-
344+ // Get repository language stat HTML
337345 var languageData = [ ] , sum = 0 ,
338346 percentage , languageHtml = '' ;
339347
340- _ . each ( data , function ( value , key ) {
348+ _ . each ( data , function ( value , key ) {
341349 var data = { } ;
342350 data . language = key ;
343351 data . size = value ;
344352 languageData . push ( data ) ;
345353 sum += value ;
346354 } ) ;
347355
356+ // Sort languages by usage in repo
348357 languageData = languageData . sort ( function ( a , b ) { return b . size - a . size } ) ;
349358
350359 _ . each ( languageData , function ( element ) {
351-
360+ // Get HTML for each language
352361 percentage = ( parseInt ( element . size ) / sum * 100 ) . toFixed ( 1 ) ;
353362 languageHtml += '<div class="gt-repo-lg-cnt" style="width: ' + percentage + '%; background: #' + gitMethods . getRandomColor ( ) + '; " >' +
354363 ' <div class="gt-repo-lg-name" data-title="' + element . language + ' (' + percentage + '%)"> </div> </div>' ;
@@ -358,12 +367,12 @@ var GitHub = (function () {
358367 } ,
359368
360369 getRandomColor : function ( ) {
361-
370+ // Get random HEX code for color
362371 return Math . random ( ) . toString ( 16 ) . substring ( 2 , 8 ) ;
363372 } ,
364373
365374 millisecondsToStr : function ( milliseconds ) {
366-
375+ // Convert milliseconds to time string
367376 function numberEnding ( number ) {
368377 return ( number > 1 ) ? 's ago' : ' ago' ;
369378 }
@@ -391,7 +400,7 @@ var GitHub = (function () {
391400 } ,
392401
393402 renderContent : function ( content , selector ) {
394-
403+ // render the content to the selector
395404 var selectorDivs = document . querySelectorAll ( selector ) ;
396405 content = '<div class="gt-container">' + content + '</div>' ;
397406
@@ -403,6 +412,7 @@ var GitHub = (function () {
403412 } ,
404413
405414 setLimit : function ( value ) {
415+ // Set render limit for activities - default is 30
406416 var limit ;
407417 if ( value !== 'undefined' && gitMethods . checkInteger ( limit = parseInt ( value , 10 ) ) ) {
408418 gitMethods . activityLimit = ( limit > 30 ) ?30 :limit ;
@@ -414,6 +424,10 @@ var GitHub = (function () {
414424
415425 } ;
416426
427+ /**
428+ * userProfile - render's the github user details to selector
429+ * @param {[JSON] } options [username, selector]
430+ */
417431 gitObj . userProfile = function ( options ) {
418432
419433 if ( ! options . username || ! options . selector ) {
@@ -432,7 +446,10 @@ var GitHub = (function () {
432446 gitMethods . renderContent ( parentCnt , options . selector ) ;
433447
434448 } ;
435-
449+ /**
450+ * repoProfile - render's the github repo details to selector
451+ * @param {[JSON] } options [username, reponame, selector]
452+ */
436453 gitObj . repoProfile = function ( options ) {
437454
438455 if ( ! options . username || ! options . selector || ! options . reponame ) {
@@ -451,7 +468,10 @@ var GitHub = (function () {
451468 gitMethods . renderContent ( parentCnt , options . selector ) ;
452469
453470 } ;
454-
471+ /**
472+ * orgProfile - render's the github organization details to selector
473+ * @param {[JSON] } options [orgname, selector]
474+ */
455475 gitObj . orgProfile = function ( options ) {
456476
457477 if ( ! options . orgname || ! options . selector ) {
@@ -470,7 +490,10 @@ var GitHub = (function () {
470490 gitMethods . renderContent ( parentCnt , options . selector ) ;
471491
472492 } ;
473-
493+ /**
494+ * userActivity - render's the github user activity to selector
495+ * @param {[JSON] } options [username, selector and limit (optional)]
496+ */
474497 gitObj . userActivity = function ( options ) {
475498
476499 if ( ! options . username || ! options . selector ) {
@@ -493,7 +516,10 @@ var GitHub = (function () {
493516 gitMethods . renderContent ( parentCnt , options . selector ) ;
494517
495518 } ;
496-
519+ /**
520+ * repoActivity - render's the github repository activity to selector
521+ * @param {[JSON] } options [username, reponame, selector and limit (optional)]
522+ */
497523 gitObj . repoActivity = function ( options ) {
498524
499525 if ( ! options . username || ! options . selector || ! options . reponame ) {
@@ -516,7 +542,10 @@ var GitHub = (function () {
516542 gitMethods . renderContent ( parentCnt , options . selector ) ;
517543
518544 } ;
519-
545+ /**
546+ * orgActivity - render's the github organization activity to selector
547+ * @param {[JSON] } options [orgname, selector and limit (optional)]
548+ */
520549 gitObj . orgActivity = function ( options ) {
521550
522551 if ( ! options . orgname || ! options . selector ) {
0 commit comments