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:
parent
0c11498905
commit
379d9ce1f7
1 changed files with 42 additions and 30 deletions
|
@ -68,12 +68,12 @@ var browseByVClass = {
|
|||
// Load individuals for default class as specified by menupage template
|
||||
defaultVClass: function() {
|
||||
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
|
||||
getIndividuals: function(vclassUri, alpha, page) {
|
||||
getIndividuals: function(vclassUri, alpha, page, scroll) {
|
||||
url = this.dataServiceUrl + encodeURIComponent(vclassUri);
|
||||
if ( alpha && alpha != "all") {
|
||||
url += '&alpha=' + alpha;
|
||||
|
@ -83,6 +83,9 @@ var browseByVClass = {
|
|||
} else {
|
||||
page = 1;
|
||||
}
|
||||
if ( typeof scroll === "undefined" ) {
|
||||
scroll = true;
|
||||
}
|
||||
|
||||
// First wipe currently displayed individuals and existing pagination
|
||||
this.individualsInVClass.empty();
|
||||
|
@ -92,34 +95,7 @@ var browseByVClass = {
|
|||
// Check to see if we're dealing with pagination
|
||||
if ( results.pages.length ) {
|
||||
pages = results.pages;
|
||||
|
||||
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();
|
||||
browseByVClass.pagination(pages, page);
|
||||
}
|
||||
|
||||
$.each(results.individuals, function(i, item) {
|
||||
|
@ -150,9 +126,45 @@ var browseByVClass = {
|
|||
// Set selected class, alpha and page
|
||||
browseByVClass.selectedVClass(results.vclass.URI);
|
||||
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
|
||||
selectedVClass: function(vclassUri) {
|
||||
// Remove active class on all vClasses
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue