throw"in Bootstrap version 2 the pagination must be a div element. Or if you are using Bootstrap pagination 3. Please specify it in bootstrapMajorVersion in the option";
}elseif(version>2&&!this.$element.is("ul")){
throw"in Bootstrap version 3 the pagination root item must be an ul element."
if(page>this.totalPages||page<1){// if the current page is out of range, throw exception.
throw"Page out of range";
}
this.lastPage=this.currentPage;
this.currentPage=parseInt(page,10);
},
/**
* Gets an array that represents the current status of the page object. Numeric pages can be access via array mode. length attributes describes how many numeric pages are there. First, previous, next and last page can be accessed via attributes first, prev, next and last. Current attribute marks the current page within the pages.
*
* @return object output objects that has first, prev, next, last and also the number of pages in between.
* */
getPages:function(){
vartotalPages=this.totalPages,// get or calculate the total pages via the total records
pageStart=(this.currentPage%this.numberOfPages===0)?(parseInt(this.currentPage/this.numberOfPages,10)-1)*this.numberOfPages+1:parseInt(this.currentPage/this.numberOfPages,10)*this.numberOfPages+1,//calculates the start page.
output=[],
i=0,
counter=0;
pageStart=pageStart<1?1:pageStart;//check the range of the page start to see if its less than 1.
for(i=pageStart,counter=0;counter<this.numberOfPages&&i<=totalPages;i=i+1,counter=counter+1){//fill the pages
output.push(i);
}
output.first=1;//add the first when the current page leaves the 1st page.
if(this.currentPage>1){// add the previous when the current page leaves the 1st page
output.prev=this.currentPage-1;
}else{
output.prev=1;
}
if(this.currentPage<totalPages){// add the next page when the current page doesn't reach the last page
output.next=this.currentPage+1;
}else{
output.next=totalPages;
}
output.last=totalPages;// add the last page when the current page doesn't reach the last page
output.current=this.currentPage;//mark the current page.
output.total=totalPages;
output.numberOfPages=this.options.numberOfPages;
returnoutput;
},
/**
* Gets the value from the options, this is made to handle the situation where value is the return value of a function.
*
* @return mixed value that depends on the type of parameters, if the given parameter is a function, then the evaluated result is returned. Otherwise the parameter itself will get returned.