function PlayerListNavigator(pageNoArea, playerListManager) { var self = this; this.playerListManager = playerListManager; this.pagination = pageNoArea; // console.log(parent); this.activePageNo = 1; this.lastPageNo = 1; } PlayerListNavigator.prototype.updateNavigator = function(activePageNo, lastPageNo) { this.activePageNo = activePageNo; this.lastPageNo = lastPageNo; // this.lastPageNo = Math.ceil( (playerCount + 1) / 10 ); $(this.pagination).empty(); this.makePagination(); this.applyClickEvent(); this.disableNavButtons(); } PlayerListNavigator.prototype.makePagination = function() { // left arrows var paginationLeftArrows = '\
  • \ \ \ First\ \
  • \ \
  • \ \ \ Previous\ \
  • \ \
  •  
  • \ \ '; $(this.pagination).append(paginationLeftArrows); // numbers for(var pageNo = 1; pageNo < this.lastPageNo + 1; pageNo++) { $(this.pagination).append( '
  • ' + pageNo + '
  • ' ); } // right arrows var paginationRightArrows = '\
  •  
  • \ \
  • \ \ \ Next\ \
  • \ \
  • \ \ \ Last\ \
  • \ '; $(this.pagination).append(paginationRightArrows); } PlayerListNavigator.prototype.applyClickEvent = function() { var self = this; $("[aria-label='First']").click(function() { self.onClickPageNo("first"); }); $("[aria-label='Previous']").click(function() { self.onClickPageNo("previous"); }); for(var pageNo = 1; pageNo < this.lastPageNo + 1; pageNo++) { $("[aria-label='" + pageNo + "']").click(function() { self.onClickPageNo(pageNo); }); } $("[aria-label='Next']").click(function() { self.onClickPageNo("next"); }); $("[aria-label='Last']").click(function() { self.onClickPageNo("last"); }); } PlayerListNavigator.prototype.disableNavButtons = function() { /* console.log(this.activePageNo); console.log(this.lastPageNo); console.log($("[aria-label='First']").parent()); if(this.activePageNo === 1 || this.lastPageNo === 1) $("[aria-label='First']").parent().prop("disabled", true); else $("[aria-label='First']").parent().prop("disabled", false); if(this.activePageNo === 1 || this.lastPageNo === 1) $("[aria-label='Previous']").parent().prop("disabled", true); else $("[aria-label='Previous']").parent().prop("disabled", false); for(var pageNo = 1; pageNo < this.lastPageNo + 1; pageNo++) { if(this.activePageNo === pageNo) $("[aria-label='" + pageNo + "']").parent().prop("disabled", true); else $("[aria-label='" + pageNo + "']").parent().prop("disabled", false); } if(this.activePageNo === this.lastPageNo) $("[aria-label='Next']").parent().prop("disabled", true); else $("[aria-label='Next']").parent().prop("disabled", false); if(this.activePageNo === this.lastPageNo) $("[aria-label='Last']").parent().prop("disabled", true); else $("[aria-label='Last']").parent().prop("disabled", false); */ } PlayerListNavigator.prototype.onClickPageNo = function(pageNo) { console.log(pageNo); switch(pageNo) { case "first": this.activePageNo = 1; break; case "previous": if(this.activePageNo > 1) this.activePageNo -= 1; break; case "next": if(this.activePageNo < this.lastPageNo) this.activePageNo += 1; break; case "last": this.activePageNo = this.lastPageNo; break; default: this.activePageNo = pageNo; } console.log(this.activePageNo); this.playerListManager.onClickPageNo(this.activePageNo); }