(function ($, GLOBAL) { var TOOLBAR_TEMPLATE = '
The current version does not support user management.
COST ESTIMATE
', RUN_LINE_TEMPLATE = '
  • TITLEDESCRIPTION
  • ', TABLE_LINE_TEMPLATE = 'KEYVALUE'; // ======================================================================== // Helper // ======================================================================== function projectInfoToHTML(info, path) { var projectDescription = "", exclude = { "title": 1, "description": 1, "analysis": 1, "path": 1 }; // Update project description projectDescription += TABLE_LINE_TEMPLATE.replace(/KEY/g, "Name").replace(/VALUE/g, info.title); projectDescription += TABLE_LINE_TEMPLATE.replace(/KEY/g, "Description").replace(/VALUE/g, info.description); for(var key in info) { if(!exclude.hasOwnProperty(key)) { projectDescription += TABLE_LINE_TEMPLATE.replace(/KEY/g, key).replace(/VALUE/g, info[key]); } } projectDescription += "
    "; return projectDescription; } // ------------------------------------------------------------------------ function handlePath(fullPath, projectPath) { if(projectPath.indexOf("http://") === 0 || projectPath.indexOf("https://") === 0 || projectPath.indexOf("file://") === 0) { return projectPath; } else { // Relative path var basePath = fullPath.substr(0, 1 + fullPath.lastIndexOf("/")); return basePath + projectPath; } } // ------------------------------------------------------------------------ function createControlToolbar(container, projectList, fullURL) { // Fill run list var count = projectList.length, buffer = []; while(count--) { buffer.push(RUN_LINE_TEMPLATE.replace(/PATH/g, handlePath(fullURL, projectList[count].path)).replace(/TITLE/g, projectList[count].title).replace(/DESCRIPTION/g, projectList[count].description)); } container.html(TOOLBAR_TEMPLATE); $('.run-content', container).html(buffer.join('')); } // ------------------------------------------------------------------------ function initializeListeners(container) { // Handle view/button toggle $('.toggle-button', container).addClass('action').click(function(){ var me = $(this), group = me.attr('data-group'), view = me.attr('data-view'), animation = me.attr('data-animation'), isActive = me.hasClass('active'), buttons = $('.toggle-button[data-group="' + group + '"]', container), contents = $('.toggle-content[data-group="' + group + '"]', container); // Disable all buttons.removeClass('active'); if(animation && isActive) { contents.animate({ left: "-1000" }, 500, function() { // Animation complete. contents.hide(); }); } else { contents.hide(); } // Enable local one if not previously active if(!isActive) { me.addClass('active'); if(animation) { $('.toggle-content.' + view, container).show().animate({ left: "0" }, 500, function() { // Animation complete. }); } else { $('.toggle-content.' + view, container).show(); } } else { $('.default-toggle[data-group="' + group + '"]', container).trigger('click'); } }); // Load run $('.select-run', container).addClass('action').click(function(){ var me = $(this), basePath = me.attr('data-path'); // Load project $.ajax({ url: basePath + '/info.json', dataType: 'json', success: function( data ) { $('.toggle-button[data-group="runs"]', container).click(); // Store metadata container.data('project', data); // Add project description / viewers / search / cost $('.info-content', container).empty().html(projectInfoToHTML(data, basePath)); $('.bench-content', container).vtkCatalystAnalysisBench(data, basePath); $('.search-content', container).vtkCatalystAnalysisSearch(data, basePath); $('.cost-content', container).vtkCatalystAnalysisCost(data, basePath); // Update title document.title = data.title; // Show default $('.default-toggle[data-group="content"]', container).trigger('click'); }, error: function(error) { console.log("error when trying to download " + basePath + '/info.json'); console.log(error); } }); // Enable toolbar $('li.need-project', container).css('display', "inline"); }); } /** * jQuery catalyst view constructor. * * @member jQuery.vtkCatalystViewer * @param basePath * Root directory for data to visualize */ $.fn.vtkCatalystAnalysis = function(fullURL) { return this.each(function() { var me = $(this).unbind().empty().addClass('vtkweb-catalyst-analysis'); // Get meta-data $.ajax({ url: fullURL, dataType: 'json', success: function( data ) { // Store metadata me.data('projects', data); // Create project list createControlToolbar(me, data, fullURL); // Attach interaction listeners initializeListeners(me); // Add general purpose cost estimate $('.estimate-content',me).vtkCatalystAnalysisCostEstimate(); }, error: function(error) { console.log("error when trying to download " + fullURL); console.log(error); } }); }); } }(jQuery, window));