I wrote this script to make a blogging site but the virtual pagination appears on every tab. How do I create virtual pagination for individual tabs. I wrote a code but Here is the code
// -------------------------------------------------------------------// Virtual Pagination Script- By Dynamic Drive, available at: http://www.dynamicdrive.com// Last updated: May 31st, 2007//// PUBLIC: virtualpaginate(className, chunksize)// Main Virtual Paginate Object function.// -------------------------------------------------------------------
JavaScript
functionvirtualpaginate(className, chunksize, elementType){
var elementType=(typeof elementType=="undefined")? "div" : elementType //The type of element used to divide up content into pieces. Defaults to "div"this.pieces=virtualpaginate.collectElementbyClass(className, elementType) //get total number of divs matching class name//Set this.chunksize: 1 if "chunksize" param is undefined, "chunksize" if it's less than total pieces available, or simply total pieces avail (show all)this.chunksize=(typeof chunksize=="undefined")? 1 : (chunksize>0 && chunksize <this.pieces.length)? chunksize : this.pieces.lengththis.pagecount=Math.ceil(this.pieces.length/this.chunksize) //calculate number of "pages" needed to show the divsthis.showpage(-1) //show no pages (aka hide all)this.currentpage=0//Having hidden all pages, set currently visible page to 1st pagethis.showpage(this.currentpage) //Show first page
}
Code
// -------------------------------------------------------------------
// PRIVATE: collectElementbyClass(classname)- Returns an array containing DIVs with the specified classname
// -------------------------------------------------------------------
JavaScript
virtualpaginate.collectElementbyClass=function(classname, element){
//Returns an array containing DIVs with specified classnamevar classnameRE=newRegExp("(^|\\s+)"+classname+"($|\\s+)", "i") //regular expression to screen for classname within elementvar pieces=[]
var alltags=document.getElementsByTagName(element)
for (var i=0; i<alltags.length; i++){
if (typeof alltags[i].className=="string" && alltags[i].className.search(classnameRE)!=-1)
pieces[pieces.length]=alltags[i]
}
return pieces
}
Code
// -------------------------------------------------------------------
// PUBLIC: showpage(pagenumber)- Shows a page based on parameter passed (0=page1, 1=page2 etc)
// -------------------------------------------------------------------
JavaScript
virtualpaginate.prototype.showpage=function(pagenumber){
var totalitems=this.pieces.length//total number of broken up divsvar showstartindex=pagenumber*this.chunksize//array index of div to start showing per pagenumber settingvar showendindex=showstartindex+this.chunksize-1//array index of div to stop showing after per pagenumber settingfor (var i=0; i=showstartindex && i element is present, update it with the most current info (ie: Page3/4)
this.cpspan.innerHTML='Page '+(this.currentpage+1)+'/'+this.pagecount
}
C#
// -------------------------------------------------------------------// PRIVATE: paginate_build_() methods- Various methods to create pagination interfaces// paginate_build_selectmenu(paginatedropdown)- Accepts an empty SELECT element and turns it into pagination menu// paginate_build_regularlinks(paginatelinks)- Accepts a collection of links and screens out/ creates pagination out of ones with specific "rel" attr// paginate_build_flatview(flatviewcontainer)- Accepts element and replaces it with sequential pagination links// paginate_build_cpinfo(cpspan)- Accepts element and displays current page info (ie: Page 1/4)// -------------------------------------------------------------------
JavaScript
virtualpaginate.prototype.paginate_build_selectmenu=function(paginatedropdown, anchortext){
var instanceOfBox=thisvar anchortext=anchortext || newArray()
this.selectmenupresent=1for (var i=0; i<this.pagecount; i++){
if (typeof anchortext[i]!="undefined") //if custom anchor text for this link exists, use anchor text as each OPTION's text
paginatedropdown.options[i]=newOption(anchortext[i], i)
else//else, use auto incremented, sequential numbers
paginatedropdown.options[i]=newOption("Page "+(i+1)+" of "+this.pagecount, i)
}
paginatedropdown.selectedIndex=this.currentpage
paginatedropdown.onchange=function(){
instanceOfBox.showpage(this.selectedIndex)
}
}
JavaScript
virtualpaginate.prototype.paginate_build_regularlinks=function(paginatelinks){
var instanceOfBox=thisfor (var i=0; i<paginatelinks.length; i++){
var currentpagerel=paginatelinks[i].getAttribute("rel")
if (currentpagerel=="previous" || currentpagerel=="next" || currentpagerel=="first" || currentpagerel=="last") //screen for these "rel" values
paginatelinks[i].onclick=function(){
instanceOfBox.navigate(this.getAttribute("rel"))
returnfalse
}
}
}
Code
virtualpaginate.prototype.paginate_build_flatview=function(flatviewcontainer, anchortext){
var instanceOfBox=this
var flatviewhtml=""
var anchortext=anchortext || new Array()
for (var i=0; i'+anchortext[i]+' ' //build pagination link using custom anchor text
else
flatviewhtml+=''+(i+1)+' ' //build pagination link using auto incremented sequential number instead
}
flatviewcontainer.innerHTML=flatviewhtml
this.flatviewlinks=flatviewcontainer.getElementsByTagName("a")
for (var i=0; i<this.flatviewlinks.length; i++){
this.flatviewlinks[i].onclick=function(){
instanceOfBox.flatviewlinks[instanceOfBox.currentpage].className="" //"Unhighlight" last flatview link clicked on...
this.className="selected" //while "highlighting" currently clicked on flatview link (setting its class name to "selected"
instanceOfBox.showpage(this.getAttribute("rel"))
return false
}
}
this.flatviewlinks[this.currentpage].className="selected" //"Highlight" current page
this.flatviewpresent=true //indicate flat view links are present
}
// -------------------------------------------------------------------
// PRIVATE: buildpagination()- Create pagination interface by calling one or more of the paginate_build_() functions
// -------------------------------------------------------------------
JavaScript
virtualpaginate.prototype.buildpagination=function(divid, optnavtext){
var instanceOfBox=thisvar paginatediv=document.getElementById(divid)
if (this.chunksize==this.pieces.length){ //if user has set to display all pieces at once, no point in creating pagination div
paginatediv.style.display="none"return
}
var paginationcode=paginatediv.innerHTML//Get user defined, "unprocessed" HTML within paginate divif (paginatediv.getElementsByTagName("select").length>0) //if there's a select menu in divthis.paginate_build_selectmenu(paginatediv.getElementsByTagName("select")[0], optnavtext)
if (paginatediv.getElementsByTagName("a").length>0) //if there are links defined in divthis.paginate_build_regularlinks(paginatediv.getElementsByTagName("a"))
var allspans=paginatediv.getElementsByTagName("span") //Look for span tags within passed divfor (var i=0; i<allspans.length; i++){
if (allspans[i].className=="flatview")
this.paginate_build_flatview(allspans[i], optnavtext)
elseif (allspans[i].className=="paginateinfo")
this.paginate_build_cpinfo(allspans[i])
}
this.paginatediv=paginatediv
}
Code
// -------------------------------------------------------------------
// PRIVATE: navigate(keyword)- Calls this.showpage() with the currentpage property preset based on entered keyword
// -------------------------------------------------------------------
Answers
Know the answer? Post it. Somebody with the same question will find it here.