/* $This file is distributed under the terms of the license in /doc/license.txt$ */ var browseClassGroups = { // Initial page setup onLoad: function() { this.mergeFromTemplate(); this.initObjects(); this.bindEventListeners(); }, // Add variables from browse template mergeFromTemplate: function() { $.extend(this, browseData); }, // Create references to frequently used elements for convenience initObjects: function() { this.vClassesInClassGroup = $('ul#classes-in-classgroup'); this.browseClassGroupLinks = $('#browse-classgroups li a'); }, // Event listeners. Called on page load bindEventListeners: function() { // Listener for classGroup switching this.browseClassGroupLinks.click(function() { uri = $(this).attr("data-uri"); browseClassGroups.getVClasses(uri); return false; }); // Call the bar chart highlighter listener this.chartHighlighterListener(); }, // Listener for bar chart highlighting -- separate from the rest because it needs to be callable chartHighlighterListener: function() { // This essentially replicates the native Raphael hover behavior (see chart.hover below) // but allows us to trigger it via jQuery from the list of classes adjacent to the chart $('ul#classes-in-classgroup li a').hover(function() { var classIndex = $('ul#classes-in-classgroup li a').index(this); $('#visual-graph svg path').eq(classIndex).attr('fill', '#ccc'); $('#visual-graph svg text').eq(classIndex).toggle(); return false; }, function() { var classIndex = $('ul#classes-in-classgroup li a').index(this); $('#visual-graph svg path').eq(classIndex).attr('fill', '#999'); $('#visual-graph svg text').eq(classIndex).toggle(); }) }, // Load classes and chart for default class group as defined by template defaultClassGroup: function() { if ( this.defaultBrowseClassGroupURI != "false" ) { this.getVClasses(this.defaultBrowseClassGroupUri); } }, // Where all the magic happens -- gonna fetch me some classes getVClasses: function(classgroupUri, alpha) { url = this.dataServiceUrl + encodeURIComponent(classgroupUri); if ( alpha && alpha != "all") { url = url + '&alpha=' + alpha; } // First wipe currently displayed classes this.vClassesInClassGroup.empty(); var values = [], labels = [], uris = []; $.getJSON(url, function(results) { $.each(results.classes, function(i, item) { name = results.classes[i].name; uri = results.classes[i].URI; indivCount = results.classes[i].entityCount; indexUrl = browseClassGroups.baseUrl + '/individuallist?vclassId=' + encodeURIComponent(uri); // Only add to the arrays and render classes when they aren't empty if ( indivCount > 0 ) { values.push(parseInt(indivCount, 10)); labels.push(name + ' (' + parseInt(indivCount, 10) +')'); uris.push(uri); // Build the content of each list item, piecing together each component listItem = '