//Create loader object window.loader = {}; window.loader.setupSidebar = function (contents) { window.loader.sidebar_contents = jQuery.extend(true, {}, contents); }; window.loader.setupPage = function (page) { window.loader.page_contents = jQuery.extend(true, {}, page); }; //Initialise the various page's content window.loader.initialisePages = function () { var loader = window.loader; //Create object for the sidebar's contents loader.sidebar_contents = {}; loader.page_contents = {}; }; //Loads topbar window.loader.loadTopbar = function () { $('#topbar').load('topbar.html') }; window.loader.generateSidebarItem = function (icon, text, link) { var sidebar_item = '' + '\n' + '\n' ; return sidebar_item; }; //Loads sidebar window.loader.loadSidebar = function () { //$('#sidebar').load('factors_social_sidebar.html') var loader = window.loader; var sidebar_break = '\n\n'; var sidebar_item = loader.sidebar_contents[0]; document.getElementById('sidebar').innerHTML += loader.generateSidebarItem(sidebar_item.icon, sidebar_item.text, sidebar_item.link); for (var i = 1;i < loader.sidebar_contents.size;i++) { sidebar_item = loader.sidebar_contents[i]; document.getElementById('sidebar').innerHTML += sidebar_break; document.getElementById('sidebar').innerHTML += loader.generateSidebarItem(sidebar_item.icon, sidebar_item.text, sidebar_item.link); } }; //Prepares window.loader.arguements window.loader.prepareArguements = function () { //Define arguements if not already defined if (typeof loader.arguements === 'undefined') { loader.arguements = {}; } //prepare args var args = window.location.search; args = args.slice(1, args.length); //Get rid of the leading '?' //Extract all arguements seperated by ampersands(&) while (args.length > 0) { var ampersand_location = args.lastIndexOf('&'); //Get location of last ampersand //Move the last arguement to arg and remove from args var arg = args.slice(ampersand_location+1, args.length); if (ampersand_location == -1) { ampersand_location = 0; } args = args.slice(0, ampersand_location); //console.log("ampersand_location: " + ampersand_location); //console.log("arg: " + arg); //console.log("args: " + args); //Find arguement name and value var arg_name, arg_value; { var arg_equal_location = arg.indexOf('='); //Get position of equals //If there isn't an equals, define the variable and set value to null if (arg_equal_location == -1) { arg_name = arg; arg_value = null; } else { //If there is a equals, defind the variable and set the value arg_name = arg.slice(0, arg_equal_location); arg_value = arg.slice(arg_equal_location+1, arg.length); } //console.log("arg_name: " + arg_name); //console.log("arg_value: " + arg_value); } //Add arg to loader.arguements loader.arguements[arg_name] = arg_value; } }; window.loader.loadPage = function (page) { var loader = window.loader; document.getElementById('page').innerHTML = loader.page_contents[loader.arguements['page']].innerHTML //Shorten window.location to loc /*var loc = window.location; //Prepare loc.pathname stuff var pathname_dot_location = loc.pathname.lastIndexOf('.'); var pathname_page_name = loc.pathname.slice(0, pathname_dot_location); var pathname_page_extension = loc.pathname.slice(pathname_dot_location, loc.pathname.length); //Make path variable var path = loc.origin + pathname_page_name + '_' + page + pathname_page_extension; //console.log(path); //Load page $('#page').load(path)*/ };