Team:RHIT/static/wiki.js

From 2012.igem.org

(Difference between revisions)
 
(16 intermediate revisions not shown)
Line 1: Line 1:
-
/*
+
var area = 'overview';
-
This file is part of the cambridge 2011 igem team's wiki. nothing is guaranteed.
+
 +
var subarea = 'home';
 +
//the url that's loaded
-
                    Version 2, December 2004
+
var the_url = window.location.pathname;
 +
//the url that's being displayed
-
Copyright (C) 2011 Haydn King hjking734@gmail.com
+
var int;
 +
//the interval
 +
var set_hash = function(path)
 +
{//set the hash to the path given
 +
  int = window.clearInterval(int);
 +
 
 +
  //turn the path into a presentable hash
 +
  var hash = path.replace(/http:\/\/2011.igem.org/i, '').replace(/\/Team:RHIT/i, '');
 +
 
 +
  window.location.hash = hash;
 +
  the_url = get_hash(false);
 +
 
 +
  int = setInterval('check_hash();', 500);
 +
}
-
  TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
var get_hash = function(absolute)
 +
{
 +
  var hash = window.location.hash.substr(1);
 +
  if(!absolute || (absolute == undefined))
 +
    return "/Team:RHIT" + hash;
 +
  return "https://2011.igem.org/Team:RHIT" + hash;
 +
}
 +
 
 +
var check_hash = function()
 +
{//check if the hash has changed (e.g. back button press)
 +
  if(the_url != get_hash(false))
 +
  {
 +
    int = clearInterval(int);//pause
 +
    if((window.location.hash.charAt(1) == '/') || (window.location.hash == ''))
 +
      load_url(get_hash(false));
 +
    int = setInterval('check_hash();', 500);
 +
  }
 +
}
 +
 
 +
//update the edit, login and logout links after page change
 +
var update_links = function(current_url)
 +
{
 +
  $('#edit-link').attr('href', current_url + '?action=edit');
 +
  $('#edit-intro-link').attr('href', '/Team:RHIT/desc/' + area + '/' + subarea + '?action=edit');
 +
  $('#login-link' ).attr('href', '/wiki/index.php?title=Special:UserLogin&returnto=' + current_url);
 +
  $('#logout-link').attr('href', '/wiki/index.php?title=Special:UserLogout&returnto=' + current_url);
 +
}
 +
 
 +
var is_internal = function(obj)
 +
{
 +
  if($(obj).hasClass('RHIT-external')) return false;
 +
  return /\/Team:RHIT/i.test($(obj).attr("href"));
 +
}
 +
 
 +
var is_external = function(obj) { return !is_internal(obj);}
 +
 
 +
var wiki_main = function() {
 +
  if((window.location.hash == '') || (window.location.hash == undefined) || !(window.location.hash.charAt(1) == '/'))
 +
  {
 +
    set_hash(the_url);
 +
  }
 +
  else
 +
  {
 +
    load_url(get_hash());
 +
  }
 +
}
-
*/
 
-
/*
 
-
** Removes iGEM style content, then pulls in the Cambridge Team's styling & javascript
 
-
*/
 
  var get_login = function()
  var get_login = function()
   {
   {
Line 32: Line 88:
     }
     }
   }
   }
-
 
-
  var head = "<title>Cambridge iGEM</title>" +
 
-
            "<link rel='stylesheet' type='text/css' href='/Team:Cambridge/static/wiki.css?action=raw&ctype=text/css' />";
 
-
 
-
  var script = '//ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js';
 
-
 
-
  var wiki_js = '/Team:Cambridge/static/wiki.js?action=raw&ctype=text/javascript';
 
-
  var intro_js ='/Team:Cambridge/static/introduction.js?action=raw&ctype=text/javascript';
 
-
 
-
   
 
-
$('head').html(head);
 
$(window).ready(function() {
$(window).ready(function() {
   var login = get_login();
   var login = get_login();
-
  $('body').html($('#cam_page'));
 
-
 
 
-
  //this is ugly, but it makes sure that the JS is loaded in the correct order
 
-
  $.getScript(script, function() {
 
-
    $.getScript(wiki_js, function() {
 
-
      $.getScript(intro_js, function() {
 
-
        wiki_main();
 
-
      });
 
-
    });
 
-
  });
 
-
 
 
-
  set_bk();
 
   set_login(login);
   set_login(login);
});
});

Latest revision as of 14:27, 19 July 2012

var area = 'overview';

var subarea = 'home'; //the url that's loaded

var the_url = window.location.pathname; //the url that's being displayed

var int; //the interval

var set_hash = function(path) {//set the hash to the path given

 int = window.clearInterval(int);
 
 //turn the path into a presentable hash
 var hash = path.replace(/http:\/\/2011.igem.org/i, ).replace(/\/Team:RHIT/i, );
 
 window.location.hash = hash;
 the_url = get_hash(false);
 
 int = setInterval('check_hash();', 500);

}

var get_hash = function(absolute) {

 var hash = window.location.hash.substr(1);
 if(!absolute || (absolute == undefined))
   return "/Team:RHIT" + hash;
 return "https://2011.igem.org/Team:RHIT" + hash;

}

var check_hash = function() {//check if the hash has changed (e.g. back button press)

 if(the_url != get_hash(false))
 {
   int = clearInterval(int);//pause
   if((window.location.hash.charAt(1) == '/') || (window.location.hash == ))
     load_url(get_hash(false));
   int = setInterval('check_hash();', 500);
 }

}

//update the edit, login and logout links after page change var update_links = function(current_url) {

 $('#edit-link').attr('href', current_url + '?action=edit');
 $('#edit-intro-link').attr('href', '/Team:RHIT/desc/' + area + '/' + subarea + '?action=edit');
 $('#login-link' ).attr('href', '/wiki/index.php?title=Special:UserLogin&returnto=' + current_url);
 $('#logout-link').attr('href', '/wiki/index.php?title=Special:UserLogout&returnto=' + current_url);

}

var is_internal = function(obj) {

 if($(obj).hasClass('RHIT-external')) return false;
 return /\/Team:RHIT/i.test($(obj).attr("href"));

}

var is_external = function(obj) { return !is_internal(obj);}

var wiki_main = function() {

 if((window.location.hash == ) || (window.location.hash == undefined) || !(window.location.hash.charAt(1) == '/'))
 {
   set_hash(the_url);
 }
 else
 {
   load_url(get_hash());
 }

}

var get_login = function()
 {
   var page = $('#menubar.right-menu').find('#pt-userpage');
   if(page.length == 0) return undefined;
   return page.children('a').text();
 }  
 var set_login = function(username)
 {
   if(username != undefined)
   {
     $('#user-link').text(username).attr('href', '/User:' + username);
     $('#edit-link').text('Edit Page');
     $('#edit-intro-link').text('Edit Introduction');
     $('#logged_out').hide();
     $('#logged_in').show();
   }
 }

$(window).ready(function() {

 var login = get_login();
 set_login(login);

});