/* $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(); }, // 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() { uri = $(this).attr('data-uri'); browseByVClass.getIndividuals(uri); }); this.browseVClassLinks.click(function() { uri = $(this).attr('data-uri'); browseByVClass.getIndividuals(uri); return false; }); // Listener for alpha switching this.alphaIndexLinks.click(function() { uri = $('#browse-classes li a.selected').attr('data-uri'); 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() { uri = $('#browse-classes li a.selected').attr('data-uri'); alpha = $('#alpha-browse-individuals li a.selected').attr('data-alpha'); 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) { 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 scrollPosition = browseByVClass.getPageScroll(); browseByOffset = $('#browse-by').offset(); if ( scrollPosition[1] > browseByOffset.top) { $.scrollTo('#menupage-intro', 500); } } $.getJSON(url, function(results) { 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 { $.each(results.individuals, function(i, item) { label = results.individuals[i].label; moniker = results.individuals[i].moniker; vclassName = results.individuals[i].vclassName; uri = results.individuals[i].URI; profileUrl = results.individuals[i].profileUrl; if ( results.individuals[i].thumbUrl ) { image = browseByVClass.baseUrl + results.individuals[i].thumbUrl; } // Build the content of each list item, piecing together each component listItem = '
  • '; if ( typeof results.individuals[i].thumbUrl !== "undefined" ) { listItem += ''+ label +'

    '; } else { listItem += '

    '; } listItem += ''+ label +'

    '; // Include the moniker only if it's not empty and not equal to the VClass name if ( moniker != vclassName && moniker != "" ) { listItem += ''+ moniker +''; } listItem += '
  • '; // browseByVClass.individualsInVClass.append(listItem); individualList += listItem; }) // Remove existing content browseByVClass.wipeSlate(); // And then add the new content browseByVClass.individualsInVClass.append(individualList); // Check to see if we're dealing with pagination if ( results.pages.length ) { pages = results.pages; browseByVClass.pagination(pages, page); } } // Set selected class, alpha and page // Do this whether or not there are any results $('h3.selected-class').text(results.vclass.name); browseByVClass.selectedVClass(results.vclass.URI); browseByVClass.selectedAlpha(alpha); }); }, // getPageScroll() by quirksmode.org getPageScroll: function() { var xScroll, yScroll; if (self.pageYOffset) { yScroll = self.pageYOffset; xScroll = self.pageXOffset; } else if (document.documentElement && document.documentElement.scrollTop) { yScroll = document.documentElement.scrollTop; xScroll = document.documentElement.scrollLeft; } else if (document.body) {// all other Explorers yScroll = document.body.scrollTop; xScroll = document.body.scrollLeft; } return new Array(xScroll,yScroll) }, // Print out the pagination nav if called pagination: function(pages, page) { pagination = '