NIHVIVO-1948 Pulled pagination out into its own function so it can be called by the default file and any product extension. Also introduced scrolling to getIndividuals(). Not sure if we'll keep this.

This commit is contained in:
nac26 2011-01-31 04:03:32 +00:00
parent 0c11498905
commit 379d9ce1f7

View file

@ -68,12 +68,12 @@ var browseByVClass = {
// Load individuals for default class as specified by menupage template // Load individuals for default class as specified by menupage template
defaultVClass: function() { defaultVClass: function() {
if ( this.defaultBrowseVClassURI != "false" ) { if ( this.defaultBrowseVClassURI != "false" ) {
this.getIndividuals(this.defaultBrowseVClassUri); this.getIndividuals(this.defaultBrowseVClassUri, "all", 1, false);
} }
}, },
// Where all the magic happens -- gonna fetch me some individuals // Where all the magic happens -- gonna fetch me some individuals
getIndividuals: function(vclassUri, alpha, page) { getIndividuals: function(vclassUri, alpha, page, scroll) {
url = this.dataServiceUrl + encodeURIComponent(vclassUri); url = this.dataServiceUrl + encodeURIComponent(vclassUri);
if ( alpha && alpha != "all") { if ( alpha && alpha != "all") {
url += '&alpha=' + alpha; url += '&alpha=' + alpha;
@ -83,6 +83,9 @@ var browseByVClass = {
} else { } else {
page = 1; page = 1;
} }
if ( typeof scroll === "undefined" ) {
scroll = true;
}
// First wipe currently displayed individuals and existing pagination // First wipe currently displayed individuals and existing pagination
this.individualsInVClass.empty(); this.individualsInVClass.empty();
@ -92,34 +95,7 @@ var browseByVClass = {
// Check to see if we're dealing with pagination // Check to see if we're dealing with pagination
if ( results.pages.length ) { if ( results.pages.length ) {
pages = results.pages; pages = results.pages;
browseByVClass.pagination(pages, page);
pagination = '<nav class="pagination menupage">';
pagination += '<h3>page</h3>';
pagination += '<ul>';
$.each(pages, function(i, item) {
anchorOpen = '<a class="page'+ pages[i].text +' round" href="#" title="View page '+ pages[i].text +' of the results">';
anchorClose = '</a>';
pagination += '<li class="page'+ pages[i].text;
pagination += ' round';
// Test for active page
if ( pages[i].text == page) {
pagination += ' selected';
anchorOpen = "";
anchorClose = "";
}
pagination += '" role="listitem">';
pagination += anchorOpen;
pagination += pages[i].text;
pagination += anchorClose;
pagination += '</li>';
})
pagination += '</ul>';
// Add the pagination above and below the list of individuals and call the listener
browseByVClass.individualsContainer.prepend(pagination);
browseByVClass.individualsContainer.append(pagination);
browseByVClass.paginationListener();
} }
$.each(results.individuals, function(i, item) { $.each(results.individuals, function(i, item) {
@ -150,9 +126,45 @@ var browseByVClass = {
// Set selected class, alpha and page // Set selected class, alpha and page
browseByVClass.selectedVClass(results.vclass.URI); browseByVClass.selectedVClass(results.vclass.URI);
browseByVClass.selectedAlpha(alpha); browseByVClass.selectedAlpha(alpha);
// Scroll to the top of the browse section unless told otherwise
if ( scroll != false ) {
$.scrollTo('#browse-by', 500);
}
}); });
}, },
// Print out the pagination nav if called
pagination: function(pages, page) {
pagination = '<nav class="pagination menupage">';
pagination += '<h3>page</h3>';
pagination += '<ul>';
$.each(pages, function(i, item) {
anchorOpen = '<a class="page'+ pages[i].text +' round" href="#" title="View page '+ pages[i].text +' of the results">';
anchorClose = '</a>';
pagination += '<li class="page'+ pages[i].text;
pagination += ' round';
// Test for active page
if ( pages[i].text == page) {
pagination += ' selected';
anchorOpen = "";
anchorClose = "";
}
pagination += '" role="listitem">';
pagination += anchorOpen;
pagination += pages[i].text;
pagination += anchorClose;
pagination += '</li>';
})
pagination += '</ul>';
// Add the pagination above and below the list of individuals and call the listener
browseByVClass.individualsContainer.prepend(pagination);
browseByVClass.individualsContainer.append(pagination);
browseByVClass.paginationListener();
},
// Toggle the active class so it's clear which is selected // Toggle the active class so it's clear which is selected
selectedVClass: function(vclassUri) { selectedVClass: function(vclassUri) {
// Remove active class on all vClasses // Remove active class on all vClasses