1 var currentlyloaded = [];
4 * Loads the data for the clicked navigation item.
6 * @param {Object} clickednode The jquery object for the clicked node.
8 function handleClick(clickednode) {
10 var parentnodes = clickednode.parents('li');
11 for (var i = parentnodes.length; i >= 0; i--) {
12 var treenodes = window.$(parentnodes[i]);
13 if (treenodes.hasClass('item')) {
14 if (contextcrumb == '') {
15 contextcrumb = treenodes[0].innerText;
17 contextcrumb = contextcrumb + ' | ' + treenodes[0].innerText;
19 } else if (treenodes.hasClass('menu-item')) {
20 if (contextcrumb == '') {
21 contextcrumb = treenodes[0].firstChild.textContent;
23 contextcrumb = contextcrumb + ' | ' + treenodes[0].firstChild.textContent;
27 var datafile = clickednode.attr('data-var');
28 loadContent(datafile, function() {
29 addFileDataToMainArea(window[datafile], contextcrumb);
34 * Load content to be displayed.
36 * @param {String} datafile The json data to be displayed.
37 * @param {Function} callback The function to run after loading the json file.
39 function loadContent(datafile, callback) {
41 // Check to see if this file has already been loaded. If so just go straight to the callback.
42 if (fileIsLoaded(datafile)) {
47 // This (user_data_index) is defined in data_index.js
48 var data = window.user_data_index[datafile];
49 var newscript = document.createElement('script');
51 if (newscript.readyState) {
52 newscript.onreadystatechange = function() {
53 if (this.readyState == 'complete' || this.readyState == 'loaded') {
54 this.onreadystatechange = null;
59 newscript.onload = function() {
64 newscript.type = 'text/javascript';
66 newscript.charset = 'utf-8';
67 document.getElementsByTagName("head")[0].appendChild(newscript);
69 // Keep track that this file has already been loaded.
70 currentlyloaded.push(datafile);
74 * Checks to see if the datafile has already been loaded onto the page or not.
76 * @param {String} datafile The file entry we are checking to see if it is already loaded.
77 * @return {Boolean} True if already loaded otherwise false.
79 function fileIsLoaded(datafile) {
80 for (var index in currentlyloaded) {
81 if (currentlyloaded[index] == datafile) {
89 * Adds the loaded data to the main content area of the page.
91 * @param {Object} data Data to be added to the main content area of the page.
92 * @param {String} title Title for the content area.
94 function addFileDataToMainArea(data, title) {
95 var dataarea = window.$('[data-main-content]');
96 while (dataarea[0].firstChild) {
97 dataarea[0].removeChild(dataarea[0].firstChild);
99 var htmldata = makeList(data);
101 var areatitle = document.createElement('h2');
102 areatitle.innerHTML = title;
103 dataarea[0].appendChild(areatitle);
105 var maincontentlist = document.createElement('div');
106 maincontentlist.innerHTML = htmldata;
107 dataarea[0].appendChild(maincontentlist.firstChild);
111 * Creates an unordered list with the json data provided.
113 * @param {Object} jsondata The json data to turn into an unordered list.
114 * @return {String} The html string of the unordered list.
116 function makeList(jsondata) {
118 for (var key in jsondata) {
120 if (typeof jsondata[key] == 'object') {
122 html += makeList(jsondata[key]);
124 html += key + ': ' + jsondata[key];
132 window.$(document).ready(function() {
133 window.$('[data-var]').click(function(e) {
136 handleClick(window.$(this));