@@ -371,7 +371,7 @@ issues.MainView = Backbone.View.extend({
371371 $ ( document . body ) . addClass ( 'language-html' ) ;
372372 var issueNum = { number : issueNumber } ;
373373 this . issue = new issues . Issue ( issueNum ) ;
374- this . comments = new issues . CommentsCollection ( [ ] ) ;
374+ this . comments = new issues . CommentsCollection ( { pageNumber : 1 } ) ;
375375 this . initSubViews ( ) ;
376376 this . fetchModels ( ) ;
377377 } ,
@@ -426,17 +426,18 @@ issues.MainView = Backbone.View.extend({
426426
427427 // If there are any comments, go fetch the model data
428428 if ( this . issue . get ( 'commentNumber' ) > 0 ) {
429- this . comments . fetch ( headersBag ) . success ( _ . bind ( function ( ) {
429+ this . comments . fetch ( headersBag ) . success ( _ . bind ( function ( response ) {
430430 this . addExistingComments ( ) ;
431- // the add event is fired when a model is added to the collection.
432431 this . comments . bind ( 'add' , _ . bind ( this . addComment , this ) ) ;
433-
434432 // If there's a #hash pointing to a comment (or elsewhere)
435433 // scrollTo it.
436434 if ( location . hash !== '' ) {
437435 var _id = $ ( location . hash ) ;
438436 window . scrollTo ( 0 , _id . offset ( ) . top ) ;
439437 }
438+ if ( response [ 0 ] . lastPageNumber > 1 ) {
439+ this . getRemainingComments ( ++ response [ 0 ] . lastPageNumber ) ;
440+ }
440441 } , this ) ) . error ( function ( ) {
441442 var msg = 'There was an error retrieving issue comments. Please reload to try again.' ;
442443 wcEvents . trigger ( 'flash:error' , { message : msg , timeout : 4000 } ) ;
@@ -453,6 +454,17 @@ issues.MainView = Backbone.View.extend({
453454 }
454455 } ) ;
455456 } ,
457+
458+ getRemainingComments : function ( count ) {
459+ //The first 30 comments for page 1 has already been loaded.
460+ //If more than 30 comments are there the remaining comments are rendered in sets of 30
461+ //in consecutive pages
462+
463+ _ . each ( _ . range ( 2 , count ) , function ( i ) {
464+ this . comments . fetchPage ( { pageNumber : i , headers : { 'Accept' : 'application/json' } } ) ;
465+ } , this ) ;
466+ } ,
467+
456468 addComment : function ( comment ) {
457469 // if there's a nsfw label, add the whatever class.
458470 var view = new issues . CommentView ( { model : comment } ) ;
0 commit comments