Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //////// Global variables ////////
- /// The current hash, in the format #hash_here
- var current_hash = "";
- /// The tabs, all of them, every last one. When a new tab is requested,
- /// this variable is checked for the existence of that tab. If it does
- /// not exist, the content is pulled from the server and dumped in here.
- /// If it does exist, the content is pulled from this variable. This
- /// way, you pull the minimum amount of data from the server as possible.
- // uses the php function to minimize the amount of calls to the server.
- //<?php admin::print_js_site(); ?>
- var site = {
- title : "Farraginous Fumblings",
- modules : {
- "pages" : {
- id : "pages",
- title: "Pages",
- "pages" : {
- view : {
- id : "view",
- title : "View all pages",
- onload : function() { // todo: update pages list
- },
- content : "The view page",
- loaded : true
- },
- new_page : {
- id : "new_page",
- title : "Create a new page",
- content : "loading...",
- loaded : false
- }
- },
- current_page : "view"
- }
- },
- current_module : "pages",
- default_module : "pages",
- has_module : function (id) {
- if ( this.modules[id] ) { return true; }
- else { return false; }
- },
- set_module : function (id) {
- if ( this.has_module( id ) ) {
- this.current_module = id;
- }
- else { alert("ERROR: set_module: no such module '" + id + "'." ); }
- },
- get_current_page : function () { return this.modules[this.current_module].pages[this.current_page]; },
- get_current_module : function () { return this.modules[this.current_module]; },
- has_page : function (id) { if ( this.get_current_module().pages[id] ) { return true; } else { return false; } },
- set_page : function (id) {
- if ( this.has_page( id ) ) {
- this.get_current_module().current_page = id;
- if ( this.get_current_module().pages[id].loaded == false ) {
- /*$.getJSON( "?admin_ajax=get_page&module="+get_current_module().id+"&page="id, function( data ) {
- this.get_current_module().pages[id].loaded = true;
- this.get_current_module().pages[id].content = data;
- });*/
- // get contents, then update.
- }
- else {
- if ( this.get_current_module().pages[id].onload ) {
- this.get_current_module().pages[id].onload();
- }
- update();
- }
- }
- else { alert("ERROR: set_page: no such page '" + id +"' in module '" + this.get_current_module().id + "'." ); }
- },
- url_change : function (name) {
- //alert( "hash changed to '" + current_hash + "'." );
- name = name.split('/');
- if ( name[0] ) {
- if ( this.has_module( name[0] ) ) {
- if ( name[0] != this.get_current_module().id ) {
- this.set_module( name[0] );
- if ( name[1] ) {
- if ( this.has_page( name[1] ) ) {
- alert(" hello sweetie");
- this.set_page( name[1] );
- update();
- }
- // TOOD error
- else { alert( "Error: page '" + name[1] + "' doesn't exist. Don't know why. Sorry." ); }
- }
- else {
- alert("oh uh");
- this.set_page( this.get_current_module().current_page );
- update();
- }
- }
- }
- else { alert( "Error: module '" + name[0] + "' doesn't exist. Haha." ); }
- }
- else {
- this.set_module( site.default_module );
- this.set_page( site.get_current_module().current_page );
- update();
- }
- }
- }
- /*
- * ##############################3
- * Should load tabs & their pages list. Should only REQUEST a tab's page.
- * WHY? Because that way, it'll be neater. Perhaps load all of a tabs pages
- * probably not though.
- * Need to provide a php ajax for getting a tab and getting all tabs
- * Maybe restructure thing to include site variables as well, ie. site.title, site.modules["page"].title
- * Yeah, I like that.
- * >> I like this better
- * site.current_module.title
- * site.title
- * site.modules["page"].title
- * site.current_module.title
- * site.current_module.current_page.title
- * site.current_module.pages["view"].title
- * ##############################
- */
- //////// The startup function ////////
- /// Initialises the [tabs] and sets the [current_hash].
- $(document).ready( function() {
- if ( window.location.hash ) {
- current_hash = window.location.hash;
- }
- site.url_change( window.location.hash.substr(1) );
- update();
- setInterval( "check_hash()", 150);
- });
- //////// Functions ////////
- /// check_hash checks if the hash has changed, and if it has, it calls
- /// load_content().
- function check_hash() {
- if ( window.location.hash == current_hash ) {
- return;
- }
- // else there must be a different hash, so new content to load
- current_hash = window.location.hash;
- // load the content - .substr removes the # from the hash.
- site.url_change( window.location.hash.substr(1) );
- }
- /// Updates the front-page content.
- function update() {
- site.get_current_module();
- $("._page_title").html( site.get_current_page().title );
- $("._page_content").html( site.get_current_page().content );
- page_menu = "<ul>";
- for( i in site.get_current_module().pages ) {
- page_menu += '<li><a href="#'
- +site.get_current_module().id + '/'
- + site.get_current_module().pages[i].id
- + '">'
- + site.get_current_module().pages[i].title
- + '</a></li>';
- }
- page_menu += "</ul>";
- $("._page_menu").html( page_menu );
- module_menu = "<ul>";
- for ( i in site.modules ) {
- module_menu += '<li><a href="#'+ site.modules[i].id + '">'
- + site.modules[i].title + '</a></li>';
- }
- module_menu += "</ul>";
- $("._module_menu").html( module_menu );
- $("._module_title").html(
- site.get_current_module().title
- );
- }
Add Comment
Please, Sign In to add comment