PDA

View Full Version : Virtual Pagination script (demo 4)



strat68
06-26-2008, 03:55 PM
Title: Virtual Pagination script (demo 4)
http://www.dynamicdrive.com/dynamicindex17/virtualpagination.htm

Question:
I've used demo 4 on this page to setup an event calendar of sorts (in lieu of finding one specifically for that purpose). On the virt. page script, it defaults to the first or leftmost "page." In the example below, I am breaking up the pages as "Jan-Feb" "Mar-Apr" etc...

example link here (http://www.patmedia.net/sjhorvath/schedule.htm)

My question is, could the systems date cause the current month to be the default first page. Reason being, it somewhat de-values an event calendar if it's say, July and the default page is always January.

Alternatively, if anyone knows of another tool to fulfill this purpose let me know.

Thanks,
Steve

Strangeplant
06-27-2008, 02:41 PM
Yes, you can do that with the instance.showpage(page_number) function. You need to write a java script function that is called when the page is loaded, the onload. The function would determine the month number, then change the variable to have 6 values, 0 through 5, and that is the variable to put in the showpage call that happens at onload.

BTW, the fix that I submitted months ago still hasn't been added to the code, I see. Without it, the item selected through the instance.showpage will not be highlighted correctly as it should be.

ddadmin
06-27-2008, 06:09 PM
Sure. The key is to use the supported function:

instance.showpage(page_number)

to directly go to a specific page within your Virtual Pages (see docs (http://www.dynamicdrive.com/dynamicindex17/virtualpagination_ref.htm)). In your case, following your initialization code, you'd add the part in red to it:


<script type="text/javascript">
var gallery=new virtualpaginate("virtualpage4", 1)
gallery.buildpagination("galleryalt", ["Jan-Feb", "Mar-Apr", "May-Jun", "Jul-Aug", "Sep-Oct", "Nov-Dec"])
var currentmonth=new Date().getMonth()+1 //get current month: 1-12
var currentmonthrange=Math.round(currentmonth/2)
gallery.showpage(currentmonthrange-1)
</script>

strat68
07-03-2008, 02:25 AM
BTW, the fix that I submitted months ago still hasn't been added to the code, I see. Without it, the item selected through the instance.showpage will not be highlighted correctly as it should be.

Hi Strangeplant, can I get the fix directly for now?

Thanks,
Steve

Strangeplant
08-18-2008, 12:51 PM
Sure, sorry that I haven't responded sooner (maybe this is too late), been busy and not on this board.

Just find the same section in the virtual pagination script, the one at: http://dynamicdrive.com/dynamicindex17/virtualpaginate.js, and fix it like this (additions are in red):

// -------------------------------------------------------------------
// PUBLIC: showpage(pagenumber)- Shows a page based on parameter passed (0=page1, 1=page2 etc)
// -------------------------------------------------------------------

virtualpaginate.prototype.showpage=function(pagenumber){
var totalitems=this.pieces.length //total number of broken up divs
var showstartindex=pagenumber*this.chunksize //array index of div to start showing per pagenumber setting
var showendindex=showstartindex+this.chunksize-1 //array index of div to stop showing after per pagenumber setting
if (this.flatviewpresent)
this.flatviewlinks[this.currentpage].className="" //"Unhighlight" previous page (before this.currentpage increments)
for (var i=0; i<totalitems; i++){
if (i>=showstartindex && i<=showendindex)
this.pieces[i].style.display="block"
else
this.pieces[i].style.display="none"
}
this.currentpage=parseInt(pagenumber)
if (this.cpspan) //if <span class="paginateinfo> element is present, update it with the most current info (ie: Page 3/4)
this.cpspan.innerHTML='Page '+(this.currentpage+1)+'/'+this.pagecount

if (this.flatviewpresent)
this.flatviewlinks[this.currentpage].className="selected" //"Highlight" current page
}