/* $This file is distributed under the terms of the license in /doc/license.txt$ */ var browseByVClass = { // Initial page setup onLoad: function() { this.mergeFromTemplate(); this.initObjects(); this.bindEventListeners(); this.defaultVClass(); }, // Add variables from menupage template mergeFromTemplate: function() { $.extend(this, menupageData); }, // Create references to frequently used elements for convenience initObjects: function() { this.vgraphVClasses = $('#vgraph-classes'); this.vgraphVClassLinks = $('#vgraph-classes li a'); this.browseVClasses = $('#browse-classes'); this.browseVClassLinks = $('#browse-classes li a'); this.alphaIndex = $('#alpha-browse-individuals'); this.alphaIndexLinks = $('#alpha-browse-individuals li a'); this.individualsInVClass = $('#individuals-in-class ul'); this.individualsContainer = $('#individuals-in-class'); }, // Event listeners. Called on page load bindEventListeners: function() { // Listeners for vClass switching this.vgraphVClassLinks.click(function() { var uri = $(this).attr('data-uri'); browseByVClass.getIndividuals(uri); }); this.browseVClassLinks.click(function() { var uri = $(this).attr('data-uri'); browseByVClass.getIndividuals(uri); return false; }); // Listener for alpha switching this.alphaIndexLinks.click(function() { var uri = $('#browse-classes li a.selected').attr('data-uri'); var alpha = $(this).attr('data-alpha'); browseByVClass.getIndividuals(uri, alpha); return false; }); // Call the pagination listener this.paginationListener(); }, // Listener for page switching -- separate from the rest because it needs to be callable paginationListener: function() { $('.pagination li a').click(function() { var uri = $('#browse-classes li a.selected').attr('data-uri'); var alpha = $('#alpha-browse-individuals li a.selected').attr('data-alpha'); var page = $(this).attr('data-page'); browseByVClass.getIndividuals(uri, alpha, page); return false; }); }, // Load individuals for default class as specified by menupage template defaultVClass: function() { if ( this.defaultBrowseVClassURI != "false" ) { this.getIndividuals(this.defaultBrowseVClassUri, "all", 1, false); } }, // Where all the magic happens -- gonna fetch me some individuals getIndividuals: function(vclassUri, alpha, page, scroll) { var url = this.dataServiceUrl + encodeURIComponent(vclassUri); if ( alpha && alpha != "all") { url += '&alpha=' + alpha; } if ( page ) { url += '&page=' + page; } else { page = 1; } if ( typeof scroll === "undefined" ) { scroll = true; } // Scroll to #menupage-intro page unless told otherwise if ( scroll != false ) { // only scroll back up if we're past the top of the #browse-by section var scrollPosition = browseByVClass.getPageScroll(); var browseByOffset = $('#browse-by').offset(); if ( scrollPosition[1] > browseByOffset.top) { $.scrollTo('#menupage-intro', 500); } } $.getJSON(url, function(results) { var individualList = ""; // Catch exceptions when empty individuals result set is returned // This is very likely to happen now since we don't have individual counts for each letter and always allow the result set to be filtered by any letter if ( results.individuals.length == 0 ) { browseByVClass.emptyResultSet(results.vclass, alpha) } else { var vclassName = results.vclass.name; $.each(results.individuals, function(i, item) { var individual, label, mostSpecificTypes, uri, profileUrl, image, listItem; individual = results.individuals[i]; label = individual.label; mostSpecificTypes = individual.mostSpecificTypes; moreInfo = browseByVClass.getMoreInfo(mostSpecificTypes, vclassName); uri = individual.URI; profileUrl = individual.profileUrl; if ( individual.thumbUrl ) { image = browseByVClass.baseUrl + individual.thumbUrl; } // Build the content of each list item, piecing together each component listItem = '