Team:RHIT/static/wiki.js

From 2012.igem.org

Revision as of 15:10, 18 July 2012 by Frenchra (Talk | contribs)

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 get_login = function() {

  var page = $('#login.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();
  }

}

var login = get_login();

set_login(login);