Template:Team:Cambridge/CAM 2012 TEMPLATE HEAD PROJECT

From 2012.igem.org

(Difference between revisions)
Line 25: Line 25:
set_bk();
set_bk();
 +
 +
//the url that's loaded
 +
var the_url = window.location.pathname;//the url that's being displayed
 +
//the interval
 +
var int;
 +
 +
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:\/\/2012.igem.org/i, '').replace(/\/Team:Cambridge/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:Cambridge" + hash;
 +
  return "https://2012.igem.org/Team:Cambridge" + 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:Cambridge/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);
 +
}
 +
 +
//define external internal links
 +
 +
var is_internal = function(obj)
 +
{
 +
  if($(obj).hasClass('cam-external')) return false;
 +
  return /\/Team:Cambridge/i.test($(obj).attr("href"));
 +
}
 +
var is_external = function(obj) { return !is_internal(obj);}
 +
</script>
</script>

Revision as of 13:00, 23 July 2012